Re: [R] Generating artificial datasets with a specific correlati

From: Ted Harding <>
Date: Wed, 13 Jun 2007 00:36:02 +0100 (BST)

On 12-Jun-07 20:54:05, Ken Knoblauch wrote:

> see mvrnorm in MASS and especially the empirical argument
> James Milks <james.milks <at>> 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,

E-Mail: (Ted Harding) <> Fax-to-email: +44 (0)870 094 0861
Date: 13-Jun-07                                       Time: 00:35:59
------------------------------ XFMail ------------------------------

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 12 Jun 2007 - 23:41:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 13 Jun 2007 - 00:32:05 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.