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) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 13-Jun-07 Time: 00:35:59 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@stat.math.ethz.ch 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.