[R] Generating artificial datasets with a specific correlati
(Ted Harding)
ted.harding at nessie.mcc.ac.uk
Wed Jun 13 01:36:02 CEST 2007
On 12-Jun-07 20:54:05, Ken Knoblauch wrote:
> see mvrnorm in MASS and especially the empirical argument
>
> James Milks <james.milks <at> wright.edu> writes:
>
>
>> I need to create artificial datasets with specific correlation
>> coefficients (i.e. a dataset that returns r = 0.30, etc.) as examples
>> for a lab I am teaching this summer. Is there a way to do that in R?
>>
>> Thanks.
>>
>> Jim Milks
Alternatively, if you would prefer your datasets to have non-nomal
distributions, consider the fact that if X and Y are independent,
each with mean 0 and variance 1, then the correlation coefficient
between (X + a*Y) and (X - a*Y) is
(1 - a^2)/(1 + a^2)
so if you choose a = sqrt((1 - r)/(1 + r)) then these will have
correlation coefficient r.
So generate X and Y as you please, and then continue as above.
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Jun-07 Time: 00:35:59
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list