[R] Beta stochastic simulation

Duncan Murdoch murdoch at stats.uwo.ca
Thu Sep 14 20:31:28 CEST 2006


On 9/14/2006 1:42 PM, Mark Pinkerton wrote:
> Hi,
> I am finding that I get quite different results when I interchange the
> following "equivalent" lines for sampling from a beta distribution in my
> r script. The rbeta line is correct judging by the summary statistics of
> the simulated values, while the qbeta line consistently leads to a
> higher mean simulated value.
>  
> simulation <- rbeta(1, alpha, beta)
> simulation <- qbeta(runif(1), alpha, beta)
>  
> Are there any implementation reasons for this?

You need to be more specific about the R version, the parameter values 
you're using, and the size of the differences you're seeing.  I just tried

 > x <- rbeta(100000, 1, 6)
 > y <- qbeta(runif(100000), 1, 6)
 > summary(x); summary(y)
      Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
4.076e-07 4.681e-02 1.085e-01 1.423e-01 2.055e-01 8.773e-01
      Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
2.803e-06 4.583e-02 1.078e-01 1.419e-01 2.047e-01 8.861e-01

and I think those results look reasonable (and the qbeta method has a 
smaller mean, this run).

Duncan Murdoch

>  
> Thanks
>  
> Mark Pinkerton
> Risk Management Solutions 
> Peninsular House
> 30 Monument Street
> London EC3R 8HB 
> UK 
>  
> www.RMS.com <http://www.rms.com/>  
> Tel:  +44 20 7444 7783 
> Fax: +44 20 7444 7601
>  
> 
> 
> This message and any attachments contain information that may be RMS Inc. 
> confidential and/or privileged.  If you are not the intended recipient 
> (or authorized to receive for the intended recipient), and have received 
> this message in error, any use, disclosure or distribution is strictly 
> prohibited.   If you have received this message in error, please notify 
> the sender immediately by replying to the e-mail and permanently deleting 
> the message from your computer and/or storage system.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list