Skip to main content
1 of 3
AdamO
  • 64.8k
  • 6
  • 135
  • 273
  1. If you want 200 copies of 5 categorical variables in random order, then do this

x <- sample(rep(paste0('pict', 1:5), 200))

  1. If you want to control for overall prevalence of a specific outcome, then you must choose which beta you will fudge. I usually do beta0.

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)))

AdamO
  • 64.8k
  • 6
  • 135
  • 273