[R] How to create a random matrix with conditions

D. Rizopoulos d.rizopoulos at erasmusmc.nl
Mon Jan 28 09:04:18 CET 2013

You didn't say how you want these variables to be distributed, but in 
case you want a multivariate normal, then have a look at function 
mvrnorm() from package MASS, and especially at the 'empirical' argument, 


# assumed covariance matrix
V <- cbind(c(2, 1), c(1, 1.2))

x1 <- mvrnorm(1000, c(0,0), V, empirical = FALSE)

x2 <- mvrnorm(1000, c(0,0), V, empirical = TRUE)

I hope it helps.


On 1/28/2013 7:11 AM, Simon Givoli wrote:
> Hi!
> I want to create a random matrix with 15 variables, each variable having
> 1000 observations.
> Between each two variables, I want to define a specific (*not *random)
> correlations between them, but still saving the "randomness" of each
> variable (mean=zero, s.d=1).
> How can I do this in R?
> thanks,
> Simon
> 	[[alternative HTML version deleted]]
> ______________________________________________
> 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.

Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

More information about the R-help mailing list