I am trying to generate a simulated data matrix that is correlated by both observation and variable directions. So far I know how to do this for variable x variable.
# correlated matrix between variables n = 200 p = 100 CRMt <- matrix(NA, nrow = p, ncol = p) diag(CRMt) <- 1 CRMt[upper.tri (CRMt, diag = FALSE)] <- 0.5 CRMt[lower.tri (CRMt, diag = FALSE)] <- 0.5 L = chol(CRMt)# Cholesky decomposition p = dim(L) set.seed(999) M = t(L) %*% matrix(rnorm(p*n), nrow=p, ncol=n) M1 <- t(M) rownames(M1) <- paste("S", 1:200, sep = "") colnames(M1) <- paste("M", 1:100, sep = "") cor(M1)
Now say I want to create a data matrix that also follows the following observation x observation correlation matrix.
OCRMt <- matrix(NA, nrow = n, ncol = n) diag(OCRMt) <- 1 OCRMt[upper.tri (OCRMt, diag = FALSE)] <- 0.3 OCRMt[lower.tri (OCRMt, diag = FALSE)] <- 0.3
How can I do this ?