Re: [R] Generating Data for Simulation

From: Ben Bolker <>
Date: Wed, 12 Nov 2008 14:48:36 +0000 (UTC)

Brett Magill <magillb <at>> writes:

> Are there any R packages that could be used to generate random data given a
> set of parameters? Or, if not a package, how would one generate such data?
> What I would like to do is simulate some sample data for a regression model
> given a set of population covariances and distribution parameters to be used
> in a MC simulation.
> Thanks for any tips.

  This is very definitely doable, don't know of any end-user packages to do it.

  Simple example: generate data according to

X ~ Uniform(0,10)
Y ~ Normal(1+2*X,sigma=0.1)

set.seed(1001) ## for reproducibility

n <- 100
x <- runif(n,0,10)
y <- rnorm(n,mean=1+2*x,sigma=0.1)

  You can look at chapter 5 of (or buy the book) for more information ...

    Ben Bolker mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 12 Nov 2008 - 14:56:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Nov 2008 - 16:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive