首页 > 解决方案 > 事后自定义对比 - glmmTMB 与 poly()

问题描述

我需要弄清楚如何为glmmTMB具有多项式预测器的模型运行一组自定义对比。我按照此处给出的答案允许glht使用该glmmTMB模型,但我仍然失败,似乎处于两个阶段:1)如何定义多项式预测器的对比?我需要使用 list() 方法,因为我的实际模型非常复杂,而且我肯定会弄乱matrix方法 2) 一旦设置了对比 - 我该如何glmmTMB专门运行它们?

library(contrast)
library(glmmTMB)

set.seed(1)
df <- structure(list(x = 1:20, y = c(4L, 7L, 11L, 12L, 23L, 21L, 42L, 
56L, 70L, 80L, 95L, 120L, 152L, 187L, 224L, 280L, 326L, 374L, 
438L, 500L), z = structure(c(2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L), .Label = c("a", 
"b"), class = "factor"), group = structure(c(1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), class = "factor", .Label = "1")), class = "data.frame", row.names = c(NA, 
-20L))

#just a toy example with a linear model and no poly()
m <- lm(y ~ x * z, data = df)
contrast(m, 
        a = list(x = 1, z = "a"),
        b = list(x = 10, z = "b"))

# a (big) simplification of what I'm after:
m1 <- glmmTMB(y ~ poly(x, 3) * z + (1|group), data = df, family = poisson)
contrast(m1, 
        a = list(x = 1, z = "a"),
        b = list(x = 10, z = "b"))

编辑一个补充——因为我的实际模型是零膨胀的,这种方法是如何处理的?我只对测试“响应”值(即零通货膨胀和计数)感兴趣。

标签: rmixed-modelsposthoc

解决方案


推荐阅读