Why Test a Random Slope?
A random intercept allows clusters to differ in their baseline outcome level. A random slope allows the association between a predictor and the outcome to vary across clusters as well. The question here is whether the slope variation improves the model after retaining the random intercept. This is a test of a variance component, not a test of whether the population-average slope is zero.
The distinction matters because a variance cannot be negative. Under the null hypothesis of no random-slope variation, its value is exactly zero, at the edge of the allowed parameter space. Consequently, the usual likelihood-ratio reference distribution \(\chi^2_1\) does not generally apply. Under a specific, commonly useful covariance assumption, the asymptotic reference distribution is a mixture with half its probability at zero and half following \(\chi^2_1\).
Model and Hypotheses
Suppose cluster \(j\) contributes observations \(i=1,\ldots,n_j\), with a predictor \(x_{ij}\). A random-intercept and random-slope GLMM can be written
Here \(g\) is the link function, \(\beta_0\) and \(\beta_1\) are fixed effects, and \(u_{0j}\) and \(u_{1j}\) are the cluster-specific random intercept and slope. For the simple boundary test developed below, assume
Random effects are independent across clusters. Conditional on the random effects, outcomes are independent and have the specified GLM response distribution. The predictor values and link are the same in both models. The fixed effects are retained unchanged; the models differ only in whether \(\tau_1^2\) is fixed at zero or estimated as nonnegative.
Under \(H_0\), \(u_{1j}=0\) with probability one, so the model still has a random intercept but no cluster-to-cluster slope variation. Under \(H_a\), clusters may have different slopes, with variance \(\tau_1^2\). The null does not say that the fixed slope \(\beta_1\) is zero; it says that the cluster-specific slopes do not vary around that fixed effect through a random-slope term.
The simple mixture result assumes an independent random-intercept/random-slope structure. If the model instead estimates an intercept-slope covariance, the covariance is constrained by positive semidefiniteness and must be zero when \(\tau_1^2=0\). The independent-case reference law should not automatically be carried over to that model; its boundary behavior requires separate treatment.
Likelihood-Ratio Statistic and Boundary Reference Law
Let \(\ell_0\) be the maximized marginal log likelihood under \(H_0\), and \(\ell_1\) the maximized marginal log likelihood under \(H_a\). “Marginal” means the likelihood for the observed outcomes after integrating over the random effects. The likelihood-ratio statistic is
Because the null model is nested in the alternative, fitting is performed so that \(\ell_1\geq \ell_0\), apart from numerical optimization error, and thus \(T\geq0\). For a GLMM, the models should be fit by the same likelihood method, with identical fixed effects and data. Do not compare likelihoods from models that differ in fixed effects when the aim is this random-slope test.
When the null variance is an interior point, a regular one-parameter likelihood-ratio test has an asymptotic \(\chi^2_1\) reference distribution. Here the null value \(\tau_1^2=0\) is a boundary point. In the stated independent-variance setup, with regular nuisance parameters and adequate information as the number of independent clusters grows, the limiting distribution is instead
The notation \(\chi^2_0\) denotes a point mass at zero. For an observed \(T>0\), the boundary-adjusted upper-tail p-value is
where \(\Phi\) is the standard normal cumulative distribution function. The last equality follows because a \(\chi^2_1\) random variable has the distribution of the square of a standard normal variable: \(P(\chi^2_1\geq T)=2\{1-\Phi(\sqrt T)\}\) for \(T>0\).
Why the Mixture Appears
A short local likelihood argument explains the point mass. Consider the variance parameter in a local scale where the log likelihood near the null is approximated by a quadratic. In a regular one-sided problem, the unconstrained local estimate is proportional to a standard normal score \(Z\), where \(Z\sim N(0,1)\). The constraint that the variance cannot be negative restricts the local parameter \(h\) to \(h\geq0\). After scaling the curvature to one, the local log-likelihood difference from its value at zero has the form \(Zh-h^2/2\).
The likelihood-ratio statistic is twice this maximized difference, so its limiting form is \(\max(0,Z)^2\). A standard normal variable is positive with probability \(1/2\), producing a statistic of zero in half the cases; conditional on being positive, its squared value has a \(\chi^2_1\) distribution. This gives the stated mixture. The argument relies on the regular one-sided local setup; it is not a license to apply the mixture when additional covariance parameters become unidentified or constrained at the null.
Worked Tests
Worked Example: A Moderate Likelihood-Ratio Statistic
In hypothetical data from 28 clinics, a binary outcome is modeled with a logit link. A standardized continuous predictor varies within clinics. Both fitted models retain a random clinic intercept and the same fixed intercept and fixed predictor effect. The random intercept and slope are assumed independent. The null model has maximized log likelihood \(\ell_0=-83.640\); the model adding a random slope has \(\ell_1=-83.035\). Test at \(\alpha=0.05\).
Check the setup. The predictor varies within clinics, so a cluster-specific slope is not simply indistinguishable from the intercept. The two models use the same observations and fixed effects, and the random-intercept structure is retained. We use the independent random-effects assumption and the asymptotic boundary reference law.
Calculate the statistic.
Calculate the p-value. Since \(\sqrt{1.210}=1.100\),
The boundary-adjusted p-value exceeds 0.05, so these data do not provide sufficient evidence to reject \(H_0\). This is not proof that the random-slope variance is zero. For comparison, the ordinary \(\chi^2_1\) upper-tail probability is \(2\{1-\Phi(1.100)\}\approx0.2713\), twice the boundary-adjusted value before rounding.
Worked Example: Evidence for Slope Heterogeneity
In a second hypothetical study, a binary outcome is recorded across 40 centers. The predictor is standardized and varies within centers. The models have the same fixed effects and random intercept; the alternative adds an independent normally distributed random slope. The null and alternative log likelihoods are \(-147.20\) and \(-144.32\). The fitted random-slope standard deviation is \(0.42\) log-odds units per one-standard-deviation increase in the predictor.
The assumptions for the simple reference law are stipulated: conditional independence, independent normal random effects across centers, an independent intercept and slope, and adequate cluster information for the asymptotic approximation. The statistic is
Thus \(\sqrt{T}=2.400\), and
At the 0.05 significance level, reject \(H_0\). The likelihood comparison provides evidence that allowing the predictor's slope to vary across centers improves the model, beyond the retained random intercept. The estimated standard deviation describes fitted between-center slope variation on the log-odds scale; it is not itself the test statistic and does not establish a causal effect.
Worked Example: The Alternative Fit Reaches the Boundary
In a third hypothetical analysis, the predictor varies within 16 schools, and both models retain the same random intercept and fixed effects. The fitted alternative has a random-slope variance estimate of zero, and both models have maximized log likelihood \(-51.700\). Assume the independent random-effects specification and otherwise valid fitting.
The likelihood-ratio statistic is
For the mixture distribution, \(P(T\geq0)=1\), because all of its probability mass is at or above zero. The p-value is therefore 1. This result indicates that the fitted alternative did not improve the likelihood; it does not prove that the population random-slope variance is exactly zero. A boundary estimate can also occur because the data provide limited information about slope variation.
Assumptions, Diagnostics, and Alternatives
The asymptotic mixture is a reference approximation, not an automatic correction for every random-effects model. Before using it, check the following:
- Nested comparison: the fixed-effects specification, observations, response distribution, link, and random-intercept term must be the same in both fits; only the random-slope variance is added.
- Informative predictor design: there should be meaningful predictor variation within clusters. If \(x_{ij}\) is constant within each cluster, the data may not distinguish a random slope from a change in the cluster intercept.
- Independent random effects: the half-at-zero, half-\(\chi^2_1\) result here assumes the intercept and slope are independent. An estimated intercept-slope covariance changes the boundary problem, so do not use this reference law automatically.
- Reliable optimization: verify that the alternative likelihood is not below the null likelihood because of convergence failure. Check optimizer convergence, gradient or Hessian warnings, and whether repeated starts give consistent estimates and likelihoods.
- Adequate information: the law is asymptotic in the amount of independent cluster information. With few clusters, sparse outcomes, or weak within-cluster predictor variation, the approximation may be poor.
A Wald test based on an estimated variance divided by its standard error is generally unsuitable at this boundary: normal approximations for the variance estimate need not hold, and the standard error can be unstable. An ordinary \(\chi^2_1\) likelihood-ratio test ignores the boundary and, in this particular one-sided setting, gives twice the upper-tail probability for positive statistics. A test of the fixed slope \(\beta_1\) answers a different question: whether the average slope is zero, not whether slopes vary among clusters.
| Approach | Question or reference | Main caution |
|---|---|---|
| Boundary likelihood-ratio test | Does adding the random-slope variance improve fit? Uses the half-at-zero, half-\(\chi^2_1\) law under the stated assumptions. | Requires the appropriate independent-variance setup and adequate asymptotic information. |
| Ordinary \(\chi^2_1\) likelihood-ratio test | Uses a regular interior-parameter reference law. | Does not account for the variance null being on the boundary. |
| Wald test for the variance | Compares an estimate with zero using a standard error. | Normal approximation is unreliable for a boundary variance component. |
| Fixed-effect test for \(\beta_1\) | Tests the population-average predictor effect. | Does not test whether the slope varies across clusters. |
The test also has substantive limits. A statistically detectable variance does not say which clusters have larger or smaller slopes, and it does not show that the model's random-effects distribution is a good description of the data. Conversely, failure to reject may reflect limited cluster-level information rather than negligible heterogeneity. Interpret the result together with the design, fitted variance, convergence behavior, and the scientific scale of the predictor.
Common Mistake
Check Your Understanding
Use the independent random-intercept/random-slope setup and the asymptotic boundary reference law unless a question says otherwise. Solutions follow the questions.
- State the null and alternative for testing a random-slope variance while retaining a random intercept. Is this a test of the fixed slope?
- For \(T=2.706\), calculate the boundary-adjusted p-value to three significant figures. Use \(\sqrt{2.706}\approx1.645\) and \(\Phi(1.645)\approx0.950\).
- Why is within-cluster variation in the predictor important for identifying a random slope?
- A model estimates an intercept-slope covariance and tests the slope variance at zero. Can the independent-case mixture law be used automatically? Explain briefly.
Solutions. (1) \(H_0:\tau_1^2=0\) versus \(H_a:\tau_1^2>0\), with \(\tau_0^2\) estimated in both models. This is not a test of \(\beta_1=0\); it tests between-cluster slope variability. (2) \(p=1-\Phi(\sqrt{2.706})\approx1-0.950=0.0500\). At a 0.05 level this is at the decision threshold, so report the approximation and use the prespecified decision rule rather than treating rounding as decisive. (3) If a predictor does not vary within clusters, slope changes may be indistinguishable from cluster-specific intercept shifts, leaving little or no information to separate the effects. (4) No. When the slope variance is zero, the covariance is constrained to zero as well, so the independent-case boundary reference result is not automatically justified.