Add dirichlet#264
Open
stemangiola wants to merge 3 commits into
Open
Conversation
- Introduced a new noise model option, 'dirichlet_multinomial', in the sccomp package, allowing for the use of Dirichlet-multinomial likelihoods for count data. - Updated the `fit_model` function to accommodate different initialization parameters based on the selected noise model. - Enhanced documentation for `sccomp_estimate` and related functions to clarify the new noise model options and their implications. - Added tests to ensure functionality and correctness of the new model implementation, including checks for expected output structure and compatibility with existing models.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for a new Dirichlet(-multinomial) noise model option to sccomp_estimate(), including a new Stan model and accompanying documentation/tests.
Changes:
- Add
noise_model = "dirichlet_multinomial"option and route model fitting to a new Stan program. - Update Stan model initialization and proportion preprocessing (renormalization after 0 replacement).
- Add test coverage and update generated documentation for the new noise model.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
tests/testthat/test-dirichlet.R |
Adds tests for estimating/testing with dirichlet_multinomial, plus a correlation check vs. existing model. |
R/sccomp_estimate.R |
Extends API to accept dirichlet_multinomial, validates via match.arg(), and selects the Stan model/parameters accordingly. |
R/model_fitting.R |
Adjusts Stan init values by model name and renormalizes y_proportion rows after replacing zeros. |
man/sccomp_estimate.Rd |
Documents the new noise_model option and behavior for counts vs proportions. |
man/sccomp_calculate_residuals.Rd |
Clarifies meaning of residuals_unconstrained and updates details accordingly. |
inst/stan/glm_dirichlet.stan |
Introduces a Dirichlet-multinomial / Dirichlet Stan model with reduce_sum and log_lik for LOO. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+89
to
+102
| est_bb <- sccomp_estimate( | ||
| counts_obj, | ||
| formula_composition = ~ type, | ||
| formula_variability = ~ 1, | ||
| sample = "sample", | ||
| cell_group = "cell_group", | ||
| abundance = "count", | ||
| noise_model = "multi_beta_binomial", | ||
| cores = 1, | ||
| verbose = FALSE, | ||
| inference_method = "hmc", | ||
| max_sampling_iterations = 500, | ||
| cache_stan_model = cache_dir | ||
| ) |
There was a problem hiding this comment.
These tests run HMC without setting mcmc_seed, but sccomp_estimate() defaults to a random seed (sample_seed()), which can make the test non-deterministic and flaky (especially the correlation threshold). Set an explicit mcmc_seed for the estimates in this test file (at least for the correlation test).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.