Displaying 1 result from an estimated 1 matches for "catdismat".
2011 Dec 15
1
how to draw random numbers from many categorical distributions quickly?
Dear R helpers,
I have a question about drawing random numbers from many categorical
distributions.
Consider n individuals, each follows a categorical distribution defined
over k categories.
Consider a simple case in which n=4, k=3 as below
catDisMat <-
rbind(c(0.1,0.2,0.7),c(0.2,0.2,0.6),c(0.1,0.2,0.7),c(0.1,0.2,0.7))
outVec <- rep(NA,nrow(catDisMat))
for (i in 1:nrow(catDisMat)){
outVec[i] <- sample(1:3,1, prob=catDisMat[i,], replace = TRUE)
}
I can think of one way to potentially speed it up (in reality, my n is very
large, so spe...