Description Usage Arguments Details Value Author(s) See Also Examples
This function will randomly generate correlated multivariate normal data with specified means
and covariances (or correlations). The user also has the flexibility to generate data with
a randomly selected correlation matrix using the random.correlation
function.
1 |
n |
The sample size of the randomly generated dataset |
vars |
An integer indicating the number of variables. Ignored unless no |
mu |
A vector of means that has the same length as the number of rows/columns of Sigma. Defaults to a vector of zeroes. |
Sigma |
A positive definate matrix. If |
names |
Optional. A vector of strings indicating the variable names. |
mv.norm
generates correlated multivariate normal data using a choleski decomposition. If the
user does not specify Sigma
, a random correlation matrix will be generated. Also, if means are
not specified, the function will default to means of zero.
a nxp matrix of pseuodo-random values.
Dustin Fife
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | set.seed(2)
## generate data with correlation of .6
d = mv.rnorm(n=1000, Sigma=matrix(c(1, .6, .6, 1), 2), names=c("x", "y"))
head(d); cor(d)
## generate data with a random correlation
d = mv.rnorm(n=1000, vars=4, names=letters[1:4])
head(d); cor(d)
## generate non-scaled data
ms = c(100, 10, 5, 0) ### specify means
Sigma = matrix(c(1, .6, .5, .4,
.6, 1, .3, .2,
.5, .3, 1, .1,
.4, .2, .1, 1), 4)
## convert Sigma to covariance matrix
Sigma = cor2cov(Sigma, sd=c(15, 3, 2, 1))
## generate the data
d = mv.rnorm(n=1000, mu=ms, Sigma=Sigma, names=letters[1:4])
head(d); cor(d)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.