0

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")
karyn-h
  • 133
  • 7
  • Is this your whole data set or a subset? – Ben Bolker Jan 06 '22 at 00:08
  • This is the whole data set – karyn-h Jan 06 '22 at 00:13
  • Why are you using `+(1|ID)` when you only have one line of data per ID? – IRTFM Jan 06 '22 at 00:21
  • I am sorry, I am new to this model. Var1 to Var6 are repeated measures so I suppose they are needed. Also, the model would not run without this argument as it gives `Error: No random effects terms specified in formula` – karyn-h Jan 06 '22 at 00:23
  • You are calling Var1-Var6 repeated measures but they are on the same line. If they represent the same measure, then you need to make this into a "long" dataframe with a single variable Var that variesa over time and then it might make sense to have a clustering structure to your model. Unfortunately, you only have one Level per ID so that's not really going to work. – IRTFM Jan 06 '22 at 00:30
  • Thank you @IRTFM, it makes sense. Do you happen to know a way to run the negative binomial model without having a cluster? – karyn-h Jan 06 '22 at 00:36
  • 2
    Sure. The `glm.nb` function in pkg:MASS can do it. However I'm not sure that you have enough data and I'm not sure what the research question is. You still only have one value of Level and it's not clear How that single level is related to a "repeated measure" of the "var"'s. – IRTFM Jan 06 '22 at 00:42
  • Thank you very much for your help! @IRTFM – karyn-h Jan 06 '22 at 00:53
  • 1
    I'm still unclear on the experimental design/meaning of the data. If `Level` is the response variable, then it appears to be binary (so it's not obvious why you would want to fit a negative binomial model, which is for count data?) I guess `Var1`-`Var6` are repeated measures through time of something. Repeated measures are usually repeated measurements of a *response* variable ... It might be good to post this to [CrossValidated](https://stats.stackexchange.com), with a lot more context about the experimental design and scientific question ... – Ben Bolker Jan 06 '22 at 16:12

1 Answers1

1

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)
jpsmith
  • 11,023
  • 5
  • 15
  • 36