I am working on simulation of data, and this is just the first step of what I am trying to do. I am first simulating data based on a correlation matrix (as this is what I want). I used the R code found on a blog :
# The variables will each have a mean of 0 and a variance of 1. After you have the data, you can
# apply a linear transformation to get any mean and variance that you want.
rmat <- matrix(c(1.0, .50, -.50, .50, 1.0, .30, -.50, .30, 1.0), nrow = 3, byrow = T)
mu <- c(0,0,0)
library(MASS)
mat <- mvrnorm(100, Sigma = rmat, mu = mu, empirical = TRUE)
# If empirical = FALSE, the correlations will be approx.
cat ("The intercorrelation matrix is = '\n'")
print(cor(mat))
I have two questions - (1) can I just use a covariance matrix here instead?
2) the author has written "apply a linear transformation to get any mean and variance that you want". I need the data to have a particular mean and S.D...it is probably a trivial exercise , but can someone help me how I can transform this data which has mean 0 and SD 1 to what is desired? So is there an easy way to scale mat variables to have the desired mean and S.D?
Thanks for the help!