r:generating_a_random_data_set_with_certain_correlations
This is an old revision of the document!
Generating a random data set with certain correlations
n.d <- 6
r12 <- .2
r13 <- .6
r23 <- .8
n.var <- length(mu)
mu <- c(4, 10, 2)
stddev <- c(1, 1, 1)
corMat <- matrix(c(1, r12, r13,
r12, 1, r23,
r13, r23, 1),
ncol = n.var)
corMat
covMat <- stddev %*% t(stddev) * corMat
covMat
set.seed(1)
library(MASS)
d1 <- mvrnorm(n = n.d, mu = mu, Sigma = covMat, empirical = TRUE)
colnames(d1) <- c("x", "y", "z")
colMeans(d1)
cor(d1)
plot(d1)
d1
r/generating_a_random_data_set_with_certain_correlations.1588657314.txt.gz · Last modified: by hkimscil
