[R] Efficient multinom probs

From: Ingmar Visser <I.Visser_at_uva.nl>
Date: Fri 05 Jan 2007 - 10:41:41 GMT


Dear R-helpers,

I need to compute probabilties of multinomial observations, eg by doing the following:

y=sample(1:3,15,1)
prob=matrix(runif(45),15)
prob=prob/rowSums(prob)
diag(prob[,y])

However, my question is whether this is the most efficient way to do this. In the call prob[,y] a whole matrix is computed which seems a bit of a waste.

Is there maybe a vectorized version of dmultinom which does this?

Best, Ingmar



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Jan 06 11:19:09 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 06 Jan 2007 - 00:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.