Written and maintained by CASRAI Editorial Board
Last updated
glmmTMB is an R package that fits linear and generalized linear mixed models with extensions such as zero-inflation, using the same formula syntax as lme4. This page is for researchers and analysts who need to fit a count, binomial or continuous mixed model in R, choose the family and zero-inflation arguments, and read the result and its warnings.
What glmmTMB is used for in research
The CRAN description is “Fit linear and generalized linear mixed models with various extensions, including zero-inflation.” In practice one function, glmmTMB(), covers models with random effects (for example repeated measures, sites or clusters) where the response is a count, a binomial outcome or a continuous measure, and where you may also need to model excess zeros or a dispersion that differs between groups. For the model class itself see generalized linear mixed models explained; for the lme4 route see lmer in R.
Choosing family, ziformula and dispformula
The table maps a data situation to the arguments documented in the package reference (checked 2026-11-08).
| Data situation | Arguments | Documented behaviour |
|---|---|---|
| Counts with excess zeros | family = poisson or nbinom2, plus ziformula = ~ predictors |
Default ziformula = ~0 means no zero-inflation; ~. reuses the right-hand side of the main formula; zero-inflation uses a logit link. |
| Hurdle model for counts | family = truncated_poisson with ziformula |
Used in the package reference examples. |
| Binomial proportions | family = binomial with cbind(successes, failures) as the response |
The reference example uses the cbpp data from lme4. |
| Variance that differs between groups | dispformula = ~ predictor |
Fixed effects only; default ~1; log link; ignored for families without a dispersion parameter. |
| Overdispersed or hard-to-converge counts | nbinom1, nbinom2, compois |
The troubleshooting vignette suggests these as alternatives to genpois, which has known convergence problems. |
All available families are listed in ?family_glmmTMB.
Install or access (CRAN)
glmmTMB is distributed on CRAN, with binaries for Windows and macOS. At the time of reading (2026-11-08) CRAN lists version 1.1.15.2, published 2026-09-29, which depends on R 3.6.0 or later. Installing from source requires GNU make and compiles against TMB and RcppEigen.
install.packages("glmmTMB")
library(glmmTMB)
Step-by-step: a zero-inflated count model with the Salamanders data
These steps use examples from the package reference. The Salamanders data ships with the package.
- Load the package:
library(glmmTMB) - Fit a Poisson model with a random intercept for site and zero-inflation depending on mining status:
m1 <- glmmTMB(count ~ mined + (1|site), zi = ~mined, family = poisson, data = Salamanders) - Inspect it:
summary(m1) - Try a negative binomial family with more predictors:
m2 <- glmmTMB(count ~ spp + mined + (1|site), zi = ~spp + mined, family = nbinom2, data = Salamanders) - For a binomial outcome, give successes and failures as a two-column response:
data(cbpp, package = "lme4")glmmTMB(cbind(incidence, size - incidence) ~ period + (1|herd), family = binomial, data = cbpp) - To model dispersion separately:
glmmTMB(x ~ sd + (1|t), dispformula = ~sd, data = dat), thenfixef(m)$dispreturns the dispersion coefficients.
The formula combines fixed and random effects in lme4 syntax, so (1|site) is a random intercept by site.
Output and how to read it
summary() reports the fitted model; fixef() returns fixed-effect estimates, and the dispersion part is reached as fixef(m)$disp. The zero-inflation part uses a logit link and the dispersion part a log link, so coefficients for those components are on those scales, not the scale of the count. Before interpreting any model, confirm it converged properly: the troubleshooting vignette states that models with a non-positive definite Hessian “should be excluded from further consideration”, and that sdr$pdHess can be checked. NA or NaN standard errors, log-likelihood or AIC are the visible symptom. For count models in general see Poisson regression analysis.
Troubleshooting
From the package troubleshooting vignette (read 2026-11-08):
| Warning or symptom | Documented causes | Documented fixes |
|---|---|---|
| Non-positive-definite Hessian; NA/NaN standard errors, logLik or AIC | Overparameterization; singular fit with too few random-effect levels; zero-inflation or dispersion near zero; complete separation in binomial models; a dispersion model on equidispersed data | Look for extreme coefficients (absolute value above 10 on a logit or log link is suspect); simplify the model; check sdr$pdHess |
| Eigenvalue problems | Predictors on very different scales | Rescale and center predictors; consider nbinom1, nbinom2 or compois instead of genpois |
| NA/NaN function evaluation, or Cholmod “not positive definite” | Usually a transient optimizer step | Ignorable if the final fit has no warnings |
| False convergence (nlminb) | Optimizer stopped early | Restart at the estimated values or try another optimizer such as optim BFGS, then confirm results are similar |
| NA/NaN gradient | Response does not fit the family (for example negative values with nbinom) |
Check the response against the family |
| Gradient length error | Model too complex for the data | Rescale, simplify, then build the model up step by step |
Free alternatives
| Tool | Relationship to glmmTMB | More on CASRAI |
|---|---|---|
lme4 (lmer, glmer) |
glmmTMB formulas use lme4 syntax, so formulas carry over | lmer in R |
nlme (lme) |
Another free R package for mixed models | LME in R with nlme |
| afex | R package for factorial ANOVA designs | afex R package guide |
FAQ
Does glmmTMB use the same formula syntax as lme4?
Yes. The reference states that the formula combines fixed and random effects in lme4 syntax.
How do I turn zero-inflation off or on?
The default ziformula = ~0 fits no zero-inflation. Supply a one-sided formula such as ~mined to model it, or ~. to reuse the main formula.
Where can I find worked examples?
The CRAN vignettes include Basic examples, Covariance structures, Model evaluation, Priors, Simulate and Troubleshooting.
Sources
- CRAN package page, glmmTMB: cran.r-project.org/web/packages/glmmTMB (read 2026-11-08)
- Reference for
glmmTMB(): glmmtmb.github.io/glmmTMB/reference/glmmTMB.html (read 2026-11-08) - Troubleshooting vignette: cran.r-project.org/web/packages/glmmTMB/vignettes/troubleshooting.html (read 2026-11-08)







