简体   繁体   中英

Negative Binomial Model in R: glmer.nb

Running this glmer.nb , I received the error message

boundary (singular) fit: see?isSingular

Warning message: In theta.ml(Y, mu, weights = object@resp$weights, limit = limit, : iteration limit reached

I ran singular(model) and it return TRUE . Then I ran summary(model) and it showed the warning message

Warning messages: 1: In vcov.merMod(object, use.hessian = use.hessian): variance-covariance matrix computed from finite-difference Hessian is not positive definite or contains NA values: falling back to var-cov estimated from RX 2: In vcov.merMod(object, correlation = correlation, sigm = sig): variance-covariance matrix computed from finite-difference Hessian is not positive definite or contains NA values: falling back to var-cov estimated from RX

I looked up and it seems like the warning message suggests that the model is not accurate. But I am not sure what I can do to resolve the warning. I would highly appreciate any help!

model <- glmer.nb(Level ~ var1+var2+var3+var4+var5+var6+(1|ID),data = df)
summary(model)
df<-structure(list(ID = c("A", "B", "C", "D", "E", "F", "G", "H", 
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", 
"V", "W", "X"), var1 = c(0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 
1, 1, 0, 2, 0, 0, 0, 0, 3, 0, 0, 5), var2 = c(0, 2, 2, 1, 1, 
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 3, 1, 0, 0), var3 = c(0, 
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0), var4 = c(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 1, 0, 0, 0), var5 = c(0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), var6 = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0), Level = c(1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 
1, 0, 1, 0, 1, 1, 0, 1, 0)), row.names = c(NA, -24L), class = "data.frame")

R has limited support for running a zero-inflated/negative binomial random effects model, but there are some options. Given the comments, I agree with @IRTFM in that it seems like your data are in the wrong structure for a repeated measures analysis - see here . You can restructure your data and try running the model, though it does not seem to converge nicely, likely due to small sample size (though it does produce results).

df.lng <- df %>% pivot_longer(-c(ID, Level), names_to = "repeatedMeasure", values_to = "value")
df.lng[2:ncol(df.lng)] <- lapply(df.lng[1:ncol(df.lng)], as.factor) # convert to factors

# Using lme4 
library(lme4)
model <- glmer.nb(Level ~ repeatedMeasure + (1|ID), data = df.lng)
summary(model)

# Using glmmTMB
library(glmmTMB)
glmmTMB(Level ~ 1 + repeatedMeasure + (1|ID), data = df.lng,
        family = "nbinom2",
        ziformula= ~ 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM