[R] How to simulate correlated data

Berwin A Turlach berwin at maths.uwa.edu.au
Thu Dec 15 16:50:13 CET 2005


G'day Lisa,

>>>>> "LW" == Lisa Wang <lisawang at uhnres.utoronto.ca> 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: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin




More information about the R-help mailing list