[R] Simulating from a Multivariate Normal Distribution Using a Correlation Matrix

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Fri Jun 25 10:04:54 CEST 2004


Hi Matt,

the correlation marix can be regarded as a covaraince matrix with unit
variance, so I think you could use it instead of your Sigma matrix,
e.g.,

rho <- cbind(c(1, .3, .1), c(.3, 1, .2), c(.1, .2, 1))
library(MASS)
x <- mvrnorm(5000, mu=1:3, Sigma=rho)
var(x)
          [,1]      [,2]      [,3]
[1,] 1.0234457 0.3101399 0.1146355
[2,] 0.3101399 0.9923358 0.2076328
[3,] 0.1146355 0.2076328 1.0115746

cor(x)
          [,1]      [,2]      [,3]
[1,] 1.0000000 0.3077485 0.1126647
[2,] 0.3077485 1.0000000 0.2072372
[3,] 0.1126647 0.2072372 1.0000000


Moreover, if you want different variance you could use

rho <- cbind(c(1, .3, .1), c(.3, 1, .2), c(.1, .2, 1))
vars <- 5
library(MASS)
x <- mvrnorm(5000, mu=1:3, Sigma=vars*rho)
var(x)
          [,1]      [,2]      [,3]
[1,] 4.9036297 1.4153234 0.4396337
[2,] 1.4153234 4.8801609 0.8947988
[3,] 0.4396337 0.8947988 4.8844880

cor(x)
           [,1]      [,2]       [,3]
[1,] 1.00000000 0.2893209 0.08983026
[2,] 0.28932087 1.0000000 0.18327313
[3,] 0.08983026 0.1832731 1.00000000


I hope this helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Doctoral Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm




----- Original Message ----- 
From: "Matthew David Sylvester" <msylvest at uclink.berkeley.edu>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, June 25, 2004 9:48 AM
Subject: [R] Simulating from a Multivariate Normal Distribution Using
a Correlation Matrix


> Hello,
> I would like to simulate randomly from a multivariate normal
distribution using a correlation
> matrix, rho.  I do not have sigma.  I have searched the help archive
and the R documentation as
> well as doing a standard google search.  What I have seen is that
one can either use rmvnorm in
> the package: mvtnorm or mvrnorm in the package: MASS.  I believe I
read somewhere that the latter
> was more robust.  I have seen conflicting (or at least seemingly
conflicting to me, a relative
> statistics novice), views on whether one can use the correlation
matrix with these commands
> instead of the covariance matrix.  I thought that if the commands
standardized the covariance
> matrix, then it would not matter, but I end up with larger values
when I test the covariance
> matrix versus when I test rho.  So, my question is, if one does not
know sigma, can they use rho?
>  And, if so, which command (or is there another) is better to use?
I gather that both use eigen
> decomposition?  Thank you so much  in advance for your help.
> Best,
> Matt
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list