Statistics Glossary → Generalized Linear Mixed Models (GLMM)
Generalized Linear Mixed Models (GLMM)analysis
A regression method for binary or count outcomes in data where observations are grouped in clusters such as patients, schools, herds or sites, modelling them with random effects that vary between clusters in addition to fixed effects.
Concept
Logistic and Poisson regression assume independent observations. Yet the probability of illness among animals in the same herd, the risk of complications among patients in the same hospital or the success of pupils in the same school resemble one another. A generalised linear mixed model (GLMM) captures this similarity by adding a cluster-specific random effect to a generalised linear model.
The model links the expected value of the outcome, through a link function, to both the fixed effects and each cluster's random deviation; for a binary outcome, for instance, logit P(y = 1) = β₀ + β₁x₁ + … + uⱼ. Here uⱼ is the j-th cluster's departure from the average and is assumed to be normally distributed; its variance (σ²ᵤ) shows how large the differences between clusters are. The coefficients are subject- or cluster-specific (conditional) effects: they answer 'within the same cluster, how much do the odds change when a predictor changes by one unit?'. Because the likelihood cannot be computed directly, numerical approximations such as the Laplace method or adaptive Gauss-Hermite quadrature are used.
The assumptions are that the random effects are normally distributed and that the link function and distribution family are appropriate. With overdispersed counts, the negative binomial family is needed instead of Poisson. With few clusters, the between-cluster variance is estimated imprecisely. Conditional coefficients are usually larger in absolute value than the population-averaged coefficients from GEE; which to report depends on the research question.
When to use it
- When the outcome is binary or a count and the observations are clustered or repeated, and the size of between-cluster differences and within-cluster effects are of interest (complications across hospitals, disease rates across herds, pupils passing an exam).
- For a continuous outcome use a linear mixed model (LMM); if only population-averaged rather than cluster-specific effects are wanted, use generalised estimating equations (GEE).
- Without clustering, ordinary logistic or Poisson regression is sufficient; if the counts are far more spread out than Poisson expects, the negative binomial family should be chosen.
An everyday example
A vet follows 20 cattle herds over four seasons and records in each season how many animals caught a respiratory disease, along with the size of the herd. Some herds are consistently riskier because of their housing. The GLMM takes herd as a random intercept and estimates the season effect taking these persistent differences between herds into account. If it finds OR = 2.2 for winter, then within the same herd the odds of illness in winter are about 2.2 times those in summer.
Parameters in MerQur
Independent variables, Dependent variable (DV), Group variable (random intercept)
Concept: The dependent variable and predictors define the fixed part of the model, while the grouping variable defines the random intercept that gives each cluster its own level.
Everyday example: In the herd example the dependent variable is the number of sick animals, the predictor is season and the grouping variable is the herd. The random intercept accounts for some herds being persistently riskier or safer than others.
What it does: Sets y, the fixed effects and the cluster ID of the random intercept. For text factors the first level is the baseline.
Effect on the result: Determines all output. Numeric predictors are standardized internally and transformed back; coefficients are on the original scale.
On the validation data: In hdp CancerStage (I-IV) is a text factor with baseline level I; coefficients are reported on the original scale.
Family (Binomial (logistic) / Poisson (count) / Negative binomial NB2 (overdispersed count))
Concept: Sets the conditional distribution of the outcome: binomial for binary or events/trials data, Poisson for counts, negative binomial for counts whose variance exceeds the mean.
Everyday example: If the outcome is 'is there a sick animal in the herd?', binomial is chosen; if it is 'how many times an animal was treated in a year', Poisson. If some animals are treated very often, the counts are overdispersed and negative binomial is more suitable.
What it does: Selects the conditional distribution; for NB2 Var = μ + μ²/θ.
Effect on the result: The coefficient scale, overdispersion and θ change.
On the validation data: epilepsy Poisson trt_time -0.1047 (0.0650), NB2 -0.3119 (0.1415; θ 6.770). grouseticks NB2 θ 3.276.
Method (Maximum likelihood - adaptive Gauss-Hermite (AGQ) / Variational Bayes (VB))
Concept: Sets the estimation approach. Maximum likelihood (AGQ) gives frequentist estimates and standard errors; variational Bayes is a fast approximate Bayesian method whose posterior standard deviations can understate uncertainty, so they should not be read as frequentist standard errors.
Everyday example: If the report will give p values and confidence intervals, maximum likelihood is chosen. For a quick preliminary result on a very large dataset, variational Bayes can be used, but its measures of uncertainty should be interpreted with caution.
What it does: ML-AGQ gives the frequentist marginal likelihood, VB (mean-field) approximates the posterior.
Effect on the result: VB posterior SDs are much smaller than ML SEs; MerQur states this with a warning and the note "posterior SD; not a frequentist SE". VB is not supported for events/trials, offset, negative binomial or non-logit links; ML is used with a warning.
On the validation data: amenorrhea trt_time SE 0.0325 (VB) vs 0.1922 (ML); hdp CancerStage IV 0.1326 vs 0.1581.
nAGQ
Concept: The number of points (nodes) used to approximate numerically the likelihood integrated over the random effects. A value of 1 corresponds to the Laplace approximation; more nodes give a more accurate result but take longer.
Everyday example: If each herd has only a few animals and the disease is rare, the Laplace approximation may be crude. Raising the number of nodes to 25 reduces the error due to the approximation; going higher changes the result very little.
What it does: The number of quadrature nodes; 1 = Laplace. As it increases the marginal likelihood becomes more exact.
Effect on the result: logLik, the variance component and the coefficients change.
On the validation data: hdp logLik nAGQ 1: -3695.9925; 7: -3689.6239; 25 and 50: -3689.6165; σ²_u 3.925 -> 4.061. In amenorrhea Laplace trt_time 0.5472, nAGQ 50 0.5644.
→ Adaptive Gauss-Hermite quadrature (AGQ) and Laplace approximation
Link function (binomial) (logit / probit / cloglog)
Concept: The transformation linking the probability of a binary outcome to the linear predictor. Logit coefficients are read as odds ratios; probit works on the scale of the normal distribution, and cloglog is used when the event is rare or when the probability of occurrence within a period is modelled.
Everyday example: If the vet wants to describe results as odds ratios, logit is chosen. Changing the link changes the numerical value of the season coefficient, but the conclusion that 'risk is higher in winter' usually stays the same.
What it does: Selects the link function for a binomial response.
Effect on the result: The coefficient scale changes; the Nakagawa distribution variance becomes π²/3, 1, π²/6.
On the validation data: hdp CancerStage IV: logit -2.3371, probit -1.3397, cloglog -1.7309.
Number of trials (events/trials)
Concept: Gives the number of trials when the outcome is 'how many successes out of n trials'; the model then treats each row as a proportion rather than a single yes/no.
Everyday example: If 6 of 40 animals fell ill in one herd and 3 of 15 in another, the number of trials is the herd size. The model then assesses 6 against 40 animals and 3 against 15.
What it does: y is the number of successes and the selected column the number of trials (cbind(y, n - y)).
Effect on the result: The model is fitted as an events/trials binomial; the rate is summarised as Σy/Σn.
On the validation data: cbpp period4 -1.5795 (0.4276), σ_u 0.6475. multicenter σ²_u 0.6209.
Offset (linear-predictor scale)
Concept: A term added to the linear predictor with its coefficient fixed at 1; in count models it is usually the logarithm of observation time or exposure, so that the model explains a rate rather than a count.
Everyday example: If the outcome is 'number of treatments in a herd' and the herds were followed for different lengths of time, the log of months observed enters as an offset and the model compares treatments per month.
What it does: A term added to the linear predictor with coefficient 1 (e.g. log time).
Effect on the result: The intercept changes; if the offset is a linear combination of the other predictors, the other coefficients and logLik stay the same.
On the validation data: epilepsy intercept 1.0327 with ltime, 3.1121 without.
Random-effect LRT (GLMM vs GLM, σ²_u = 0)
Concept: Tests whether the random effect is needed, i.e. whether the between-cluster variance is zero, by comparing the models with and without the random effect. Because a variance cannot be negative, the p value is computed with a boundary correction.
Everyday example: If the test is significant, the herds really differ in disease risk, and ordinary logistic regression would have given standard errors that were too small.
What it does: Likelihood ratio against the model without the random effect for σ²_u = 0; χ²(1) and the boundary-mixture p.
Effect on the result: An extra row.
On the validation data: hdp χ² 2435.3213; cbpp 14.0917; epilepsy Poisson 2614.96, NB 243.44.
EMMEANS factor and EMMEANS p adjustment
Concept: Estimated marginal means are model-based predictions for each level of a categorical factor, given on the link scale and on the probability or count scale. Pairwise comparisons are made with a multiple-comparison correction.
Everyday example: The model might give the probability of illness in a typical herd as 0.20 in winter, 0.10 in spring, 0.08 in summer and 0.12 in autumn. Four seasons mean six pairwise comparisons, and the correction limits the risk of false alarms.
What it does: Gives marginal means on the link and response scales at the levels of a categorical factor, and adjusted pairwise comparisons.
Effect on the result: Only EMM and comparison tables are added; the main model does not change.
On the validation data: cbpp period probabilities 0.198, 0.084, 0.074, 0.048; the hdp CancerStage comparisons are reported separately with the four p adjustments.
EMM second factor (compare within each level): group x time marginal means; nAGQ 25, EMMEANS p adjustment: Tukey
Concept: In a model with a group × time interaction, compares the groups separately at each time point, showing how the group difference changes over time.
Everyday example: If half the herds were vaccinated, vaccinated and unvaccinated herds are compared in each season separately. A large difference in winter and a small one in summer shows that the vaccine protects most in the riskiest period.
What it does: Gives cell marginal means and Tukey-adjusted comparisons in a GLMM with a group x time interaction.
Effect on the result: Extra marginal-mean and comparison tables; the main model does not change.
On the validation data: In the epil (Poisson), toenail and respiratory (binary) data, the group x time marginal means and the Tukey-adjusted comparisons are reported separately at each time level.
Confidence Level
Concept: Sets the confidence level of the intervals for the coefficients and odds or rate ratios; the higher the level, the wider the interval.
Everyday example: For a winter OR of 2.2 the 95% confidence interval might be [1.3, 3.7]; at 99% it widens.
What it does: Sets the Wald interval level; the significance mark follows the interval.
Effect on the result: Only the intervals and the significance mark change.
On the validation data: hdp CancerStage IV: 80% (-2.540, -2.135), 90% (-2.597, -2.077), 99% (-2.744, -1.930).
Other outputs
Concept: Summarises the uncertainty of the between-cluster variance, the proportions of variance explained (Nakagawa R²: marginal for fixed effects only, conditional for fixed and random effects together), the intraclass correlation (ICC), overdispersion and whether there are more zeros than expected.
Everyday example: An ICC of 0.15 means that about 15% of the variation in the tendency to fall ill comes from differences between herds. If there are far more zeros than expected (many herds with no sick animals), a zero-inflated model should be considered.
What it does: SE of σ_u and σ²_u (delta method), Nakagawa R² and ICC, conditional Pearson overdispersion and a zero-inflation check.
Effect on the result: Given as extra rows in every run.
On the validation data: σ²_u SE hdp 0.4121; epilepsy Pearson overdispersion Poisson 2.294, NB 0.766; zero inflation observed 23, expected 6.229.
Example on real data
Data: Lesnoff et al. 2004 contagious bovine pleuropneumonia, lme4 cbpp
Variables: dependent incidence (new cases), number of trials size (herd size), independent period, group herd; Binomial family
- Question: Does the rate of contagious bovine pleuropneumonia (CBPP) cases (incidence / size) change over four observation periods? A random intercept was given to herd for repeated measurements of the same herd (binomial GLMM, logit, adaptive Gauss-Hermite nAGQ = 25).
- Assumption: Pearson χ² = 62.98, df = 51, ratio = 1.235, p = .121; no marked overdispersion. With only 15 herds the variance component is uncertain (SE = 0.234); the coefficients are subject-specific (conditional) effects, and GEE should be used for a population-averaged interpretation.
- Result: Compared with the first period (P1), the odds of disease fall significantly in later periods: P2 OR = 0.371 (95% CI [0.203, 0.677], p = .001), P3 OR = 0.324 (p < .001), P4 OR = 0.206 (95% CI [0.089, 0.476], p < .001). Between-herd variance σ²_u = 0.419 (SD = 0.648).
- Effect size: Latent-scale ICC = 0.113 (adjusted); Nakagawa R² marginal = .085, conditional = .189; log-likelihood = -91.98, AIC = 193.97, BIC = 204.09.
- APA: Binomial GLMM (nAGQ = 25), P4 vs P1: β = -1.58, SE = 0.43, z = -3.69, p < .001, OR = 0.21, 95% CI [0.09, 0.48]; σ²_herd = 0.42.
Related concepts
Likelihood ratio test (LRT)Adaptive Gauss-Hermite quadrature (AGQ) and Laplace approximationEstimated marginal means (EMM)Offset (exposure term)Link functionIntraclass correlation (ICC)Fixed and random effectsDistribution family (GLM)
The numbers in the examples are MerQur's output on independent, publicly available validation data; see the MerQur Technical Note for details.