-
Notifications
You must be signed in to change notification settings - Fork 13
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
use rmultinom with arrays #255
Comments
Thanks a lot! Using rbinom multiple times could do the trick, although a little tedious |
Agreed, quite tedious. In #213 there's a trick to re-write the multinomial draw as a set of binomial draws - that will allow expansion to work on a matrix (or higher-order structure). We use this on some large models and it will be just as efficient. Also: if you're using odin for stochastic models, you should look at our dust package (via odin.dust) as that will compile models that can be run in parallel (see this paper, this vignette and this walkhrough) |
+1 to implementing this, alongside hypergeometric distributions. I am not sure an alternative such as the nested binomials outlined in #213 exists for the latter, but would love to hear about a similar trick if it exists. |
yes, same trick would likely work for multivariate hypergeometric (note that R does not actually support this distribution). The implementation at present is here: https://github.com/mrc-ide/odin/blob/master/inst/library.c#L358-L375 so one could adapt that same logic iterating across the axes of your array. While I recognise that this feature would be of use, I would not expect it to be implemented anytime soon based on our current priorities (certainly not this calendar year). It's likely a lot of work and something that can at least be worked around, unlike some of the other things we hope to get done this year. |
Makes sense, thanks. |
Dear odin team,
I've reat that rmultinom can not work as y[1, ] <- rmultinom(10, p[i, ]), but what if I have a metapopulation model? In that case, I'll have multiple sizes. I need to do something like n_Eout[i,] <- rmultinom(n_Eout[i], p_Eout_all), where p_Eout_all is a vector with the same number of elements as the number of columns of n_Eout.
Thanks,
Qu
The text was updated successfully, but these errors were encountered: