Skip to main content
3 of 3
formatted
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717
  1. If you want 200 copies of each of 5 levels in a polytomous variable in random order, then do this instead:

     x <- sample(rep(paste0('pict', 1:5), 200))
    
  2. 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.

     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