Reputation: 19
How do I resolve the error: "Error in family$family : $ operator not defined for this S4 class", when running a zipoisson model in this code? I have tried a poisson model and a quasi poisson model? I believe a 0-inflated Poisson model would better simulate the actual structure of the data, which was skewed by a large number of zeros.
# Fit the GLMM model for zero-inflated Poisson with mean duration
GLMM_freq_dur <- glmmTMB(N.x ~ duration * Sex + (1 | focalID) + (1 | videoID),
data = GLMM_data,
family = poisson (link='log'),zi=~1|focalID,
control = glmmTMBControl(optimizer = "bobyqa", optCtrl =
list(maxfun = 1e6))) # Increase max iterations
# Fit the GLMM model for zero-inflated Poisson with number of action units
GLMM_freq_au <- glmmTMB(N ~ Total_AU * Sex + (1 | focalID) + (1 | videoID),
data = GLMM_data,
family = zipoisson,
control = glmmTMBControl(optimizer = "bobyqa", optCtrl =
list(maxfun = 1e6))) # Increase max iterations
Upvotes: 1
Views: 71
Reputation: 226007
glmmTMB
doesn't have a "zipoisson" family. Instead, you specify a zero-inflated model by specifying the ziformula
argument, e.g.
GLMM_freq_au <- glmmTMB(N ~ Total_AU * Sex + (1 | focalID) + (1 | videoID),
data = GLMM_data,
family = poisson,
ziformula = ~ 1)
if you want to specify a single zero-inflation probability that is constant across all observations, or ziformula ~ .
if you want to include everything that's in the 'main' (conditional) model formula, or something in between, e.g. ziformula ~ Total_AU * Sex
if you wanted to include the fixed effects but not the random effects in the zero-inflation term.
More specifically, I think this particular unhelpful error message occurred because you have the VGAM
package (which includes VGAM::zipoisson, which returns an S4 function) loaded. The development version of glmmTMB
will give a slightly more informative error message ...
Upvotes: 0