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]]
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:> 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/
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:>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.
Seemingly Similar Threads
- problem in for loop
- counting values with some conditions in a simulation
- help about random generation of a Normal distribution of several variables
- Select rows from Data Frame with conditions
- ideas to speed up code: converting a matrix of integers to a matrix of normally distributed values