How to draw multinomial distributed patterns with RcppArmadillo?
The problem is that I have a variable arma::mat prob_vec
and require something equivalent rmultinom(1, 1, prob_vec)
in R.
I found that the function rmultinom
provided by RcppArmadillo has a weird argument requirement different from the requirement in R! Thus, it will not compile.
I just want to learn how to draw the desired pattern in RcppArmadillo, or equivalently, in Armadillo. If I need to get a pointer or convert a variable prob_vec
, please let me know how.
Many thanks!
source to share
Your co-author of Friendly Neighborhood is RcppArmadillo
here: I can assure you that it doesn't provide rmultinom
, but Rcpp does. In fact, it just jumps to R itself, as a quick one grep
would tell you:
inline void rmultinom(int n, double* prob, int k, int* rn)
{ return ::rmultinom(n, prob, k, rn); }
So, I suggest that you first write a five-line C program against the R API to make sure you know how rmultinom
to do what you want, and then use Rcpp and RcppArmadillo to do the same on the data in your vector.
source to share