[R] How to create a random matrix with conditions
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:
> 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?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
More information about the R-help