I need to figure out how to run a set of custom contrasts for a glmmTMB
model with a polynomial predictor. I followed the answer given here for allowing glht
to work with theglmmTMB
model, but I'm still failing, seemingly at two stages:
1) how do I define the contrasts for a polynomial predictor? I need to use the list() approach, since my actual model is quite complex and I'll definitely mess up the matrix
approach
2) once the contrasts are set up - how do I run them for glmmTMB
specifically?
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"))
EDIT One addition - since my actual model is zero-inflated, how does this approach handle that? I'm only interested in testing the "response" values (i.e., combined zero-inflation and counts).