Simulate a correlated variable with a given correlation
get_correlated_var(x, rho, sim_fun = rnorm, seed = 123)
Arguments
- x
response variable
- rho
target correlation
- sim_fun
simulation function
Examples
B <- 250
res <- rep(0, B)
for (i in 1:250)
{
y <- rnorm(1000)
res[i] <- get_correlated_var(y, rho = 0.1)$cors
}
hist(res)