I am looking to mimic an age variable (limited range 18-35) that correlated 0.1 with an existing binary variable called use. Most of the examples I came across demonstrate how to simulate both variables at the same time.
set.seed(493)
n <- 134
dat <- data.frame(partID=seq(1, n, 1),
trt=c(rep(0, n/2),
rep(1, n/2)))
a <- .8
b <- .2
dat$use <- c(rbinom(n/2, 1, b),
rbinom(n/2, 1, a))
source
share