[R] Defining vectors with per-determined correlations

peter dalgaard pdalgd at gmail.com
Sun Sep 7 14:33:16 CEST 2014


On 04 Sep 2014, at 19:32 , Ista Zahn <istazahn at gmail.com> wrote:

> See ?mvrnorm in the MASS package.

... and in particular, notice its empirical=TRUE argument. 

Also, notice that the 3rd correlation (corr(x, z)=r3, say) can't be set arbitrarily: if r1=r2=0.99, r3 cannot be zero. 

> 
> Best,
> Ista
> 
> 
> On Thu, Sep 4, 2014 at 12:04 PM, John Sorkin <jsorkin at grecc.umaryland.edu>
> wrote:
> 
>> I need to define three vectors x, y, z (each of length 100) such that the
>> pair-wise correlations of the vectors have per-defined values r1 and r2.
>> More specifically I need to define x, y, and z so that:
>> 
>> corr(x,y) = r1
>> corr(y,z) = r2
>> 
>> Is there any easy way to accomplish this with R?
>> 
>> Thank you,
>> John
>> John David Sorkin M.D., Ph.D.
>> Professor of Medicine
>> Chief, Biostatistics and Informatics
>> University of Maryland School of Medicine Division of Gerontology and
>> Geriatric Medicine
>> Baltimore VA Medical Center
>> 10 North Greene Street
>> GRECC (BT/18/GR)
>> Baltimore, MD 21201-1524
>> (Phone) 410-605-7119
>> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>> 
>> Confidentiality Statement:
>> This email message, including any attachments, is for ...{{dropped:18}}
> 
> ______________________________________________
> R-help at r-project.org 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list