# How to simulate correlated data

6 messages
Open this post in threaded view
|
Report Content as Inappropriate

## How to simulate correlated data

 Hello there, I would like to simulate X --Normal (20, 5)                          Y-- Normal (40, 10) and the correlation between X and Y is 0.6. How do I do it in R? Thank you very much Lisa Wang Msc. Princess Margaret Hospital Toronto, Ca ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to simulate correlated data

 See ?mvrnorm -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Lisa Wang Sent: Thursday, December 15, 2005 10:34 AM To: R-Help Subject: [R] How to simulate correlated data Hello there, I would like to simulate X --Normal (20, 5)                          Y-- Normal (40, 10) and the correlation between X and Y is 0.6. How do I do it in R? Thank you very much Lisa Wang Msc. Princess Margaret Hospital Toronto, Ca ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to simulate correlated data

 In reply to this post by Lisa Wang Hi you need library(mvtnorm) then a <- rmvnorm(n=10000,mean=c(20,40),sigma=matrix(c(5,0.6*sqrt(50), 0.6*sqrt(50),10),2,2)) will do what you want HTH rksh On 15 Dec 2005, at 15:33, Lisa Wang wrote: > Hello there, > > I would like to simulate X --Normal (20, 5) >                          Y-- Normal (40, 10) > > and the correlation between X and Y is 0.6. How do I do it in R? > > Thank you very much > > Lisa Wang Msc. > Princess Margaret Hospital > Toronto, Ca > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! http://www.R-project.org/posting-  > guide.html -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK   tel  023-8059-7743 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to simulate correlated data

 In reply to this post by Lisa Wang G'day Lisa, >>>>> "LW" == Lisa Wang <[hidden email]> writes:     LW> I would like to simulate X --Normal (20, 5) Y-- Normal (40,     LW> 10) and the correlation between X and Y is 0.6.     LW> How do I do it in R? That depends on what you want the joint distribution to be. :) If you want the joint distribution to be normal, you could use the function mvrnorm() from the MASS package. HTH. Cheers,         Berwin ========================== Full address ============================ Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)   School of Mathematics and Statistics        +61 (8) 6488 3383 (self)       The University of Western Australia   FAX : +61 (8) 6488 1028 35 Stirling Highway                   Crawley WA 6009                e-mail: [hidden email] Australia                        http://www.maths.uwa.edu.au/~berwin______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: How to simulate correlated data

 In reply to this post by Lisa Wang So what you actually wnat is a multivariate normal distribution! with mean c(20,40) and covariance matrix cbind(c(5,0.6*sqrt(5,10)),c(0.6*sqrt(5,10),10)) [Since Corr(x,y) = Cov(x,y)/sqrt(Var(x)*Var(y)) Look at the mvtnorm package, for function rmvnorm Trying RSiteSearch("Multivariate normal distribution") should also bring you to the package Best regrads, Kristel Lisa Wang wrote: > Hello there, > > I would like to simulate X --Normal (20, 5) >                          Y-- Normal (40, 10) > > and the correlation between X and Y is 0.6. How do I do it in R? > > Thank you very much > > Lisa Wang Msc. > Princess Margaret Hospital > Toronto, Ca > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- __________________________________________ Kristel Joossens        Ph.D. Student Research Center ORSTAT  K.U. Leuven Naamsestraat 69         Tel: +32 16 326929 3000 Leuven, Belgium    Fax: +32 16 326732 E-mail:  [hidden email] http://www.econ.kuleuven.be/public/ndbae49Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html