rstargazer

Stargazer custom confidence intervals with multiple models


Stargazer is exponentiating 'wrong' confidence intervals because it is using normal distribution instead of t-distribution. So one has to use custom confidence intervals (Stargazer Confidence Interval Incorrect?).

But how does one it with multiple models?

model1 <- glm(vs ~ mpg + hp, data = mtcars, family = 'binomial')
model2 <- glm(vs ~ mpg + disp, data = mtcars, family = 'binomial')

library(stargazer)
stargazer(model1,
          apply.coef = exp, 
          digits = 3,
          ci = T,
          t.auto = F,
          type = "text",
          ci.custom = list(exp(confint(model1))))

This works as intended. But when I am adding

      ci.custom = list(exp(confint(model1, model2))))

then I'll get

Error in Pnames[which] : invalid subscript type 'list'

I tried with c() but to no avail.


Solution

  • The documentation says

    a list of two-column numeric matrices ...

    so

    cc <- lapply(list(model1, model2), function(x) exp(confint(x)))
    stargazer(model1, model2,                                      
       ...,
       ci.custom = cc)
    

    should work. (cc <- list(exp(confint(model1)), exp(confint(model2))) also works, and is a little more explicit, but won't generalize as well ...)

    For what it's worth, the difference for generalized linear models between the default CIs and those provided by confint() is not a Normal-vs-Student-t distinction (this is different from the case in the linked answer about linear models) — it's the difference between Wald and profile likelihood confidence intervals. (There is some theory for finite-size corrections in GLMs, called Bartlett corrections, but they're not easy to compute/widely available.)