[ADMB Users] simulated multinomial samples

Martell, Steven s.martell at fisheries.ubc.ca
Thu Aug 8 15:22:50 PDT 2013

You could try this:

dvector rmultinom(const int& seed, const int& size,const dvector& prob)
{ //Returns a multinomial sample, of size n, based on sampling probabilities p.
//p is normalized internally, based on the same method employed in R
random_number_generator rng(seed);
int i,n,lb,ub;
float p;
lb=prob.indexmin(); ub=prob.indexmax();
dvector freq(lb,ub); freq.initialize();
dvector P=prob;
dvector bisamp(1,size); bisamp.fill_randbi(P[lb],rng);
p=P[i]/(1.-sum(P(lb,i-1))); //Corrected version

dvector bisamp(1,n); bisamp.fill_randbi(p,rng);
if(sum(freq)==size) break;
return (freq);

On 2013-08-01, at 5:35 PM, Peter Stephenson <Peter.Stephenson at fish.wa.gov.au<mailto:Peter.Stephenson at fish.wa.gov.au>>

I am wanting to draw a multinomial sample of size say 300 with a vector of known proportions at age.
randbi does not seem to work and the fill_multinomial does not give me what I am looking for.
The .tpl and .dat files are attached. Any suggestions. Cheers Peter
Users mailing list
Users at admb-project.org<mailto:Users at admb-project.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20130808/a3f04864/attachment.html>

More information about the Users mailing list