[R] Random multinomial variable
Scott Raynaud
scott.raynaud at yahoo.com
Fri Nov 4 19:51:11 CET 2011
I need some help interpreting the following code which is part of a mutlilevel model simulation with 2 levels. I've put in comments with my understanding of the code, but I'm not sure how [i2id] is functioning. It's defined in another part of the program as l2id<-rep(c(1:n2),each=n1) which looks like a number corresponding to the level 1 and 2 sample size (n1, n2). Can someone explain what [i2id] is telling x[,3] and x[,4]?
macpred<-rmultinom(n2,1,c(0.15,0.30,0.55))
## generate one multinomial variable of length=1 with probabilities of .15, .30 and .55 and do this n2 times
x[,3]<-macpred[1,][l2id]
##assign the first mutinomial value to column 3
x[,4]<-macpred[2,][l2id]
##assign the second multinomial value to column 4
More information about the R-help
mailing list