Generate Random Correlated Data




library(MASS)
covmat <- matrix(c(1,.5,.6, .5,1,.5, .6,.5,1), ncol=3) # the true cov matrix for my data
data <- mvrnorm(100, mu=c(0,0,0), Sigma=covmat) # generate random data that match that cov matrix
colnames(data) <- c("X1", "X2", "X3")

library(knitr)
kable(round(cor(data), 3),format = "pandoc", caption = "Table 1: Correlation Matrix")
Table 1: Correlation Matrix
X1 X2 X3
X1 1.000 0.560 0.555
X2 0.560 1.000 0.518
X3 0.555 0.518 1.000



Comments are closed.