Generalized Linear Models vs. Generalized Linear Mixed Models: Selection Logic and Practical Guidelines
Generalized linear models (GLMs) and generalized linear mixed models (GLMMs) can both handle binary outcomes, counts, and positive continuous variables. This article explains that the key distinction is not whether the response is normally distributed, but whether random effects are needed to represent grouped data, unobserved heterogeneity, and the dependence they induce. It reviews the components of GLMs, random intercepts and slopes, situations in which a GLM is usually sufficient, situations in which a GLMM should be considered, fixed-effects and marginal alternatives such as GEE and cluster-robust standard errors, worked examples, estimation and interpretation issues, and a practical diagnostic workflow. The aim is to help readers choose a model based on how the data are generated, the inferential target, and prediction needs rather than simple rules of thumb.
1. Start with the Core Question: Non-Normality Does Not Automatically Mean a Mixed Model
Generalized linear models (GLMs) and generalized linear mixed models (GLMMs) can both handle binary outcomes, counts, and positive continuous variables. The most important difference between them is not whether the response variable follows a normal distribution. It is whether random effects are used to describe the grouping structure of the data, unobserved heterogeneity, and the resulting correlation.
A two-sentence framework can help establish the initial judgment:
- When observational units are essentially independent and the chosen response distribution and mean structure reasonably describe the data, a GLM is usually appropriate.
- When the data involve repeated measurements, hierarchical grouping, or cross-classification, and the analysis needs to explicitly characterize group differences or make group-level predictions, a GLMM is often more suitable.
However, the statement “correlation exists, so a GLMM is required” is also imprecise. Depending on the research objective, group fixed effects, generalized estimating equations, cluster-robust standard errors, or other models for dependent data may also be appropriate. The correct question is: given the current data structure and inferential goal, are random effects needed?
2. The Three Components of a GLM
A GLM is not a single regression model. It is a unified modeling framework that usually includes a response distribution, a linear predictor, and a link function.
1. Response distribution: describing random variation in the outcome
Classical GLMs usually assume that the response variable belongs to the exponential family. Common choices include:
| Response type | Common distribution | Typical modeling target |
|---|---|---|
| Continuous, approximately symmetric | Normal distribution | Measurements, experimental results |
| Binary outcome or number of successes | Binomial distribution | Whether an event occurs, success proportion |
| Non-negative integer counts | Poisson distribution | Event counts, number of occurrences |
| Strictly positive and right-skewed | Gamma distribution | Durations, positive costs |
Distribution choice should not be based only on a histogram. It should also consider the outcome-generating mechanism, the range of values, and the relationship between the conditional mean and conditional variance.
For example, the Poisson distribution requires the conditional variance to equal the conditional mean given the explanatory variables. If the data show clear extra variation, it is necessary to examine whether omitted variables, group structure, or the distributional choice are appropriate.
2. Linear predictor: linear in the parameters
The basic structure of a GLM is:
[
g(\mu_i)=\eta_i=\mathbf{x}_i^\top\boldsymbol{\beta},
\qquad
\mu_i=E(Y_i\mid\mathbf{x}_i)
]
Here, (\mathbf{x}_i) is the vector of explanatory variables, (\boldsymbol{\beta}) is the vector of coefficients to be estimated, and (g) is the link function.
“Linear” here means that the predictor is linear in the regression coefficients. It does not require the response mean to have a straight-line relationship with the original explanatory variables. For example:
[
\eta_i=\beta_0+\beta_1t_i+\beta_2t_i^2
]
Although this includes a squared term for time, it is still a valid linear predictor because each coefficient enters the model linearly.
3. Link function: connecting the mean to the predictor
Common links include:
- Identity link: (g(\mu)=\mu);
- Log link: (g(\mu)=\log\mu);
- Log-odds link: (g(p)=\log[p/(1-p)]);
- Inverse link: (g(\mu)=1/\mu).
The link function applies to the conditional mean. It does not require applying the same transformation to each observed outcome first. For example, in Poisson regression the model is:
[
\log E(Y_i\mid\mathbf{x}_i)=\mathbf{x}_i^\top\boldsymbol{\beta}
]
It is not an ordinary linear regression on log-transformed observed counts. The two approaches have different error structures and inferential implications, and the difference is especially important when counts include zeros.
3. What GLMMs Add: Random Effects and Conditional Independence
A GLMM adds random effects to the linear predictor of a GLM:
[
g(\mu{ij})=
\mathbf{x}{ij}^\top\boldsymbol{\beta}
+\mathbf{z}_{ij}^\top\mathbf{b}_j
]
Here:
- (j) denotes a group, such as a subject, experimental batch, or survey site;
- (i) denotes an observation within the group;
- (\boldsymbol{\beta}) represents fixed effects;
- (\mathbf{b}_j) represents the random effect for group (j);
- (\mathbf{z}_{ij}) determines how the random effects enter the predictor.
A common assumption is:
[
\mathbf{b}_j\sim N(\mathbf{0},\boldsymbol{\Sigma})
]
The response variable itself can be binomial, Poisson, or another suitable distribution. The response does not become normally distributed simply because the random effects are assumed normal.
GLMMs usually assume conditional independence: given the explanatory variables and random effects, observations are independent. However, after integrating out the random effects, observations within the same group are generally no longer independent because they share the same latent group factor.
This is exactly why random effects can represent within-group correlation.
Random intercepts and random slopes
A random-intercept model is:
[
g(\mu{ij})=
\beta_0+\beta_1x{ij}+b_{0j}
]
It allows different groups to have different baseline levels.
A random-intercept and random-slope model is:
[
g(\mu{ij})=
\beta_0+\beta_1x{ij}+b{0j}+b{1j}x_{ij}
]
It further allows the effect of an explanatory variable to vary across groups. Random intercepts and random slopes can also be correlated; for example, groups with higher baseline levels may have faster or slower rates of change.
The random-effects structure should be determined jointly by the study design and the level of support in the data. More complex is not necessarily better.
4. When a GLM Is Usually Sufficient
1. One observation per independent unit
Suppose a study examines whether an event occurs, and each subject contributes only one record with no obvious shared grouping influence among subjects. A binomial GLM can be used:
[
Y_i\sim\operatorname{Bernoulli}(p_i)
]
[
\operatorname{logit}(pi)=
\beta_0+\beta_1x{i1}+\beta2x{i2}
]
If the mean structure is reasonable and observational independence approximately holds, there is no need to introduce a GLMM merely because the outcome is binary.
2. Event counts from independent units
If each record comes from a different independent observational unit, a Poisson GLM can be considered. If units have different exposure durations, an offset should be included:
[
\log\mu_i=
\log e_i+\mathbf{x}_i^\top\boldsymbol{\beta}
]
Here, (e_i) is the exposure amount, and the coefficient of (\log e_i) is fixed at 1. The model then targets the event rate per unit of exposure rather than simply comparing raw counts.
If independence holds but the conditional variance is clearly larger than the conditional mean, negative binomial regression or quasi-likelihood methods can be considered. Overdispersion does not by itself mean that a hierarchical structure exists, and it is not sufficient evidence that a GLMM is required.
3. Positive continuous outcomes with a right-skewed distribution
For outcomes that are strictly greater than zero and whose variability increases with the mean, a gamma GLM may be appropriate. With a log link:
[
\log\mu_i=\mathbf{x}_i^\top\boldsymbol{\beta}
]
The mean is always positive, and coefficients can be interpreted in terms of multiplicative changes. However, if the data contain many zeros, the ordinary gamma distribution cannot directly cover those observations, and the model must be redesigned according to the mechanism that generates the zeros.
5. When GLMMs Should Be Considered Seriously
1. The same subject is measured repeatedly
For example, the same subject may be tested at multiple time points. The results may share influences from individual physiology, baseline status, or other unobserved factors.
If these results are treated as completely independent samples in a GLM, the effective amount of information is often overestimated and standard errors may be underestimated. A random intercept can describe individual baseline differences. If individuals also have different change trajectories, a random slope for time may be considered.
A random intercept does not necessarily explain all time dependence. If clear serial correlation remains after controlling for individual differences, a more appropriate correlation structure or longitudinal model may be needed.
2. The data have a hierarchical structure
For example, observational units may belong to different sites, and sites may belong to different regions. The model can be written as:
[
g(\mu{ijk})=
\mathbf{x}{ijk}^\top\boldsymbol{\beta}
+uk+v{jk}
]
Here, (uk) represents a region-level random effect and (v{jk}) represents a site-level random effect within a region.
This type of model can distinguish sources of variation at different levels and avoid attributing all group-level differences to individual explanatory variables.
3. The data have a cross-classified structure
Some data are not simply nested. For example, the same person may rate multiple items, and the same item may be rated by multiple people.
In this case, random effects for both raters and items can be included:
[
g(\mu{ij})=
\mathbf{x}{ij}^\top\boldsymbol{\beta}
+a_i+c_j
]
Including only one grouping factor may miss the dependence induced by the other shared factor.
4. Group differences need partial pooling
When estimating group effects, GLMMs usually shrink groups with less information more strongly toward the overall average, while groups with more information retain more of their own characteristics. This is called partial pooling.
Compared with estimating each group completely independently, partial pooling can reduce extreme fluctuations in small groups. However, it depends on the random-effects distribution and model structure being reasonable, and it should not be interpreted as guaranteed improvement in predictive accuracy in every setting.
6. How to Choose Among Fixed Effects, Random Effects, and Other Approaches
Group fixed effects
If the analysis focuses only on the groups currently observed and aims to control separately for baseline differences across groups, groups can be coded as fixed effects.
This approach does not require a common probability distribution for group intercepts, but the number of parameters increases when there are many groups, and prediction for new groups is not straightforward. Adding group fixed intercepts also does not mean that all within-group correlation has disappeared.
When group characteristics are correlated with explanatory variables, the common independence assumptions of a simple random-effects model may be inappropriate. In that case, group fixed effects can be considered, or within-group and between-group effects can be distinguished by adding group means or related terms.
Generalized estimating equations
If the main interest is the population-average association rather than estimating individual or group random effects, generalized estimating equations (GEE) are a common choice.
GLMMs usually provide effect interpretations conditional on random effects. GEE targets marginal or population-average effects more directly. For nonlinear links, the regression coefficients from the two approaches usually do not have the same interpretation.
Cluster-robust standard errors
If the main concern is correcting standard errors for within-group correlation, cluster-robust standard errors can be used on the basis of a reasonable mean model.
However, this approach does not automatically build a generative model for group heterogeneity, nor does it fix an incorrect mean structure. Its usual large-sample inference also depends on a sufficient number of independent clusters, so it should be used with particular caution when there are few clusters.
Therefore, “needing to handle correlation” and “needing a GLMM” are not fully equivalent judgments.
7. Revisiting Two Examples from the Original Scenario
Example 1: Exponential growth in early case counts
Suppose the expected number of new cases on day (t) satisfies:
[
\mu_t=\gamma e^{\delta t}
]
Taking logs gives:
[
\log\mu_t=\beta_0+\beta_1t
]
where (\beta_0=\log\gamma) and (\beta_1=\delta).
If daily counts are approximately independent given the explanatory variables and the Poisson variance assumption is reasonable, a Poisson GLM can be used. For each one-unit increase in time, the expected number of cases is multiplied by (e^{\beta_1}).
Real daily case data may involve reporting delays, periodic fluctuations, and temporal correlation, however. The independent Poisson assumption should not be accepted merely because the outcome is a count.
If multiple regions are observed simultaneously and regions are believed to have different baselines or growth rates, the following model can be considered:
[
\log\mu{jt}
=
\beta_0+\beta_1t+b{0j}+b_{1j}t
]
This is a count GLMM with region-specific random intercepts and random slopes. Even so, region random effects may not explain all time-series dependence.
Example 2: Capture rate saturating with prey density
Suppose the average capture rate satisfies:
[
\mu(x)=\frac{\alpha x}{h+x},
\qquad \alpha>0,\ h>0
]
where (\alpha) is the maximum average capture rate and (h) is the prey density at which the average capture rate reaches half of its maximum.
For (x>0), this can be rewritten as:
[
\frac{1}{\mu(x)}
=
\frac{1}{\alpha}+\frac{h}{\alpha}\frac{1}{x}
=
\beta_0+\beta_1\frac{1}{x}
]
Therefore, an inverse link with the transformed explanatory variable (1/x) can be considered. If the capture rate is strictly positive and the standard deviation is roughly proportional to the mean, a gamma distribution may be suitable.
However, this rewriting does not automatically ensure that the fitted results have biologically meaningful interpretation. It is necessary to check the signs of the parameters, whether predicted means are positive, and whether the constraints of the saturating curve are satisfied. At (x=0), the inverse transformation cannot be used directly.
If the same predator is repeatedly measured at multiple density levels, individual differences should also be considered. If the research focus is directly on interpreting the maximum capture rate and the half-saturation density, a nonlinear model with parameter constraints or a nonlinear mixed model may be more natural than forcing a linearization.
8. Estimation and Interpretation: Why GLMMs Are More Complex
GLMs are usually fitted by maximum likelihood, commonly using iteratively reweighted least squares. In each iteration, the working response and weights are updated according to the current mean, link function, and variance relationship. It is not completed by a single ordinary least-squares fit.
The GLMM likelihood also requires integrating over the random effects:
[
L(\boldsymbol{\beta},\boldsymbol{\Sigma})
=
\int
p(\mathbf{y}\mid\mathbf{b},\boldsymbol{\beta})
p(\mathbf{b}\mid\boldsymbol{\Sigma})
\,d\mathbf{b}
]
For non-normal responses, this integral usually has no simple closed form and requires numerical approximation or other computational methods. The higher the dimension of the random effects and the sparser the data, the more difficult fitting and diagnostics usually become.
When interpreting coefficients, it is especially important to distinguish conditional effects from marginal effects. For a binomial GLMM:
[
\operatorname{logit}(p{ij})
=
\beta_0+\beta_1x{ij}+b_j
]
(e^{\beta_1}) is the odds ratio when other conditions are held the same and the random effect is given. After integrating out the random effects, the overall average probability usually no longer satisfies the same simple log-odds linear relationship.
When predicting for a new group, the result obtained by setting random effects to zero should not be treated directly as a population-average prediction. For nonlinear links, in general:
[
E_{\mathbf b}!\left[g^{-1}(\eta+\mathbf z^\top\mathbf b)\right]
\ne g^{-1}(\eta)
]
Whether to integrate over the random-effects distribution should be decided according to the prediction target.
9. Practical Model Selection and Diagnostic Workflow
Step 1: Define the observational unit and the objective
First confirm what one row of data represents: a person, a measurement occasion, a day, or an event. Then clarify whether the goal is to estimate a population-average association, a within-group association, or predictions for existing or new groups.
Step 2: Identify dependence structures
List repeated-measurement units, nested levels, cross-classified grouping factors, and temporal order. The absence of a group identifier in the data table does not mean that observations are truly independent.
Step 3: Choose the response distribution and link function
Choose a distribution based on the range and generating mechanism of the outcome. At the same time, examine zeros, exposure, overdispersion, and the mean–variance relationship.
Step 4: Build the necessary random-effects structure
Determine random intercepts or random slopes primarily based on the study design, rather than increasing complexity only through stepwise screening. When there are few groups, insufficient observations per group, or little within-group variation in explanatory variables, complex random effects may be difficult to identify reliably.
Step 5: Check fit quality
Focus on:
- Whether the model converges normally and whether gradient and curvature diagnostics are reasonable;
- Whether random-effect variances are close to zero and whether correlations are close to boundary values;
- Whether conditional residuals still show overdispersion, temporal correlation, or systematic trends;
- Whether binary data show complete or quasi-complete separation;
- Whether extreme groups have excessive influence on coefficients.
A random-effect variance close to zero may indicate that the data support a simpler structure, or it may reflect insufficient information. It should not be mechanically interpreted as “there are completely no group differences.”
Step 6: Validate according to the application goal
If the goal is to predict new groups, training and validation sets should be split by group. If multiple observations from the same subject are randomly divided between the two sets, validation results may be overly optimistic because information is shared across the same individual.
If the goal is to predict the future, temporal order should also be considered, and future information should not be used to evaluate predictions of the past.
Step 7: Compare models cautiously
When comparing models, the response data and likelihood definitions should remain comparable. Testing whether a random-effect variance is zero involves a parameter boundary, so the usual approximation of an ordinary likelihood ratio test may not directly apply.
Model selection should combine the study design, fit diagnostics, interpretation needs, and predictive performance, rather than relying on a single significance result.
10. Final Decision Principles
The choice between GLMs and GLMMs can be summarized in three layers.
The first layer is the response mechanism. Binary, count, and positive continuous outcomes require appropriate distributions and link functions. This determines which class of generalized model to use, but it does not determine whether random effects are needed.
The second layer is the dependence structure. Repeated measurements, hierarchical grouping, and cross-classification suggest that an independent GLM may not be sufficient and that correlation needs to be modeled explicitly or handled in inference.
The third layer is the analysis objective. If the goal is to characterize group heterogeneity, perform partial pooling, or make group-level predictions, GLMMs often have advantages. If the goal is only to estimate a population-average association, more direct alternatives may also be available.
Therefore, the most reliable principle is not “use a GLM for non-normal data and a GLMM whenever grouping exists.” Instead, first clarify how the data are generated, then clarify what question needs to be answered, and finally choose a model that can support the required interpretation, inference, and prediction.
