# [R] Random Beta variates

Thomas Lumley tlumley at u.washington.edu
Mon Jun 17 05:32:14 CEST 2002

```On Mon, 17 Jun 2002 Michael_Scroggie at nre.vic.gov.au wrote:

>
> I have been trying to use the rbeta() function to generate random beta
> variates with a particular mean and standard deviaiton  for some simulation
> problems
> I am working on, however I am unsure of the relationship between the
> parameters shape1 and shape2 and the mean and standard deviation of the
> beta
> distribution. I am guessing that there is a formula for this, but I am
> unsure what it is. Can anyone advise me?

There is indeed.
mean = a / (a + b)
var = ab / [(a + b)2 (a + b + 1)]

where a=shape1, b=shape2.  This is in a lot of textbooks, and
is easily Googled, and you can do an example eg
> var(rbeta(10000,2,1))
[1] 0.05524684
> 2/(3*3*4)
[1] 0.05555556
to confirm that you've got the right formula.

-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```