
Last chance! 50% off unlimited learning
Sale ends in
A function to simulate data from a correlation matrix. This is useful for illustrating some theoretical properties of regressions when population parameters are known and set in advance.
cor2data(cor, n, seed)
cor2data()
returns a data frame where all observations are simulated from a standard
normal distribution, but with those pre-set correlations.
A correlation matrix (of class matrix
)
A number of observations to simulate
An optional parameter to set a seed. Omitting this generates new simulations every time.
Steven V. Miller
vars <- c("control", "treat", "instr", "e")
Correlations <- matrix(cbind(1, 0.001, 0.001, 0.001,
0.001, 1, 0.85, -0.5,
0.001, 0.85, 1, 0.001,
0.001, -0.5, 0.001, 1),nrow=4)
rownames(Correlations) <- colnames(Correlations) <- vars
cor2data(Correlations, 1000, 8675309)
Run the code above in your browser using DataLab