Re: [R] Determining the correlation coefficient?

2009-12-14 Thread Liviu Andronic
Hello

On 12/14/09, Anja Mohorko nekostrg...@yahoo.com wrote:
 Hello, I need your help! Probably the answer is quite easy, but still ...
  How can I sample two (or more) vectors of data from a normal distribution so 
 they are correlated with an exact value I select (for example pearson's r = 
 .30)?


require(MASS)
Sigma - matrix(c(10,3,3,2),2,2)
Sigma
mvrnorm(n=1000, rep(0, 2), Sigma)

Liviu

__
R-help@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.


Re: [R] Determining the correlation coefficient?

2009-12-14 Thread Ravi Varadhan

If you want the samples to have exact correlation that you have specified, then 
you must specify the `empirical=TRUE' option:

mvrnorm(n=1000, rep(0, 2), Sigma, empirical=TRUE)

Ravi.


Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Liviu Andronic landronim...@gmail.com
Date: Monday, December 14, 2009 8:52 am
Subject: Re: [R] Determining the correlation coefficient?
To: Anja Mohorko nekostrg...@yahoo.com
Cc: r-help@r-project.org


 Hello
 
 On 12/14/09, Anja Mohorko nekostrg...@yahoo.com wrote:
  Hello, I need your help! Probably the answer is quite easy, but 
 still ...
   How can I sample two (or more) vectors of data from a normal 
 distribution so they are correlated with an exact value I select (for 
 example pearson's r = .30)?
 
 
 require(MASS)
 Sigma - matrix(c(10,3,3,2),2,2)
 Sigma
 mvrnorm(n=1000, rep(0, 2), Sigma)
 
 Liviu
 
 __
 R-help@r-project.org mailing list
 
 PLEASE do read the posting guide 
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.