Tutorials › Generalized Linear Mixed Models (GLMM) › Worked Fixed-Effect Model-Comparison Workshop

Testing Fixed and Random Effects · Tutorial 400 of 698

Worked Fixed-Effect Model-Comparison Workshop

Learn to compare nested fixed-effect GLMMs with Wald and likelihood-ratio tests, calculate their statistics, and interpret when their conclusions differ.

Advanced 12 min read

What You'll Learn

  • Specify nested fixed-effect hypotheses while keeping the GLMM’s random-effects structure fixed.
  • Calculate joint Wald statistics from estimates and their covariance matrix.
  • Calculate likelihood-ratio statistics from maximized log likelihoods.
  • Check the assumptions behind chi-square reference distributions for fixed-effect tests.
  • Interpret agreement and disagreement between Wald and likelihood-ratio results.
  • Identify common comparison, calibration, and model-fitting pitfalls.

Why Compare Fixed Effects in a Clustered Model?

In a generalized linear mixed model (GLMM), observations within a cluster may be related because they share random effects. A fixed-effect comparison asks whether specified population-level regression terms improve the model, given its random-effects structure. For example, a researcher might ask whether treatment group and a treatment-by-time interaction are jointly associated with a binary outcome after accounting for clinic-level variation.

Two standard approaches are the Wald test, which assesses the estimated coefficients and their estimated covariance, and the likelihood-ratio test (LRT), which compares maximized likelihoods from nested models. They rely on related large-sample theory, but they use different summaries of the fitted models and can disagree in finite samples.

Definition: Two models are nested when the smaller model can be obtained from the larger model by imposing restrictions on its parameters. In a fixed-effect comparison, the models use the same outcome data, response distribution, link, random-effects structure, and other model specifications; the smaller model excludes one or more fixed-effect terms included in the larger model.

Model Setup and Conditions for Comparison

Let \(Y_{ij}\) denote the outcome for observation \(i\) in cluster \(j\), and let \(b_j\) denote the cluster’s random effects. A GLMM specifies a conditional response distribution from an exponential-family model and a conditional mean model such as

$$ g\{E(Y_{ij}\mid b_j)\}=x_{ij}^{T}\beta+z_{ij}^{T}b_j+\mathrm{offset}_{ij},\qquad b_j\sim N(0,G(\theta)). $$

Here \(g\) is the link function, \(\beta\) is the vector of fixed-effect coefficients, \(x_{ij}\) is the fixed-effect design vector, and \(z_{ij}\) is the random-effect design vector. The model assumes the stated conditional response distribution and link are appropriate, clusters are independent, and the random-effects distribution and covariance structure are adequately specified. Conditional on the random effects, observations are assumed to follow the model’s specified response distribution with its corresponding conditional independence structure.

For a valid standard comparison, the fixed-effect models must be nested and fitted to the same observations. Keep the random-effects structure, response distribution, link, offset, and any weights unchanged. For a GLMM, fit fixed-effect comparisons by maximum likelihood; do not compare restricted maximum-likelihood criteria for models with different fixed-effect design matrices. The likelihood used in the LRT is the likelihood with the random effects integrated out, not a likelihood conditional on estimated random effects.

Under regularity conditions, the usual chi-square reference distributions are large-sample approximations. For a fixed-effect LRT, the null restrictions must be identifiable, the null must not create a boundary problem for nuisance parameters, and the model must be sufficiently regular for the likelihood-ratio asymptotics to apply. In particular, if variance parameters are themselves on a boundary or weakly identified, the ordinary fixed-effect chi-square calibration may not be reliable. The earlier material on parametric bootstrap for fixed-effect likelihood-ratio tests addresses calibration when the usual approximation is questionable.

The Two Tests

Suppose the larger model has fixed-effect vector \(\beta\), and the null hypothesis imposes \(q\) independent linear restrictions \(R\beta=r\). The reduced model is the larger model subject to those restrictions. Write \(\hat\beta\) for the maximum-likelihood estimate and \(\widehat{\mathrm{Var}}(\hat\beta)\) for its estimated covariance matrix.

Definition: The Wald statistic for \(R\beta=r\) is
$$ W=(R\hat\beta-r)^T\left\{R\widehat{\mathrm{Var}}(\hat\beta)R^T\right\}^{-1}(R\hat\beta-r). $$

If the restrictions are regular and the covariance estimate is valid, \(W\) is approximately distributed as \(\chi^2_q\) under \(H_0\). For one coefficient, this reduces to the squared Wald \(z\)-statistic: \(W=(\hat\beta_k/\mathrm{SE}(\hat\beta_k))^2\) when \(H_0:\beta_k=0\).

Definition: Let \(\ell_{\mathrm{full}}\) and \(\ell_{\mathrm{reduced}}\) be the maximized log likelihoods for the larger and smaller models, respectively. The likelihood-ratio statistic is
$$ D=2\left(\ell_{\mathrm{full}}-\ell_{\mathrm{reduced}}\right). $$

Because the larger model contains the reduced model, its maximized likelihood cannot be lower, apart from numerical fitting error. Under the same regularity conditions, \(D\) is approximately distributed as \(\chi^2_q\), where \(q\) is the number of independent restrictions (equivalently, the difference in the models’ fixed-effect parameter dimensions).

Why the Reference Distributions Arise

The Wald result follows from the large-sample approximation \(\hat\beta\approx N(\beta,\widehat{\mathrm{Var}}(\hat\beta))\). Under \(H_0:R\beta=r\), the standardized restriction vector \(R\hat\beta-r\) is approximately multivariate normal with mean zero and covariance \(R\widehat{\mathrm{Var}}(\hat\beta)R^T\). Whiten that vector by the inverse square root of its covariance matrix. The resulting \(q\)-vector is approximately standard normal, so the sum of its \(q\) squared components has a \(\chi^2_q\) distribution. That sum is exactly the Wald quadratic form above.

For the LRT, the log likelihood near its maximum is approximately quadratic in the parameters under regularity conditions. The reduction in fit from imposing \(q\) restrictions is then approximately the sum of \(q\) squared standard-normal components. Twice the log-likelihood difference therefore has an approximate \(\chi^2_q\) distribution under the null. This argument depends on regularity; boundary or weak-identification cases require care rather than automatic use of the ordinary chi-square reference.

Worked Example: A Joint Test with Different Conclusions

Consider hypothetical binary outcomes from 24 clinics. Fit two nested logistic random-intercept GLMMs to the same patients, with the same clinic random-intercept structure and all other terms held fixed. The larger model adds treatment and treatment-by-time coefficients, denoted \(\beta_1\) and \(\beta_2\). Test \(H_0:\beta_1=\beta_2=0\) at \(\alpha=0.05\). Suppose the full-model estimates are \(\hat\beta=(0.40,-0.30)^T\), and the inverse estimated covariance matrix for these two estimates is

$$ \left\{\widehat{\mathrm{Var}}(\hat\beta)\right\}^{-1} = \begin{pmatrix} 26.0417 & -3.4722\\ -3.4722 & 11.5741 \end{pmatrix}. $$

For the joint Wald test, \(R\) is the \(2\times2\) identity matrix and \(r=(0,0)^T\). Thus the displayed inverse covariance matrix can be used directly:

$$ \begin{aligned} W &= \begin{pmatrix}0.40&-0.30\end{pmatrix} \begin{pmatrix}26.0417&-3.4722\\-3.4722&11.5741\end{pmatrix} \begin{pmatrix}0.40\\-0.30\end{pmatrix}\\ &= \begin{pmatrix}0.40&-0.30\end{pmatrix} \begin{pmatrix}11.4583\\-4.8611\end{pmatrix}\\ &=0.40(11.4583)+(-0.30)(-4.8611)=6.0417. \end{aligned} $$

There are \(q=2\) restrictions. For a \(\chi^2_2\) variable, the upper-tail probability at 6.0417 is approximately \(e^{-6.0417/2}=0.04876\). The joint Wald test therefore rejects \(H_0\) at the 0.05 level.

Suppose the reduced-model log likelihood is \(-214.80\) and the full-model log likelihood is \(-213.25\). Then

$$ D=2\{-213.25-(-214.80)\}=2(1.55)=3.10. $$

With two restrictions, the LRT p-value is \(P(\chi^2_2\ge3.10)=e^{-3.10/2}\approx0.2122\). The LRT does not reject at 0.05. These hypothetical results show a genuine disagreement in the decisions: the joint Wald test rejects, whereas the LRT does not. Neither result should be silently substituted for the other; report the test, reference distribution, and p-value used.

Worked Example: A Single Added Treatment Coefficient

Suppose a hypothetical study has binary outcomes for 480 patients in 24 clinics. Both fitted models include the same clinic random intercept and the same baseline covariates; the larger model adds a treatment indicator. Assume the estimated treatment coefficient is \(0.55\) with standard error \(0.25\). Test \(H_0:\beta_{\mathrm{treatment}}=0\) against a two-sided alternative.

The Wald statistic is \(z=0.55/0.25=2.20\), or equivalently \(W=2.20^2=4.84\). Its one-degree-of-freedom chi-square p-value is approximately \(0.0278\), so the Wald test rejects at \(\alpha=0.05\). On the conditional odds scale, the estimated odds ratio is \(\exp(0.55)=1.733\): holding the included covariates and clinic random effect fixed, the fitted odds for the treatment group are about 1.73 times those for the reference group.

Suppose the reduced-model log likelihood is \(-182.60\) and the full-model log likelihood is \(-180.50\). The likelihood-ratio statistic is \(D=2\{-180.50-(-182.60)\}=4.20\). With one restriction, \(P(\chi^2_1\ge4.20)\approx0.0404\). The LRT also rejects at 0.05. The two methods agree on the decision, although their p-values differ because they use different fitted-model summaries.

Worked Example: A Joint Test for a Three-Level Predictor

In hypothetical data on 300 patients from 15 clinics, suppose a three-level exposure is represented by two indicator coefficients relative to a reference category. The smaller model excludes both indicators; the larger model includes both, while retaining the same random-intercept structure and other terms. Assume the fitted coefficient vector is \((0.30,0.20)^T\) and its estimated covariance matrix is diagonal with variances \(0.04\) and \(0.04\). Test whether both exposure coefficients are zero.

The inverse covariance matrix is diagonal with entries \(1/0.04=25\). Therefore the joint Wald statistic is

$$ W= \begin{pmatrix}0.30&0.20\end{pmatrix} \begin{pmatrix}25&0\\0&25\end{pmatrix} \begin{pmatrix}0.30\\0.20\end{pmatrix} =25(0.30^2)+25(0.20^2)=2.25+1.00=3.25. $$

For \(q=2\), the p-value is \(P(\chi^2_2\ge3.25)=e^{-3.25/2}\approx0.1969\), so the Wald test does not reject at 0.05. If the reduced and full log likelihoods are \(-121.40\) and \(-119.90\), respectively, then \(D=2\{-119.90-(-121.40)\}=3.00\). Its \(\chi^2_2\) p-value is \(e^{-1.50}\approx0.2231\). The LRT also does not reject. In these hypothetical results, neither test provides strong evidence against the joint null that the two exposure coefficients are zero.

Interpreting Agreement, Disagreement, and Diagnostics

Wald and likelihood-ratio tests often give similar conclusions when the sample is informative, the likelihood is well behaved, and the null is not close to a problematic boundary. But agreement is not guaranteed. The Wald test uses the fitted coefficient vector and a local covariance approximation at the full-model estimate. The LRT compares the optimized fit under the null with the optimized fit in the larger model. If the likelihood is asymmetric, the estimates are imprecise, the sample is limited, or the model is weakly identified, these summaries can differ appreciably.

Before interpreting either test, check that the models used the same observations and the same non-tested specifications. Confirm that the larger model truly contains the smaller model, that the log likelihoods are maximized on the same likelihood scale, and that the fixed-effect restriction count matches the degrees of freedom used. Convergence warnings, an ill-conditioned fixed-effect covariance matrix, very large standard errors, or estimates that change substantially under modest model refitting are reasons to investigate rather than to rely mechanically on a p-value. If the random-effects variance estimates indicate boundary behavior, ordinary chi-square calibration may need alternatives such as the parametric bootstrap.

A fixed-effect test does not decide whether the random-effects structure is appropriate; that is a different hypothesis and can have different reference-distribution issues. Nor does a nonsignificant result establish that the tested effects are exactly zero. The conclusion is limited to the evidence against the specified null under the fitted model and its assumptions. For a coefficient test, describe its scale and units; for example, a logistic coefficient is a change in conditional log odds per unit of its predictor, not a change in probability.

Common Pitfalls

  • Comparing models that differ in more than the tested fixed effects. A change in random effects, observations, offsets, or response specification confounds the comparison. Keep these features fixed.
  • Using the wrong degrees of freedom. Use the number of independent restrictions, not the number of observations or clusters. A two-coefficient joint null generally has \(q=2\).
  • Calling the Wald test and LRT interchangeable. They are distinct procedures. Report the statistic and p-value for the method actually used, especially when results disagree.
  • Using a REML comparison for different fixed-effect designs. Fit the fixed-effect comparison by maximum likelihood.
  • Treating failure to reject as proof of no effect. A large p-value means the data do not provide sufficient evidence against the specified null at the chosen level; it does not prove the null true.
Key takeaway: A fixed-effect comparison in a GLMM requires nested models fitted to the same data with the same random-effects and response specifications. The Wald test uses coefficient estimates and their covariance; the LRT uses the difference in maximized log likelihoods. Check assumptions and diagnostics, and state clearly when the two tests disagree.

Check Your Understanding

Answer each question, then compare with the worked solutions below.

  1. A nested comparison removes three independent fixed-effect restrictions. What degrees of freedom are used for the usual Wald and LRT reference distributions?
  2. A full model has log likelihood \(-90.20\), and its nested reduced model has log likelihood \(-92.00\). Calculate the LRT statistic.
  3. A coefficient estimate is \(0.48\) with standard error \(0.20\). Calculate the one-degree-of-freedom Wald statistic.
  4. Why should a fixed-effect comparison keep the random-effects structure and analysis observations unchanged?
  5. A joint Wald test rejects at 0.05 but the corresponding LRT does not. Is it valid to report only the result that supports the preferred conclusion?

Solutions. (1) Use \(df=q=3\), because there are three independent restrictions. (2) \(D=2\{-90.20-(-92.00)\}=2(1.80)=3.60\). (3) \(W=(0.48/0.20)^2=2.40^2=5.76\). (4) Changing the random-effects structure or analysis sample changes more than the tested fixed effects, so the comparison no longer isolates the stated null. (5) No. Report both procedures and their p-values if both were conducted, explain the disagreement, and assess the assumptions and diagnostics rather than selecting a result based on the desired conclusion.

Clinical Biostats