I would like to generate N
number of random variables that each have a fixed correlation p
with each other.
The variables should have mean = 1
and a std = 5
N=10 #number of variables
mu <- rep(1,N) #means
p=0.7 #correlation
Sigma <- matrix(p,ncol=N,nrow=N) #variance covariance matrix
diag(Sigma) <- 5 #standard deviations
library(MASS)
set.seed(12)
data <- mvrnorm(10000,mu,Sigma)
However, the resulting standard deviations are not 5.
apply(data,2,sd)
[1] 2.264853 2.219811 2.224703 2.245595 2.216712 2.236484 2.240794 2.220532 2.227445
[10] 2.247943
Is there a systematic way in which I could vary the standard deviations while keeping the other parameters fixed?
diag(Sigma) <- 25
. Note that2.264853^2
is 5.129559 which is pretty close to 5... – lmo