cor2data: Simulate Data from Correlation Matrix

View source: R/cor2data.R

cor2dataR Documentation

Simulate Data from Correlation Matrix

Description

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.

Usage

cor2data(cor, n, seed)

Arguments

cor

A correlation matrix (of class matrix)

n

A number of observations to simulate

seed

An optional parameter to set a seed. Omitting this generates new simulations every time.

Value

cor2data() returns a data frame where all observations are simulated from a standard normal distribution, but with those pre-set correlations.

Author(s)

Steven V. Miller

Examples

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)


stevemisc documentation built on Sept. 11, 2024, 5:23 p.m.