mindlessgreen
mindlessgreen

Reputation: 12142

R: glmer.nb error

I get the following error:

Error in if (family$family %in% c("quasibinomial", "quasipoisson", "quasi")) stop("\"quasi\" families cannot be used in glmer") : 
  argument is of length zero

when I run a glmm negative binomial model as below.

library(lme4)
nm <- glmer.nb(value~(1|replicate)+(1|family)+condition,data=cdat)

I have a data set that looks like below:

cdat
   condition family replicate value
1          c     20         1  60
2          c     20         2 131
3          c     20         3  84
4          c     21         1 179
5          c     21         2  98
6          c     21         3 107
7          c     27         1  80
8          c     27         2  72
9          c     27         3  84
10         c     30         1  87
11         c     30         2  81
12         c     30         3 120
13         l     20         1 136
14         l     20         2 101
15         l     20         3  88
16         l     21         1  83
17         l     21         2  52
18         l     21         3  77
19         l     27         1 136
20         l     27         2 110
21         l     27         3 126
22         l     30         1  69
23         l     30         2  77
24         l     30         3 115

str(cdat)
'data.frame':   24 obs. of  4 variables:
 $ condition: Factor w/ 2 levels "c","l": 1 1 1 1 1 1 1 1 1 1 ...
 $ family   : Factor w/ 4 levels "20","21","27",..: 1 1 1 2 2 2 3 3 3 4 ...
 $ replicate: Factor w/ 3 levels "1","2","3": 1 2 3 1 2 3 1 2 3 1 ...
 $ value      : int  60 131 84 179 98 107 80 72 84 87 ...

There is no family argument in glmer.nb and it cannot be changed. I am generally interested in comparing the two conditions while controlling for biological differences between families and replicates. I hope my model is correct.

Upvotes: 1

Views: 1719

Answers (2)

Ben Bolker
Ben Bolker

Reputation: 226771

I can't replicate the problem with a fresh install of the current version of lme4 from CRAN:

packageVersion("lme4")
## [1] ‘1.1.12’

library(lme4)
g1 <- glmer.nb(value~condition+(1|replicate)+(1|family),data=cdat)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: Negative Binomial(14.228)  ( log )
## Formula: value ~ condition + (1 | replicate) + (1 | family)
##    Data: cdat
##       AIC       BIC    logLik  deviance  df.resid 
##  236.4621  242.3524 -113.2311  226.4621        19 
## Random effects:
##  Groups    Name        Std.Dev.
##  family    (Intercept) 0       
##  replicate (Intercept) 0       
## Number of obs: 24, groups:  family, 4; replicate, 3
## Fixed Effects:
## (Intercept)   conditionl  
##     4.59090     -0.01105  
  • glmer.nb estimates zero variance for both random effects, not really surprising with such a small data set - usually a minimum of 5 levels is needed for a reasonable hope of non-zero variance estimates.
  • I often recommend using a linear model on transformed data when the means are so large (and variances not too large), even though I appreciate that it's nice to use a model built for count data ... when the shape parameter is much less than the mean of the data, that means that most of the data are in the range where the quadratic term of the variance dominates, hence a log-Normal or Gamma model might work fine.

Upvotes: 3

StasK
StasK

Reputation: 1555

Negative binomial is a one-way random effect Poisson model, where the random effects are gamma distributed. The family argument is implicit in the call to glmer: I imagine that glmer.nb is but a wrapper to glmer that supplies the call with the family=poisson argument somewhere deep inside. In your case, though, it did not work: I am not sure that the two-way model, the way you specified, is a statistical possibility. Apparently, the way glmer parsed your request was to attempt to generalize the nb model (which, as I said above, is an overdispersed poisson), and the best it could do is with that quasi stuff... and it failed.

You may want to try falling back onto Poisson, with the two-way effects you are interested in, and see if it runs.

Upvotes: 0

Related Questions