Home > Mobile >  getting confidence intervals from coeftest?
getting confidence intervals from coeftest?

Time:06-18

Is there a way to get coeftest to report confidence intervals? Or a command that will calculate confidence intervals from coef results?

dummy data:

library(lmtest)
data("mtcars")
testmodel <- glm(am ~ vs, data = mtcars, family = quasibinomial(link = "logit"))
testcoef <- coeftest(testmodel)
testcoef
z test of coefficients:

            Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.69315    0.51640 -1.3423   0.1795
vs           0.69315    0.75593  0.9169   0.3592

CodePudding user response:

would that help?

library(lmtest)
data("mtcars")
testmodel <- glm(am ~ vs, data = mtcars, family = quasibinomial(link = "logit"))
testcoef <- coeftest(testmodel)

confint(testcoef)
coefci(testmodel)

CodePudding user response:

Following @Will, you could use cbind to combine coeftest with coefci

cbind(coeftest(testmodel), coefci(testmodel))
cbind(coeftest(testmodel), confint(testmodel))  ## profile CIs (more accurate)

Or use broom::tidy:

library(broom)
tidy(testmodel, conf.int = TRUE)  ## profile CIs (the only option)

If you have multiple models, it's convenient to use purrr::map_dfr to combine the results:

data(mtcars)
m1 <- glm(am ~ vs, data = mtcars, family = quasibinomial(link = "logit"))
m2 <- update(m1, . ~ mpg)
(list(vs = m1, mpg = m2)
  |> purrr::map_dfr(tidy, conf.int = TRUE, .id = "model")
)
  •  Tags:  
  • r
  • Related