Matthew David Sylvester
2004-Jun-25 07:48 UTC
[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
Dimitris Rizopoulos
2004-Jun-25 08:04 UTC
[R] Simulating from a Multivariate Normal Distribution Using a Correlation Matrix
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 normaldistribution using a correlation> matrix, rho. I do not have sigma. I have searched the help archiveand the R documentation as> well as doing a standard google search. What I have seen is thatone can either use rmvnorm in> the package: mvtnorm or mvrnorm in the package: MASS. I believe Iread somewhere that the latter> was more robust. I have seen conflicting (or at least seeminglyconflicting to me, a relative> statistics novice), views on whether one can use the correlationmatrix with these commands> instead of the covariance matrix. I thought that if the commandsstandardized the covariance> matrix, then it would not matter, but I end up with larger valueswhen I test the covariance> matrix versus when I test rho. So, my question is, if one does notknow 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
Prof Brian Ripley
2004-Jun-25 08:13 UTC
[R] Simulating from a Multivariate Normal Distribution Using a Correlation Matrix
Short answer: to know a MVN distribution you need to know the mean vector and the covariance matrix. If you don't know a distribution you cannot simulate from it. So you need to know the marginal variances (the diagonal of the covariance matrix). If you have those, you can form the covariance matrix and use rmvnorm or mvrnorm. If you are willing to assume they are one, you have the covariance (= correlation matrix). If you don't know the marginal variances the problem is incompletely specified. On Fri, 25 Jun 2004, Matthew David Sylvester wrote:> 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 > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Possibly Parallel Threads
- generate random numbers from a multivariate distribution with specified correlation matrix
- Generating MVN Data
- simulate data from multivariate normal with pre-specified correlation matrix
- Generating an autocorrelated binary variable
- Bivariate Normal Distribution Plots