[英]getting confidence intervals from coeftest?
有沒有辦法讓 coeftest 報告置信區間? 還是一個從 coef 結果計算置信區間的命令?
虛擬數據:
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
那會有幫助嗎?
library(lmtest)
data("mtcars")
testmodel <- glm(am ~ vs, data = mtcars, family = quasibinomial(link = "logit"))
testcoef <- coeftest(testmodel)
confint(testcoef)
coefci(testmodel)
在@Will 之后,您可以使用cbind
將coeftest
與coefci
結合起來
cbind(coeftest(testmodel), coefci(testmodel))
cbind(coeftest(testmodel), confint(testmodel)) ## profile CIs (more accurate)
或使用broom::tidy
:
library(broom)
tidy(testmodel, conf.int = TRUE) ## profile CIs (the only option)
如果你有多個模型,使用purrr::map_dfr
合並結果很方便:
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")
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.