- If you want 200 copies of 5 categorical variables in random order, then do this
x <- sample(rep(paste0('pict', 1:5), 200))
- If you want to control for overall prevalence of a specific outcome, then you must choose which
beta
you will fudge. I usually dobeta0
.
set.seed(1)
MM <- model.matrix(~x)
betas <- rnorm(4)
prevTarget <- 0.3
prevDiff <- function(beta0)
prevTarget - mean(binomial()$linkinv(MM%*%c(beta0, betas)))
beta0 <- uniroot(prevDiff, c(-100, 100))$root
mean(binomial()$linkinv(MM%*%c(beta0, betas)))