Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass argument from fit_seromodel() to rstan::sampling() via ... #118

Open
Bisaloo opened this issue Sep 8, 2023 · 2 comments
Open

Pass argument from fit_seromodel() to rstan::sampling() via ... #118

Bisaloo opened this issue Sep 8, 2023 · 2 comments

Comments

@Bisaloo
Copy link
Member

Bisaloo commented Sep 8, 2023

At the moment, it seems that several arguments are passed from fit_seromodel() to rstan::sampling() directly, without any transformation.

Additionally, some rstan::sampling() are hardcoded, even though users might want to adjust them (e.g., number of chains).

The standard way to deal with this, allowing for maximum flexibility while keeping the fit_seromodel() function signature concise and clear, would be to pass argument to rstan::sampling() via ....

fit_seromodel <- function(
  serodata,
  foi_model,
  decades = 0,
) {
  fit <- rstan::sampling(
    model,
    data = stan_data,
    ...
  )
}

Additional reading on ...: https://adv-r.hadley.nz/functions.html#fun-dot-dot-dot

@ntorresd
Copy link
Member

ntorresd commented Mar 8, 2024

@Bisaloo, could you please confirm to me whether this was adequately addressed by #157?

@Bisaloo
Copy link
Member Author

Bisaloo commented Mar 8, 2024

Partially, I would also encourage you to simplify the fit_seromodel() signature even more to become:

fit_seromodel <- function(
    serodata,
    foi_model = c("constant", "tv_normal_log", "tv_normal"),
    ...
) {

However, here are two reasons you may have to keep some argument explicit rather than folding them into ...:

  • if you want to pre-process them or have different actions based on their value, such as suggested in

    serofoi/R/modelling.R

    Lines 241 to 242 in 05ad912

    # TODO Add a warning because there are exceptions where a minimal amount of
    # iterations is needed
  • if you really want to provide defaults but that's always' a difficult design choice. For example here, I definitely would not add a default for the seed, and would probably rely on rstan::sampling() existing defaults for chains, iter, thin, adapt_delta and max_treedepth()

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

No branches or pull requests

2 participants