[R] rgamma question

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu Feb 5 23:33:09 CET 2004


Icabalceta, Jorge L. wrote:

> I was trying to generate random numbers with a gamma distribution. In R the
> function is: 
> rgamma(n, shape, rate = 1, scale = 1/rate). My question is that if
> X~gamma(alpha, beta) and I want to generate one random number where do I
> plug alpha and beta in rgamma? and, what is the meaning and use of rate?
> Thanks for your attention,
> Jorge 
>  

Did you look at the help? From ?rgamma:

<quote>
Details:

      If 'scale' is omitted, it assumes the default value of '1'.

      The Gamma distribution with parameters 'shape' = a and 'scale' = s
      has density

                f(x)= 1/(s^a Gamma(a)) x^(a-1) e^-(x/s)

      for x > 0, a > 0 and s > 0. The mean and variance are E(X) = a*s
      and Var(X) = a*s^2.
</quote>

Then, depending how you define "alpha" and "beta" use the above to 
figure out how to use rgamma.

-sundar




More information about the R-help mailing list