Skip to content

How to create a random matrix with conditions

3 messages · Simon Givoli, Dimitris Rizopoulos, Jeff Newmiller

#
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, 
e.g.,

library(MASS)

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

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

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


I hope it helps.

Best,
Dimitris
On 1/28/2013 7:11 AM, Simon Givoli wrote:

  
    
#
First you must learn to be more specific in your description of what you want. That will allow others to understand what you actually want rather than guessing.

Perhaps try creating a small (3 var by 10 values) example, and describe the actual correlations you have created.

If your problem is that you don't know how to create what you want with any tool, then you should figure that out before posting here. stats.stackexchange.com might be helpful if that is the case.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
Simon Givoli <givolis at gmail.com> wrote: