简体   繁体   中英

getting confidence intervals from coeftest?

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

would that help?

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

confint(testcoef)
coefci(testmodel)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM