Skip to content

random number generation

2 messages · Hadi Darzian Azizi, Francisco J. Zagmutt

#
Hello Hadi,

See ?rgamma

The Gamma distribution usually takes two parameters, shape and scale, 
not the mean and st. deviation.  If you have data, you can estimate 
those parameters using MLE methods, which are nicely provided in MASS:

library(MASS)
fitdistr(yourdata,"Gamma")

Once you have your parameters you can generate random values using 
rgamma i.e. rgamma(1000,10,1) will generate 1000 random samples from a 
Gamma distribution with shape = 10 and scale = 1.

If you only have the mean and standard deviation you can approximate the 
shape and scale parameters using:

scale=variance/mean
shape=mean^2/var

Remember the variance is equal to sd^2

I hope this helps,


Francisco J. Zagmutt

PS: Please read the posting guide (see the link at the bottom of this 
email). It really helps people trying to help you :-)
Hadi Darzian Azizi wrote: