[R] Generating Data for Simulation
Ben Bolker
bolker at ufl.edu
Wed Nov 12 15:48:36 CET 2008
Brett Magill <magillb <at> sbcglobal.net> 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
n=100
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
http://www.zoology.ufl.edu/bolker/emdbook/book.pdf
(or buy the book) for more information ...
cheers
Ben Bolker
More information about the R-help
mailing list