我按照此页面上的说明进行操作: https://strengejacke.github.io/ggeffects/articles/practical_robustestimation.html
我做了一个没有稳健标准误差的基本回归:
data(mtcars)
reg <- glm(vs ~ mpg + cyl + disp + hp, mtcars, family="binomial")
screenreg(reg)
然后我得到了预测值:
ggpredict(reg, terms=c("mpg")) %>% as_tibble()
假设我想要稳健的标准误差。我可以通过
coeftest
执行此操作并相应地更改 screenreg
输出:
reg2 <- coeftest(reg, vcov = vcovHC, type = "HC1", cluster = "ResponseId")
screenreg(list(reg),
override.se=list(
reg2[,2]),
override.pvalues=list(
reg2[,4]))
但是,当考虑到稳健标准误差来查看预测值时,这些值是完全相同的。
ggpredict(reg, terms=c("mpg"), vcov_fun = "vcovHC", vcov_type = "HC1") %>% as_tibble()
我假设由于回归输出中的标准误差不同,我也会看到
ggpredict
输出的变化。我错过了什么?
奇怪,我无法重现你的例子。你安装了sandwich包吗?当我运行你的代码时,CI 和 SE 都不同:
library(ggeffects)
data(mtcars)
reg <- glm(vs ~ mpg + cyl + disp + hp, mtcars, family="binomial")
ggpredict(reg, "mpg")
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#> plots.
#> # Predicted probabilities of vs
#>
#> mpg | Predicted | 95% CI
#> ----------------------------
#> 10 | 0.70 | 0.02, 1.00
#> 12 | 0.61 | 0.03, 0.99
#> 16 | 0.39 | 0.05, 0.89
#> 20 | 0.21 | 0.03, 0.70
#> 22 | 0.15 | 0.01, 0.70
#> 24 | 0.10 | 0.00, 0.74
#> 28 | 0.05 | 0.00, 0.86
#> 34 | 0.01 | 0.00, 0.96
#>
#> Adjusted for:
#> * cyl = 6.19
#> * disp = 230.72
#> * hp = 146.69
#>
#> Not all rows are shown in the output. Use `print(..., n = Inf)` to show
#> all rows.
ggpredict(reg, "mpg", vcov_fun = "vcovHC", vcov_type = "HC1")
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#> plots.
#> # Predicted probabilities of vs
#>
#> mpg | Predicted | 95% CI
#> ----------------------------
#> 10 | 0.70 | 0.04, 0.99
#> 12 | 0.61 | 0.05, 0.98
#> 16 | 0.39 | 0.07, 0.84
#> 20 | 0.21 | 0.08, 0.48
#> 22 | 0.15 | 0.05, 0.38
#> 24 | 0.10 | 0.02, 0.37
#> 28 | 0.05 | 0.00, 0.45
#> 34 | 0.01 | 0.00, 0.63
#>
#> Adjusted for:
#> * cyl = 6.19
#> * disp = 230.72
#> * hp = 146.69
#>
#> Not all rows are shown in the output. Use `print(..., n = Inf)` to show
#> all rows.
ggpredict(reg, "mpg") |> as.data.frame()
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#> plots.
#> x predicted std.error conf.low conf.high group
#> 1 10 0.70259351 2.494497 1.747344e-02 0.9968235 1
#> 2 12 0.60535681 2.056297 2.653409e-02 0.9885484 1
#> 3 14 0.49899836 1.652617 3.757648e-02 0.9621327 1
#> 4 16 0.39273047 1.315624 4.677843e-02 0.8949872 1
#> 5 18 0.29573482 1.107940 4.568542e-02 0.7864790 1
#> 6 20 0.21424339 1.105050 3.031314e-02 0.7039801 1
#> 7 22 0.15041153 1.308311 1.344489e-02 0.6969606 1
#> 8 24 0.10310235 1.642913 4.571786e-03 0.7420843 1
#> 9 26 0.06945689 2.045381 1.353191e-03 0.8043664 1
#> 10 28 0.04622510 2.482931 3.730739e-04 0.8628956 1
#> 11 30 0.03050906 2.939941 9.893732e-05 0.9091607 1
#> 12 32 0.02002413 3.408591 2.564065e-05 0.9421399 1
#> 13 34 0.01309385 3.884672 6.548620e-06 0.9641321 1
ggpredict(reg, "mpg", vcov_fun = "vcovHC", vcov_type = "HC1") |> as.data.frame()
#> Data were 'prettified'. Consider using `terms="mpg [all]"` to get smooth
#> plots.
#> x predicted std.error conf.low conf.high group
#> 1 10 0.70259351 2.0829964 0.0383122772 0.9929123 1
#> 2 12 0.60535681 1.7346301 0.0487080617 0.9787027 1
#> 3 14 0.49899836 1.3958193 0.0606674610 0.9388743 1
#> 4 16 0.39273047 1.0756319 0.0728272983 0.8418890 1
#> 5 18 0.29573482 0.7968433 0.0809524471 0.6668767 1
#> 6 20 0.21424339 0.6182533 0.0750705886 0.4780690 1
#> 7 22 0.15041153 0.6315201 0.0488399517 0.3790411 1
#> 8 24 0.10310235 0.8274665 0.0222040963 0.3678585 1
#> 9 26 0.06945689 1.1135020 0.0083468764 0.3982797 1
#> 10 28 0.04622510 1.4367934 0.0028918349 0.4474840 1
#> 11 30 0.03050906 1.7771230 0.0009655520 0.5060871 1
#> 12 32 0.02002413 2.1263255 0.0003164239 0.5687938 1
#> 13 34 0.01309385 2.4806565 0.0001026144 0.6317112 1
创建于 2024-02-22,使用 reprex v2.1.0