[R] Is there a way to not use an explicit loop?
    Juancarlos Laguardia 
    brassman785 at gmail.com
       
    Wed Sep 17 20:56:36 CEST 2008
    
    
  
I have a problem in where i generate m independent draws from a  
binomial distribution,
say
draw1 = rbinom( m , size.a, prob.a )
then I need to use each draw to generate a beta distribution.  So,  
like using a beta prior, binomial likelihood, and obtain beta  
posterior, m many times.  I have not found out a way to vectorize  
draws from a beta distribution, so I have an explicit for loop within  
my code
for( i in 1: m ) {
beta.post = rbeta( 10000, draw1[i] + prior.constant  ,  prior.constant  
+ size.a  - draw1[i] )
beta.post.mean[i] = mean(beta.post)
beta.post.median[i] = median(beta.post)
etc.. for other info
}
Is there a way to vectorize draws from an beta distribution?
UC Slug
    
    
More information about the R-help
mailing list