Skip to main content
formatted
Source Link
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

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

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.

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

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

  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.

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

  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)))
    
added 26 characters in body
Source Link
AdamO
  • 64.8k
  • 6
  • 135
  • 273
  1. If you want 200 copies of each of 5 categorical variableslevels in a polytomous variable in random order, then do this instead

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

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

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

  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.

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

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