cor2data | R Documentation |
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)
cor |
A correlation matrix (of class |
n |
A number of observations to simulate |
seed |
An optional parameter to set a seed. Omitting this generates new simulations every time. |
cor2data()
returns a data frame where all observations are simulated from a standard
normal distribution, but with those pre-set correlations.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.