admin管理员组

文章数量:1123768

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

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
Share Improve this question edited 14 hours ago Siddharth Satishchandran asked yesterday Siddharth SatishchandranSiddharth Satishchandran 92 bronze badges 3
  • 3 There's too much code here to be able to easily identify which part is causing the error, and without any example data we can't run it for ourselves to see when it throws the error. Please see How to write a good R question with a reproducible example. – Eonema Commented yesterday
  • Does the glmmTMB package have an example that you can adapt and get the same error? This might shorten the development of an example appropriate to this question. You don’t have a minimal example. – IRTFM Commented yesterday
  • Perhaps a duplicate of stackoverflow.com/questions/39727183/… – IRTFM Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 0

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.

(The error message should be better, though ...)

本文标签: