The next reproducible code generates 394 observations of 183 random normales, and tries to correlate them with Cholesky decomposition:
Generate the parameters
d <- 211
l <- 183
m <- -0.006495094
vectorsd <- rep(0.29, 183)
Generate random normals uncorrelated
rnormd <- as.data.frame(rnorm(l, mean = m, sd = vectorsd))
for (i in 1:(d+l)) {
rnormd[,i] <- rnorm(l, mean = m, sd = vectorsd)
}
Generate a random semidefinite positive matrix of correlations
v <- runif(183,0.6,0.8)
corr <- `diag<-`(tcrossprod(v),1)
Generate cholesky matrix
cholesky <- chol(corr)
Correlate the normals and transpose the output
rnormd <- t(rnormd*cholesky)
In this last instruction I get the error
Error in rnormd * cholesky : non-conformable arrays
At first a thought that the problem was going to be solved transposing my cholesky matrix, but then I realized that chol()
function already transposes it.
Can anyone help me?
Aucun commentaire:
Enregistrer un commentaire