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

chain_sim() fails with a negative binomial and mu = 0 and size = 0 #149

Closed
joshwlambert opened this issue Aug 22, 2024 · 2 comments · Fixed by #150
Closed

chain_sim() fails with a negative binomial and mu = 0 and size = 0 #149

joshwlambert opened this issue Aug 22, 2024 · 2 comments · Fixed by #150

Comments

@joshwlambert
Copy link

This is an unlikely, and epidemiologically nonsensical, use case, but when running bpmodels::chain_sim() with $R = 0$ and $k = 0$ then the function fails with an unfriendly error message.

bpmodels::chain_sim(n = 10, offspring = "nbinom", stat = "size", mu = 0, size = 0)
#> Warning in get(roffspring_name)(n = sum(n_offspring[sim]), ...): NAs produced
#> Error in if (any(next_gen%%1 > 0)) {: missing value where TRUE/FALSE needed

Created on 2024-08-22 with reprex v2.1.0

It would be good to catch this with an input check.

@jamesmbaazam
Copy link
Collaborator

Thanks for reporting, Josh. I will add a quick check here for negative binomial parameters as we discussed in person but as noted in the README, we have transitioned all features of bpmodels to the epichains package, which we strongly recommend that users use moving forward.

For example, running the same thing with {epichains} yields this error which could potentially be improved in not clear.

library(epichains)
epichains::simulate_chain_stats(
  n_chains = 10,
  offspring_dist = rnbinom,
  statistic = "size",
  mu = 0,
  size = 0
  )
#> Warning in (function (n, size, prob, mu) : NAs produced
#> Error in .sample_possible_offspring(offspring_func = offspring_dist, offspring_func_pars = pars, : Offspring distribution must return integers

Created on 2024-08-22 with reprex v2.1.1

@joshwlambert
Copy link
Author

Thanks, the fix in #150 looks good to me.

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 a pull request may close this issue.

2 participants