Skip to content

Generate Stan code modularly#5

Open
wpetry wants to merge 18 commits into
Pakillo:masterfrom
DICELab-NCSU:master
Open

Generate Stan code modularly#5
wpetry wants to merge 18 commits into
Pakillo:masterfrom
DICELab-NCSU:master

Conversation

@wpetry
Copy link
Copy Markdown

@wpetry wpetry commented Feb 11, 2025

This PR aims to generalize the types of models that can be fit by giving the user control of how sampling effort, animal preference, and relative abundances are modeled. This is achieved by substituting the current static Stan models with a new internal function stancode that composes the Stan code through a series of switches that respond to user-specified options. A modular approach to constructing the code will also enable future functionality to be added without needing to edit many individual Stan files by hand.

Additional new features to accommodate this change are:

  • Adding the ability to specify Dirichlet priors on $\sigma_i$ and $\tau_i$ parameters, or to pass abundances as data. Accommodates users who have prior knowledge or measurements of differences in species abundances.
  • Refactoring get_posterior to use rlang in place of current embedded functions. This dependency is already present via dplyr. This approach should be more readily extensible if/when new modeling options are added.
  • Edited documentation of existing functions.
  • Added unit testing for the most-heavily changed functions.

There are several major changes that will impact backwards compatibility with existing code that uses the package:

  • Several arguments are renamed (i) align naming conventions with new arguments and (ii) to help users understand the expected dimensions (e.g., the length of the sampling effort vector should match the number of plant types). I didn't do a good job separating these into a separate commit, but am happy to undo if these aren't wanted at this stage.
  • fit_model loses an argument to accept a file path to Stan code. I think this was a non-functional placeholder, and it's not clear when a user would want to use this function instead of the $sample() method from cmdstanr.

@wpetry wpetry changed the title Refactor Stan code into modular Generate Stan code modularly Feb 12, 2025
@wpetry
Copy link
Copy Markdown
Author

wpetry commented Feb 12, 2025

To do before submitting for review:

  • add flexibility for Dirichlet priors to accept a vector of appropriate length
  • document that Dirichlet priors use the $\alpha$ parameterization
  • final run to rebuild docs & pkgdown site

@wpetry wpetry marked this pull request as ready for review February 12, 2025 20:25
@wpetry wpetry marked this pull request as draft February 27, 2025 19:41
@wpetry wpetry marked this pull request as ready for review February 27, 2025 19:43
@wpetry
Copy link
Copy Markdown
Author

wpetry commented Sep 25, 2025

Pointwise log-likelihood support added in c985269 closes #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant