我正在尝试打印使用 glmmTMB 和 modelsummary 估计的零膨胀泊松模型的条件和零膨胀模型,但我无法这样做。
这是我迄今为止的尝试,遵循here
描述的语法Owls <- transform(Owls,
Nest=reorder(Nest,NegPerChick),
NCalls=SiblingNegotiation,
FT=FoodTreatment)
fit_zipoisson <- glmmTMB(NCalls~(FT+ArrivalTime)*SexParent+
offset(log(BroodSize))+(1|Nest),
data=Owls,
ziformula=~1,
family=poisson)
ti <- list(
broom.mixed::tidy(fit_zipoisson) |>
filter(effect=="fixed" & component=="cond"),
broom.mixed::tidy(fit_zipoisson) |>
filter(effect=="fixed" & component=="zi")
)
gl <- list(
broom.mixed::glance(fit_zipoisson),
broom.mixed::glance(fit_zipoisson)
)
mod <- list(
tidy = ti,
glance = gl)
class(mod) <- "modelsummary_list"
modelsummary(mod)
返回:
Error: `estimate` is not available. The `estimate` and `statistic` arguments must correspond to column names in the output of this command: `get_estimates(model)`
我猜这个语法不支持传递列表?
您可以使用
shape
参数使用 get_estimates()
函数返回的列名来构造表。
library(modelsummary)
library(glmmTMB)
Owls <- transform(Owls,
Nest = reorder(Nest, NegPerChick),
NCalls = SiblingNegotiation,
FT = FoodTreatment)
fit <- glmmTMB(
NCalls ~ (FT + ArrivalTime) * SexParent +
offset(log(BroodSize)) + (1 | Nest),
data = Owls,
ziformula = ~1,
family = poisson)
get_estimates(fit)
#> term estimate std.error conf.level
#> 1 (Intercept) 2.53994692 0.35656284 0.95
#> 2 FTSatiated -0.29110639 0.05960977 0.95
#> 3 ArrivalTime -0.06807809 0.01427062 0.95
#> 4 SexParentMale 0.44884508 0.45002291 0.95
#> 5 FTSatiated:SexParentMale 0.10472505 0.07286248 0.95
#> 6 ArrivalTime:SexParentMale -0.02139750 0.01834893 0.95
#> 7 (Intercept) -1.05753356 0.09411867 0.95
#> 8 SD (Intercept Nest) 0.35966420 NA 0.95
#> conf.low conf.high statistic df.error p.value effect
#> 1 1.84109659 3.23879725 7.1234201 Inf 1.052813e-12 fixed
#> 2 -0.40793938 -0.17427339 -4.8835350 Inf 1.042007e-06 fixed
#> 3 -0.09604799 -0.04010818 -4.7705056 Inf 1.837640e-06 fixed
#> 4 -0.43318360 1.33087377 0.9973827 Inf 3.185788e-01 fixed
#> 5 -0.03808278 0.24753288 1.4372974 Inf 1.506335e-01 fixed
#> 6 -0.05736075 0.01456575 -1.1661442 Inf 2.435562e-01 fixed
#> 7 -1.24200277 -0.87306435 -11.2361715 Inf 2.708767e-29 fixed
#> 8 0.25483237 0.50762131 NA NA NA random
因此我们使用
component
列来对参数进行排序。请注意,公式的顺序对于表的结构很重要,正如手册页和 modelsummary(list(fit, fit),
shape = component + statistic ~ model)
+-----------------------------+---------------+---------+---------+
| | component | (1) | (2) |
+=============================+===============+=========+=========+
| (Intercept) | conditional | 2.540 | 2.540 |
+-----------------------------+---------------+---------+---------+
| | | (0.357) | (0.357) |
+-----------------------------+---------------+---------+---------+
| | zero_inflated | -1.058 | -1.058 |
+-----------------------------+---------------+---------+---------+
| | | (0.094) | (0.094) |
+-----------------------------+---------------+---------+---------+
| FTSatiated | conditional | -0.291 | -0.291 |
+-----------------------------+---------------+---------+---------+
| | | (0.060) | (0.060) |
+-----------------------------+---------------+---------+---------+
| ArrivalTime | | -0.068 | -0.068 |
+-----------------------------+---------------+---------+---------+
| | | (0.014) | (0.014) |
+-----------------------------+---------------+---------+---------+
| SexParentMale | | 0.449 | 0.449 |
+-----------------------------+---------------+---------+---------+
| | | (0.450) | (0.450) |
+-----------------------------+---------------+---------+---------+
| FTSatiated × SexParentMale | | 0.105 | 0.105 |
+-----------------------------+---------------+---------+---------+
| | | (0.073) | (0.073) |
+-----------------------------+---------------+---------+---------+
| ArrivalTime × SexParentMale | | -0.021 | -0.021 |
+-----------------------------+---------------+---------+---------+
| | | (0.018) | (0.018) |
+-----------------------------+---------------+---------+---------+
| SD (Intercept Nest) | | 0.360 | 0.360 |
+-----------------------------+---------------+---------+---------+
| Num.Obs. | | 599 | 599 |
+-----------------------------+---------------+---------+---------+
| R2 Marg. | | 0.015 | 0.015 |
+-----------------------------+---------------+---------+---------+
| R2 Cond. | | 0.066 | 0.066 |
+-----------------------------+---------------+---------+---------+
| AIC | | 4015.6 | 4015.6 |
+-----------------------------+---------------+---------+---------+
| BIC | | 4050.8 | 4050.8 |
+-----------------------------+---------------+---------+---------+
| ICC | | 0.1 | 0.1 |
+-----------------------------+---------------+---------+---------+
| RMSE | | 5.96 | 5.96 |
+-----------------------------+---------------+---------+---------+