[R] generate random numbers

Greg Snow Greg.Snow at imail.org
Thu Mar 31 21:47:36 CEST 2011


There are several non-normal distributions built in that you could just use their generationg functions.  There are packages (most with dist somewhere in the name) that allow for functions on standard distributions including combining together distributions.

If your distribution is not one of the above, but has a well defined inverse cumulative distribution then you can just generate random uniforms (runif) and put them into the inverse.

If none of the above works then there are still many tools available such as rejection sampling or metropolis-hastings sampling.

The logspline package can approximate a distribution from a dataset and generate values from the approximation.

We would need to know more about the actual distribution that you are interested in to be of more specific help.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Anna Lee
> Sent: Thursday, March 31, 2011 1:24 PM
> To: r-help at r-project.org
> Subject: [R] generate random numbers
> 
> Hey List,
> 
> does anyone know how I can generate a vector of random numbers from a
> given distribution? Something like "rnorm" just for non normal
> distributions???
> 
> Thanks a lot!
> Anna
> 
> --
> 
> 
> 
> Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail
> irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu
> benachrichtigen und die E-Mail zu löschen.
> 
> This e-mail is confidential. If you have received it in error, please
> notify me immediately and delete it from your system.
> 
> ______________________________________________
> R-help at r-project.org 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