eric lee
2009-Feb-02 16:15 UTC
[R] how to generate multiple random variables that are correlated
Hi. I have two variables, x and y, that are each normally distributed with mean 0 and have known standard deviations. The variables also have a known correlation, so I can represent their correlations in a matrix like so: a <- array(c(0.3,0.1,0.1,0.2),c(2,2)) a Is there an R function that generates random values for my two variables given the correlation? I'd like to do this for up to 5 variables and I'm running version 2.7.2 on a windows platform. Thanks. eric
Ben Bolker
2009-Feb-02 16:19 UTC
[R] how to generate multiple random variables that are correlated
eric lee <ericlee100 <at> gmail.com> writes: [snip]> > Is there an R function that generates random values for my two > variables given the correlation? I'd like to do this for up to 5 > variables and I'm running version 2.7.2 on a windows platform. > Thanks.?MASS::mvrnrom
Jorge Ivan Velez
2009-Feb-02 16:21 UTC
[R] how to generate multiple random variables that are correlated
Dear Eric, See ?mvrnorm in the MASS package. HTH, Jorge On Mon, Feb 2, 2009 at 11:15 AM, eric lee <ericlee100@gmail.com> wrote:> Hi. > > I have two variables, x and y, that are each normally distributed with > mean 0 and have known standard deviations. The variables also have a > known correlation, so I can represent their correlations in a matrix > like so: > > a <- array(c(0.3,0.1,0.1,0.2),c(2,2)) > a > > Is there an R function that generates random values for my two > variables given the correlation? I'd like to do this for up to 5 > variables and I'm running version 2.7.2 on a windows platform. > Thanks. > > eric > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]