Tutorials › Regression Analysis (Undergraduate) › Diagnosing Dependence in Regression Residuals

Grouped Data and Dependence Awareness · Tutorial 887 of 991

Diagnosing Dependence in Regression Residuals

Use residual plots and cluster summaries to spot patterns consistent with dependence, while recognizing what those patterns can and cannot establish.

Advanced 10 min read

What You'll Learn

  • Define regression residuals and explain how they serve as imperfect indicators of model errors.
  • Construct cluster-labeled residual plots that preserve meaningful observation order.
  • Calculate and interpret cluster means and within-cluster residual summaries.
  • Recognize shared offsets, runs, and differences in spread within clusters.
  • Distinguish descriptive evidence of dependence from a formal test or proof.
  • Identify how model specification and fitted cluster effects can affect residual diagnostics.

Why Look at Residuals by Cluster?

When observations belong to groups such as schools, clinics, or people measured repeatedly, a regression model may leave related observations with similar errors. A cluster-labeled residual plot can reveal patterns that an ordinary plot, with all observations shown as indistinguishable points, may conceal. Such patterns matter because regression inference can be affected when observations within a cluster are dependent.

A residual is the observed response minus its fitted value. It is available after fitting a regression model, whereas the model error that generated an observation is not directly observed. Residuals can therefore help us look for dependence, but they are only an imperfect reflection of the unobserved errors. A plot can suggest a concern; it cannot establish that dependence is present or replace an inferential procedure.

Definition: For observation \(j\) in cluster \(g\), the residual is \(e_{gj}=y_{gj}-\hat{y}_{gj}\), where \(y_{gj}\) is the observed response and \(\hat{y}_{gj}\) is its fitted value from the regression model. The cluster mean residual is \(\bar{e}_g=\frac{1}{n_g}\sum_{j=1}^{n_g}e_{gj}\), where \(n_g\) is the number of observations in cluster \(g\).

The regression model supplies the reference for interpreting residuals. In the usual setup, the fitted values represent the response means specified by the model, conditional on its included predictors. If errors from different clusters are treated as independent, that is an assumption about the model errors, not a guarantee that residuals in a plot will look unrelated. Within a cluster, dependence means that knowing something about one observation’s error gives information about another observation’s error in the same cluster.

Making a Cluster-Labeled Residual Plot

Begin with a fitted model and calculate each residual. Plot residuals against fitted values or against a variable relevant to the model, and use color or labels to identify clusters. Include a horizontal reference line at zero. If observations have a meaningful order within each cluster, such as measurement time, a separate connected trace for each cluster can help show runs or changes over time. Do not connect observations in an arbitrary order: a line between unrelated points can suggest a pattern that is not in the data.

Look for recurring features rather than expecting every cluster to look alike. Several residuals in the same cluster may lie on the same side of zero, or adjacent residuals in a sequence may repeatedly have the same sign. Clusters may also show different spreads. A difference in spread is worth investigating, but by itself it is not proof of dependence: it could reflect unequal variability, an omitted predictor, or another feature of the data or model.

1
Fit the model and calculate residuals.
Use the same response, predictors, and fitted values that define the analysis being assessed.
2
Show cluster membership.
Use distinct colors, symbols, or panels so that observations from the same cluster can be recognized.
3
Preserve meaningful order.
If observations are repeated over time or another ordered scale, show that order within each cluster; otherwise, avoid implying an order.
4
Summarize, then qualify.
Check cluster means and within-cluster patterns, and describe them as evidence to consider rather than as a test result.

Within-Cluster Summaries

A cluster mean residual summarizes whether the fitted model tends to underpredict or overpredict within that cluster. A positive mean means observed responses average above their fitted values in that cluster; a negative mean means they average below. The magnitude should be interpreted in the response’s units. Means close to zero do not rule out dependence: positive and negative residuals can cancel even when nearby residuals or repeated measurements show a pattern.

A useful way to separate the cluster’s overall residual level from its internal pattern is to subtract the cluster mean from each residual. The resulting deviations show how observations vary around their cluster’s average residual.

$$ e_{gj}=\bar{e}_g+(e_{gj}-\bar{e}_g), \qquad \sum_{j=1}^{n_g}(e_{gj}-\bar{e}_g)=0. $$

The first term is the cluster-level offset; the second is the within-cluster deviation. This is an accounting identity, not a statistical test. It helps clarify which kind of pattern is being described. A nonzero cluster mean is a shared offset in the residuals, while a run or repeated sequence of similar deviations can remain even when the mean is zero.

Worked Example: Comparing Cluster Mean Residuals

Suppose a hypothetical regression predicts a clinic’s daily response, measured in points, from recorded patient characteristics. The residuals for three clinics are as follows. The clinics are the clusters, and the values are listed in an arbitrary order because these observations have no meaningful sequence.

Clinic A: \(0.8,\ 1.0,\ 0.6,\ 0.9\). Its mean residual is \( (0.8+1.0+0.6+0.9)/4=3.3/4=0.825 \) points.

Clinic B: \(-0.7,\ -0.9,\ -0.6,\ -0.8\). Its mean residual is \( (-0.7-0.9-0.6-0.8)/4=-3.0/4=-0.750 \) points.

Clinic C: \(0.3,\ -0.2,\ 0.1,\ -0.2\). Its mean residual is \( (0.3-0.2+0.1-0.2)/4=0.0/4=0.000 \) points.

A cluster-labeled plot would show all four Clinic A residuals above zero and all four Clinic B residuals below zero. Their within-cluster means differ by \(0.825-(-0.750)=1.575\) points. This is a descriptive pattern consistent with cluster-specific offsets. It does not establish why the offsets occur or prove that the underlying errors are dependent: differences in model fit or unaccounted-for cluster characteristics could also contribute. Clinic C’s mean is zero, but its residuals still vary within the clinic.

Checking Patterns Within Ordered Clusters

For observations with a meaningful order, a cluster mean alone can miss a sequence pattern. A quick descriptive summary is to inspect consecutive residuals: neighboring values that repeatedly have the same sign, or similar magnitudes, may indicate a pattern worth investigating. Their products provide a compact way to describe whether a neighboring pair has the same or opposite signs. A positive product means both residuals have the same sign; a negative product means their signs differ. This description is not a formal test, and it should not be treated as one.

Worked Example: Residual Runs Within Repeated Measurements

In a hypothetical study, a response is measured three times for each person. Time order is meaningful, and the fitted model gives these residuals in response units:

Person A: \(1.2,\ 0.8,\ 0.6\). The mean is \( (1.2+0.8+0.6)/3=2.6/3=0.867 \). The products for consecutive pairs are \(1.2(0.8)=0.96\) and \(0.8(0.6)=0.48\). Both pairs are positive, so all three residuals are above zero and consecutive values have the same sign.

Person B: \(-1.0,\ -0.6,\ -0.9\). The mean is \( (-1.0-0.6-0.9)/3=-2.5/3=-0.833 \). The consecutive products are \((-1.0)(-0.6)=0.60\) and \((-0.6)(-0.9)=0.54\). Both are positive; again, the three residuals share a sign.

Person C: \(0.7,\ -0.8,\ 0.1\). The mean is \( (0.7-0.8+0.1)/3=0.0/3=0.000 \). The consecutive products are \(0.7(-0.8)=-0.56\) and \((-0.8)(0.1)=-0.08\). Both are negative, reflecting sign changes between consecutive residuals.

A plot against measurement time would make these contrasts visible: Persons A and B have runs on one side of zero, while Person C changes sign. These patterns are reasons to examine the dependence assumptions and model context more carefully, not numerical evidence that by themselves settles whether dependence exists.

Why Residual Diagnostics Are Not a Test

Residuals are calculated after the model has been fitted, so they are not the same as the unobserved model errors. Fitting uses the data to choose coefficients, which can impose relationships among residuals even when the underlying errors do not have those same relationships. The predictors also matter: omitted or misspecified mean structure can produce systematic residual patterns that resemble shared cluster behavior. For example, if a predictor varies across clusters and is left out, clusters with different predictor values may have residuals that tend to share a sign.

There is a particularly important caution when a model includes a separate indicator for each cluster. In ordinary least squares with an intercept and all cluster indicators represented appropriately, the residuals within each fitted cluster sum to zero. Thus, a zero cluster mean may be a consequence of fitting the model, not evidence that within-cluster dependence is absent. Residual sequences or other within-cluster patterns may still be visible.

Worked Example: Zero Cluster Means Do Not Rule Out a Pattern

Suppose a hypothetical regression includes a separate cluster intercept for each group. In one cluster, the four residuals in time order are \(1.0,\ 0.7,\ -0.8,\ -0.9\). Their sum is \(1.0+0.7-0.8-0.9=0.0\), so their mean is \(0.0/4=0.000\) response units.

Despite that zero mean, the first two residuals are both positive and the last two are both negative. The products for consecutive pairs are \(1.0(0.7)=0.70\), \(0.7(-0.8)=-0.56\), and \((-0.8)(-0.9)=0.72\). Two of the three consecutive pairs have the same sign, while the middle pair changes sign. The zero mean summarizes balance around zero; it does not describe away the ordered pattern.

The mean of zero is consistent with the cluster intercept’s role in the fitted model, and the signs describe the residual sequence. Neither calculation proves dependence. The diagnostic question is whether patterns like this are meaningful given the design, ordering, predictors, and fitting procedure.

From a Pattern to a Careful Conclusion

A useful diagnostic report states exactly what the plot or summaries show and then distinguishes that observation from its possible explanations. For example: “Residuals for several observations from the same clinic tend to fall above zero, suggesting a shared cluster pattern. This is descriptive evidence to consider when assessing the independence assumption; it is not a formal test of dependence.” This wording reports the visible feature without overclaiming.

Cluster-labeled diagnostics complement, rather than replace, knowledge of how the data were collected and the assumptions used for inference. A plot may look unremarkable even when errors are dependent, particularly with few clusters or noisy residuals. Conversely, visible structure may come from omitted predictors, an incorrect mean relationship, or differences in variability rather than dependence itself. The design and the regression specification remain essential context.

Common Mistakes

  • Calling a visual pattern proof. Similar residual signs within clusters are descriptive evidence, not a formal test or proof of dependence.
  • Treating a zero cluster mean as a clean bill of health. Positive and negative residuals can average to zero while an ordered sequence or other within-cluster pattern remains.
  • Connecting points without a meaningful order. A line can imply a sequence that the data do not have. Connect residuals only when the order has a substantive meaning.
  • Attributing every cluster difference to dependence. Omitted predictors, model misspecification, or differing variability can also produce cluster-specific residual patterns.
  • Confusing residuals with errors. Residuals are fitted quantities used as imperfect clues about unobserved errors; they are not the errors themselves.
Key takeaway: Plot residuals with cluster membership visible, summarize cluster offsets, and inspect within-cluster patterns when order matters. Describe what the data show, but do not present a residual plot or summary as a formal test or proof of dependence.

Check Your Understanding

Answer in context, distinguishing visible patterns from conclusions about the underlying errors.

  1. A cluster has residuals \(0.4,\ 0.5,\ 0.3\). Calculate its mean residual and state what the sign indicates about observed versus fitted responses in that cluster.
  2. Why might a cluster have a mean residual of zero even when its residuals show a pattern over time?
  3. In a residual plot, what is gained by coloring observations by cluster? When is it appropriate to connect residuals in time order?
  4. Give one explanation other than dependence that could produce similar residual signs within a cluster.
  5. Why should a visible cluster pattern be described as descriptive evidence rather than as proof of dependence?