GLMM Fundamentals
This page covers the statistical theory behind the GLMM tab. See that page for usage instructions.
Hierarchical Data and the Independence Problem
Most statistical models assume observations are independent. In practice, data often has a hierarchical structure where observations are grouped:
- Students nested within schools
- Patients nested within hospitals
- Repeated measurements within subjects
Observations in the same group share group-level factors (school policies, hospital resources, individual physiology) and tend to be more similar to each other. Analyzing such data with GLM while ignoring group structure is a model misspecification: the data-generating process has hierarchical structure that the model fails to represent.
This misspecification harms the estimation results in two ways.
Underestimated standard errors: A GLM that ignores group structure computes standard errors under the assumption of zero covariance between observations. Because observations within the same group are actually positively correlated, standard errors are underestimated for the intercept and for coefficients of predictors that vary between groups, so 95% confidence intervals do not actually achieve 95% coverage. The degree of underestimation depends on whether a predictor's variation lies between or within groups (see the design effect in the ICC section).
Biased fixed effects: When group-level confounders exist, the fixed effect estimates suffer omitted variable bias. For example, if school policy influences both study hours and test scores, a regression ignoring school differences cannot correctly estimate the effect of study hours. Random intercepts model mean-level differences between groups, but their estimation assumes that the random intercepts are uncorrelated with the predictors. When unmeasured group-level confounders are correlated with predictors, this assumption fails and the fixed effect estimates remain biased. Measured confounders must be included as fixed effects.
Mixed models resolve the underestimation of standard errors by explicitly modeling within-group correlation as random effects. They also estimate between-group and within-group variability separately, quantifying how much of the variability stems from group differences; the ICC described below summarizes this decomposition.
Fixed Effects and Random Effects
The "mixed" in mixed model refers to containing both fixed and random effects.
Fixed effects are systematic predictor–response relationships assumed to be common to all groups, modeled with unknown constant coefficients. For example, "how many points does test score increase per additional hour of study" is a fixed effect.
Random effects are a modeling device for representing unobserved group-level variability within the model. Each school's average score differs due to policies, student demographics, and other factors. This variability is not generated by a random mechanism — it stems from concrete causes — but measuring and including all those factors as predictors is rarely practical. Random effects approximate this "unobserved group difference" using a probability distribution.
If we write the difference for group as , the assumption is not a claim that school differences are generated from a normal distribution. It is a modeling assumption that enables estimation of the overall magnitude of group variability and produces shrinkage estimates (see below).
The practical difference between the two shows in how parameters are counted. Treating the groups as dummy variables with fixed effects adds one free parameter per group, and each group's effect becomes an estimation target in its own right. With random effects, the only variance component estimated is the single parameter ; each group's is not a free parameter but a predicted value based on that variance. The fixed/random distinction is not about whether groups were "randomly sampled" but about which of these two forms the group differences take (Gelman, 2005).
Random Intercept Model
The simplest mixed model is the random intercept model, which gives each group its own baseline:
where is the link function and is the fixed-effect linear predictor. The subscript denotes the group that observation belongs to, and is that group's random intercept. The statement means that the group-level values each independently follow the same normal distribution.
Intuitively, there is a single regression line shared by all groups (), and each group's line is shifted up or down by . The normal distribution assumption is a tool for summarizing the magnitude of these shifts with a single parameter . The actual value of each is inferred from the data (see Predicting Random Effects and Shrinkage).
For the Gaussian family, this is a linear mixed model (LMM):
is the between-group variance; is the within-group (individual-level) variance. The residual variance is assumed common to all groups: the random intercept model represents group differences in mean level and does not model structures where the magnitude of within-group variability differs by group.
In this equation, the similarity of observations within a group appears as covariance. Two observations in the same group share , so their covariance is ; observations in different groups have covariance 0. Since each observation has variance , the correlation between two observations in the same group is — the quantity measured by the ICC described below.
When the link function is not the identity, the coefficients have a conditional interpretation: they express the effect of moving a predictor within the same group, on the link scale. Because is nonlinear, the effect on the population-averaged response, with the random effects averaged out, generally differs from this whenever . For example, an odds ratio obtained from a Binomial + logit model is read as a within-group comparison, not as a ratio of population-averaged odds.
Parameter Estimation
Estimation in mixed models is more complex than in standard regression because fixed effects and variance components (, ) must be estimated simultaneously.
REML (Restricted Maximum Likelihood)
Maximum likelihood (ML) tends to underestimate variance components because the likelihood does not account for the degrees of freedom consumed by estimating . This is the same phenomenon that makes the sample variance with divisor an underestimate, which the usual divisor corrects.
To avoid this bias, REML estimates the variance components from quantities unaffected by . Viewing the response vector as a point in -dimensional space, the fixed effects can only move within the -dimensional subspace spanned by the columns of the design matrix . Projecting onto the orthogonal complement of that subspace yields residuals whose component vanishes exactly, so their distribution depends only on the variance components, not on . REML maximizes the likelihood of these residuals. Since no degrees of freedom are spent estimating , the variance estimation is effectively based on dimensions of data, which corrects the bias. The sample variance with divisor is the special case where contains only an intercept ().
MIDAS maximizes the REML likelihood by profiling, which reduces the search to one dimension. For each value of the variance ratio , the optimal and under that ratio have closed forms, so the only quantity searched numerically is , maximized by golden-section search.
Laplace Approximation and PIRLS
For the Gaussian family with the identity link, the random-effect integral is analytically tractable, so REML suffices. For all other combinations (Binomial, Poisson, Gamma, and Gaussian + log), integrating out the random effects:
has no closed-form solution. Here is the density of each observation under the chosen distribution family (a probability mass function for discrete families such as Binomial and Poisson), and is the density of the random effects, i.e. the density.
The Laplace approximation replaces this integral with a second-order expansion around the mode of the integrand. The approximation may lose accuracy when group sizes are small or when events are rare in Binomial data.
MIDAS's estimation algorithm follows the nested two-loop structure described in Bates et al. (2015); the choice of optimizer for the outer loop is specific to MIDAS.
- Outer loop: Optimizes the log of the relative covariance parameter via golden-section search
- Inner loop: PIRLS (Penalized IRLS) simultaneously estimates
PIRLS extends GLM's IRLS with a random-effect penalty and minimizes the following penalized deviance:
is the relative covariance parameter optimized by the outer loop; it expresses the standard deviation of the random effects relative to the residual scale: for Gaussian, for Poisson/Binomial, and for Gamma, where is the dispersion parameter. The first term measures fit to data; the second penalizes values that deviate too far from the normal prior. This penalty pulls estimates for data-sparse groups toward the overall mean (see shrinkage below).
Boundary Estimates (Singular Fit)
The estimate of the variance has a lower bound of 0. In either estimation path, a fit whose optimum lands on this bound is called a singular fit. It occurs when the between-group variation in the data is negligible relative to the residual variation.
A boundary estimate changes how the results should be read. is not the conclusion that no group differences exist; it means the data could not distinguish between-group variation from residual variation. Quantities that depend on — the ICC and the predicted random effects — are also nearly 0. Moreover, asymptotic approximations for the variance components assume that the true parameter lies in the interior of the parameter space, and this assumption fails at the boundary. See the GLMM tab page for how this state is detected and handled.
AIC/BIC Limitations
Since the REML projection depends on the fixed-effect structure, REML-based AIC/BIC cannot be compared across models with different fixed effects. Gaussian + identity is the only combination MIDAS estimates via REML, so it is the only one subject to this constraint. All other combinations derive AIC/BIC from a maximum-likelihood quantity (the Laplace-approximated marginal log-likelihood), so models with different fixed effects can be compared.
In either path, however, comparisons are valid only within the same family and link. Changing the family or link mixes factors unrelated to model fit into the AIC/BIC difference: a different estimation path changes the basis of the log-likelihood (REML vs. maximum likelihood), a different family changes what the log-likelihood measures (probability mass for discrete families, density for continuous ones) and how the dispersion parameter is handled, and a different link changes how the Laplace approximation error behaves.
Predicting Random Effects and Shrinkage
The fitted model yields not only the fixed-effect coefficients but also a value of for each group. These values are not computed from each group's data alone. Because is assigned the probability distribution , its value is inferred by combining two sources of information: the data and the assumed distribution. This combination produces the shrinkage described in this section.
This difference from the fixed effects also shows in terminology. The fixed effects are unknown constants, so they are "estimated"; the are treated as random variables within the model, so they are "predicted." This is a formal distinction reflecting the fact that for only the finiteness of the data contributes uncertainty, while for the assumed distribution also acts as an information source — not a claim that was truly generated randomly.
For Gaussian models (LMM), random effects are predicted with the BLUP (Best Linear Unbiased Predictor). The BLUP is the linear predictor that minimizes the mean squared prediction error subject to the constraint that unbiasedness with respect to — — holds for every value of the unknown fixed effects . It derives from the mixed model equations of Henderson (1975) and takes the form of a shrinkage estimator:
where is the group size and is the mean residual for group (the part not explained by fixed effects).
The coefficient ranges from 0 to 1, approaching 1 as group size increases:
- Large groups: Enough data to trust the group-specific estimate, so use it nearly as-is
- Small groups: Limited data, so pull the estimate toward the overall mean (zero)
This is also called "borrowing strength." The phrase comes from Tukey, who used it for this idea of shrinkage in his election-night forecasting work in the 1960s (Brillinger, 2002). Data-sparse groups borrow information from other groups to stabilize their estimates. Using group-specific estimates directly would have high variance; using only the overall mean would ignore group characteristics. BLUP optimally balances this bias-variance tradeoff.
Each predicted value comes with an assessment of its uncertainty. Writing the shrinkage coefficient as , the standard error of is the square root of the variance of conditional on the observed data, , with the estimated variance components treated as the true values. As a group's data becomes sparse, approaches 0, so the prediction shrinks to 0 and the standard error approaches the distribution's standard deviation ; as data accumulates, the standard error tends to 0.
For non-Gaussian families, random effects are estimated as conditional modes instead: the value of that maximizes the density of its distribution conditional on the observed responses. If the assumed distribution is viewed as a prior, this is the mode of the posterior distribution. Conditional modes are obtained as the PIRLS solution and exhibit shrinkage toward the overall mean just like the Gaussian BLUP, but they are not linear predictors, so strictly speaking they are not BLUPs. Their uncertainty is assessed from a normal approximation around the conditional mode.
ICC (Intraclass Correlation Coefficient)
ICC measures the share of unexplained variance — the variance remaining after the fixed effects are accounted for — attributable to between-group differences:
and are the variance components of the fitted model. In a model with fixed effects , both are residual-side quantities after removing the variance explained by the fixed effects.
The ICC is also the correlation between two observations in the same group. As derived in the random intercept model section, that correlation is — the same quantity as this definition. This property is what the name intraclass correlation coefficient refers to.
This form of the ICC is called the conditional ICC, and it is what MIDAS GLMM computes. Its counterpart, the unconditional ICC, is computed from an intercept-only model with no predictors. Because the conditional ICC depends on the fixed-effect specification, adding or removing predictors changes its value, so it generally does not equal the unconditional ICC.
Non-Gaussian Families
For non-Gaussian families, is not directly estimated from data. For the ICC to be a variance decomposition, and must be components that split the variability of the same quantity on the same scale. A satisfying this condition exists only when it can be derived theoretically from the link function and the distributional assumptions.
Binomial models with logit or probit links have a threshold model (Goldstein et al. 2002): an unobserved continuous variable generates the binary response as . The distribution of — and hence its variance — follows deductively from the choice of link function. With the logit link, follows a logistic distribution with variance . With the probit link, follows with variance . In this framework, represents the total variance of the latent variable, and ICC is a genuine variance decomposition.
| Family + Link | Residual Variance | Basis |
|---|---|---|
| Binomial + Logit | Logistic distribution (threshold model) | |
| Binomial + Probit | Standard normal distribution (threshold model) |
The Binomial ICC is a value on the scale of the latent variable . The within-group correlation of the observed binary responses is a different quantity: it is smaller than the latent-scale value because dichotomization discards information, and it also depends on the overall event probability.
ICC is a valid variance decomposition only for Gaussian + identity (where is estimated directly via REML) and the two Binomial combinations above. For other family+link combinations, ICC is not defined:
- Poisson (all links): Poisson distributions have , so the variance is fully determined by the mean and there is no independent residual variance parameter. Some conventions place in the ICC denominator, but is a monotone transformation of , not a variance decomposition.
- Gamma (all links): The profiled dispersion is a conditional variance parameter, not a latent-scale residual variance.
- Gaussian + log: is on the link scale while is estimated on the response scale. There is no theoretical residual variance on the link scale to reconcile the two.
The Design Effect and Choosing Between GLM and Mixed Models
How much a GLM that ignores group structure understates the standard errors can be gauged from the ICC and the group sizes. Observations in the same group resemble each other and carry less information than independent observations, so the variance of a coefficient estimator is larger than it would be with independent data of the same size. This ratio is the design effect (DEFF), expressed as , where is the average group size. The formula is exact when group sizes are equal and approximate when they are unequal. Because standard errors computed under the independence assumption do not include this inflation, the true standard error is roughly times the reported one.
The inflation differs by predictor. For group means and coefficients of predictors that vary at the group level this guide applies as is; for coefficients of predictors that vary within groups the inflation is smaller, and for predictors with little between-group variation it is nearly absent.
This estimate informs the choice between GLM and a mixed model. When the ICC is small and groups are not large, DEFF stays close to 1, and ignoring the group structure with a GLM yields nearly identical results. When DEFF is well above 1, a mixed model is necessary.
Fixed Effect Inference and the Normal Approximation
Fixed-effect confidence intervals are Wald-based, constructed as . is the square root of the -th diagonal entry of , with the estimated variance components plugged into . For Gaussian + identity, is the covariance matrix of the response, where is the indicator matrix of group membership. For all other combinations, is the approximate covariance of the working response built from the PIRLS weights at convergence, further multiplied by for families that estimate a dispersion parameter. This construction relies on approximately following the standard normal distribution.
In ordinary regression (OLS), the error variance is estimated, so follows a t-distribution with degrees of freedom. In mixed models, there are multiple variance components (, ), and the corresponding degrees of freedom are not uniquely determined. The normal approximation treats the estimated variance components as known.
In LMM, the normality assumptions on and ensure that follows the standard normal exactly when the variance components are known. In non-Gaussian GLMM, the normal distribution is an asymptotic approximation. In both cases, replacing the true variance components with estimates introduces additional uncertainty, making the distribution of heavier-tailed than the standard normal.
When the number of groups is large, the variance component estimates are stable and this approximation is adequate. With few groups, confidence intervals tend to be too narrow.
Random Slopes and Crossed Random Effects
MIDAS GLMM supports random intercept models only. Since a random intercept captures group differences in baseline level and nothing more, this section describes the two extensions beyond that scope, as material for judging whether a random intercept model suffices for your data.
When the effect of a predictor also varies by group, a random slope model is needed:
where is the random intercept and is the random slope, jointly following a multivariate normal distribution.
If the slopes do vary between groups and the data is nevertheless fit with a random intercept model, that variation enters the error term. The within-group covariance then actually depends on the predictor values, but the random intercept model replaces it with the constant . This leaves the covariance structure misspecified, so the standard error of that predictor's coefficient becomes unreliable.
When observations belong to multiple grouping variables that are not nested in each other, crossed random effects are used. For example, if students belong to both a school and a region, a random effect for each grouping variable enters the linear predictor:
where and index the school and the region that observation belongs to, and the two random effects are assumed independent of each other.
A random intercept model has only one grouping variable, so with crossed data the variation from the other grouping variable remains in the residuals. That remaining variation produces correlation within the groups of that variable, and ignoring it understates standard errors in the same way described in Hierarchical Data and the Independence Problem.
See also
- The GLMM Tab - How to run GLMM analysis and interpret results
- GLM Fundamentals - GLM theory underlying GLMM
- OLS Fundamentals - Mathematical background of linear models
- Glossary - Statistical term definitions
References
- Gelman, A. (2005). Analysis of variance—why it is more important than ever. The Annals of Statistics, 33(1), 1-53. https://www.jstor.org/stable/3448650
- Bates, D., Mächler, M., Bolker, B., & Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1-48. https://www.jstatsoft.org/v67/i01/
- Henderson, C. R. (1975). Best linear unbiased estimation and prediction under a selection model. Biometrics, 31(2), 423-447. https://www.jstor.org/stable/2529430
- Brillinger, D. R. (2002). John W. Tukey: His life and professional contributions. The Annals of Statistics, 30(6), 1535-1575. https://doi.org/10.1214/aos/1043351246
- Goldstein, H., Browne, W., & Rasbash, J. (2002). Partitioning variation in multilevel models. Understanding Statistics, 1(4), 223-231. https://doi.org/10.1207/S15328031US0104_02
Also available as a Markdown file.