emmeans()
也应该适用于glmmTMB模型。对我来说,它有效,并且 CI 也被反向转换(从对数尺度):
library(glmmTMB)
data(Salamanders)
m <- glmmTMB(
count ~ spp + mined + (1 | site),
ziformula = ~ spp + mined,
family = truncated_poisson,
data = Salamanders
)
emmeans::emmeans(m, "spp", type = "response")
#> spp rate SE df lower.CL upper.CL
#> GP 1.553 0.223 627 1.171 2.06
#> PR 0.922 0.251 627 0.540 1.57
#> DM 1.944 0.250 627 1.511 2.50
#> EC-A 1.277 0.246 627 0.875 1.86
#> EC-L 2.965 0.337 627 2.372 3.71
#> DES-L 2.844 0.321 627 2.280 3.55
#> DF 1.626 0.222 627 1.244 2.13
#>
#> Results are averaged over the levels of: mined
#> Confidence level used: 0.95
#> Intervals are back-transformed from the log scale
由reprex 包(v0.3.0)于 2019 年 8 月 9 日创建
如果您需要零通货膨胀的混合模型的预测值(和置信区间) ,则计算会稍微复杂一些,但在ggeffects-package中实现。您可以在此小插图中找到更多详细信息。
默认情况下,两者predict()
都emmeans()
不会返回最合适的置信区间,正如 Brooks 等人提出的那样。(见https://journal.r-project.org/archive/2017/RJ-2017-066/RJ-2017-066.pdf,附录)。
请参阅此处的示例:
library(glmmTMB)
data(Salamanders)
m <- glmmTMB(
count ~ spp + mined + (1 | site),
ziformula = ~ spp + mined,
family = truncated_poisson,
data = Salamanders
)
# emmeans, not taking zero-inflation component into account
emmeans::emmeans(m, "spp", type = "response")
#> spp rate SE df lower.CL upper.CL
#> GP 1.553 0.223 627 1.171 2.06
#> PR 0.922 0.251 627 0.540 1.57
#> DM 1.944 0.250 627 1.511 2.50
#> EC-A 1.277 0.246 627 0.875 1.86
#> EC-L 2.965 0.337 627 2.372 3.71
#> DES-L 2.844 0.321 627 2.280 3.55
#> DF 1.626 0.222 627 1.244 2.13
#>
#> Results are averaged over the levels of: mined
#> Confidence level used: 0.95
#> Intervals are back-transformed from the log scale
# ggeffects with emmeans, not taking zero-inflation
# component into account
ggeffects::ggemmeans(m, "spp", type = "fe")
#>
#> # Predicted counts of count
#> # x = spp
#>
#> x predicted conf.low conf.high
#> GP 1.553 1.171 2.059
#> PR 0.922 0.540 1.574
#> DM 1.944 1.511 2.502
#> EC-A 1.277 0.875 1.863
#> EC-L 2.965 2.372 3.707
#> DES-L 2.844 2.280 3.549
#> DF 1.626 1.244 2.126
# ggeffects with emmeans, taking zero-inflation
# component into account
ggeffects::ggemmeans(m, "spp", type = "fe.zi")
#>
#> # Predicted counts of count
#> # x = spp
#>
#> x predicted conf.low conf.high
#> GP 0.567 0.483 0.651
#> PR 0.089 0.072 0.107
#> DM 0.911 0.773 1.048
#> EC-A 0.204 0.167 0.242
#> EC-L 1.389 1.172 1.606
#> DES-L 1.506 1.268 1.744
#> DF 0.762 0.637 0.886
由reprex 包(v0.3.0)于 2019 年 8 月 9 日创建