Tutorials › Introduction to Statistics › Checking Residual Dependence by Data Order

Residuals and Transformations · Tutorial 279 of 996

Checking Residual Dependence by Data Order

Learn to use residuals in their original data order to look for patterns that can make the independence assumption questionable.

Intermediate 9 min read

What You'll Learn

  • Define error independence in an ordered regression setting.
  • Calculate residuals and arrange them in the meaningful observation order.
  • Recognize runs, trends, and cycles in an ordered residual plot.
  • Distinguish possible dependence from curvature or changing spread.
  • Explain why a visible pattern is a warning, not proof, of dependence.
  • Identify when data order is meaningful and when rearranging it can mislead.

Why the Order of Observations Can Matter

Residual plots are often examined against fitted values or predictor values, but the order in which observations were collected can also carry information. Measurements made day after day, patients recruited one after another, or parts produced consecutively may share conditions that change gradually or repeat. If nearby observations tend to have related errors, a model that describes the average relationship may still miss a feature of how the data were generated.

An ordered residual plot places each residual at its observation number or collection time, preserving the original sequence. Random-looking variation around zero is consistent with independent errors. Long runs on one side of zero, a gradual rise or fall, or a repeating cycle are possible signs that successive errors are related. Such patterns are reasons to investigate the model and data collection process, not proof by themselves that dependence exists.

Definition: In a regression model, errors are independent when the error for one observation does not provide information about the error for another. Residual dependence is a pattern in the fitted residuals across observation order that suggests this independence assumption may be questionable. A residual is \(e_i=y_i-\hat{y}_i\), the observed response minus the response predicted by the fitted model.

Model and Diagnostic

For a simple linear regression, write the response for observation \(i\) as

$$ Y_i=\beta_0+\beta_1x_i+\varepsilon_i $$

Here \(\beta_0+\beta_1x_i\) is the model's mean response at predictor value \(x_i\), and \(\varepsilon_i\) is the error: the deviation of the response from that mean. For the usual regression model, errors have mean zero, a common variance \(\sigma^2\), and are independent across observations. The independence condition concerns the errors, which are not directly observed. Residuals \(e_i=y_i-\hat{y}_i\) are estimates of those errors, calculated after fitting the regression line.

To check for possible dependence, plot \(e_i\) vertically against the actual collection time or observation sequence number horizontally. Keep the sequence as it was recorded. A substantive order is important: if the rows were sorted by response or rearranged arbitrarily, the resulting plot would not diagnose the original process. When the order has no meaningful interpretation, a pattern in an arbitrary row order generally has no such diagnostic meaning.

Look for departures from an unstructured scatter centered near zero. A run is a sequence of consecutive residuals on the same side of zero. A trend is a sustained upward or downward movement. A cycle is a recurring rise-and-fall pattern. These visual clues may reflect neighboring errors being positively related, an omitted time-related change, a repeated process, or another feature that the fitted model does not capture.

This check asks a different question from residuals versus fitted values or predictor values. A curved pattern against a predictor can indicate that a straight-line mean relationship is inadequate; a fan shape can indicate unequal spread. An ordered pattern instead raises a question about how errors relate from one observation to the next. More than one issue can occur at the same time.

Worked Example: A Sustained Trend in Daily Residuals

Suppose a hypothetical laboratory records a response each day and uses a fitted regression model to predict it. The response and predictions are measured in units. The following eight observations are listed in collection order.

DayObserved \(y_i\)Predicted \(\hat{y}_i\)Residual \(e_i=y_i-\hat{y}_i\)
121.220.01.2
220.820.00.8
320.620.00.6
420.220.00.2
519.720.0-0.3
619.320.0-0.7
719.020.0-1.0
818.920.0-1.1

For Day 1, \(e_1=21.2-20.0=1.2\) units. For Day 8, \(e_8=18.9-20.0=-1.1\) units; the other residuals are calculated the same way. Plotted in day order, the residuals begin above zero, decline across the sequence, and end below zero. This sustained downward trend is not the pattern expected from errors that vary independently around zero.

The plot does not establish why the trend occurred. For example, a gradual change in measurement conditions could be relevant, or the model could omit a change over time. The appropriate conclusion is that the sequence raises concern about independent errors and warrants checking the process and model, not that one particular cause has been proved.

Recognizing Runs and Cycles

A long run can be informative even if residuals do not move steadily. If many consecutive values are positive, the model has repeatedly underpredicted the response; if they are negative, it has repeatedly overpredicted. A cycle differs from a one-way trend because residuals repeatedly move above and below zero. Either kind of structure can arise when consecutive errors share influences that are absent from the model.

Worked Example: A Repeating Cycle

A hypothetical production line records the measured response and fitted prediction for eight consecutive items. Both are measured in millimetres.

Item orderObserved \(y_i\)Predicted \(\hat{y}_i\)Residual \(e_i\)
110.410.00.4
29.610.0-0.4
310.510.00.5
49.510.0-0.5
510.310.00.3
69.710.0-0.3
710.410.00.4
89.610.0-0.4

For Item 2, \(e_2=9.6-10.0=-0.4\) mm; for Item 3, \(e_3=10.5-10.0=0.5\) mm. Across the ordered observations, the signs alternate and the magnitudes remain near 0.4 mm. This repeated pattern is a cycle-like structure, rather than a sustained run on one side of zero. It suggests that the process may have a recurring influence, but eight observations alone do not identify its source or establish a cycle beyond this sequence.

Not every uneven-looking sequence is persuasive evidence of dependence. Short runs and isolated reversals can occur by chance. Interpretation should consider the length and strength of the pattern, the number of observations, and what is known about how data were collected. A plot is a diagnostic tool for spotting structure; it is not a formal test with a stated probability of false alarm.

Worked Example: Residuals Without a Clear Order Pattern

A hypothetical clinic records the waiting-time residuals, in minutes, for six appointments in the order they occurred: \(0.3,-0.4,0.2,-0.2,0.4,-0.3\). Each residual is observed waiting time minus the model's predicted waiting time. For the first appointment, an observed wait of 18.3 minutes and a predicted wait of 18.0 minutes give \(e_1=18.3-18.0=0.3\) minutes.

The sequence changes sides of zero several times, and no sustained upward, downward, or repeating pattern is apparent. This small plot offers no clear visual warning of dependence. It does not prove independence: subtle dependence may be hard to see in a short sequence, and the residuals are only estimates of the unobserved errors. The conclusion should therefore be limited to what the plot shows.

Why Dependence Matters

Dependence matters because the amount of variation in a collection of errors depends not only on the variation of each error, but also on how errors co-vary. Let \(S\) be the sum of four errors. The variance of a sum is the sum of the individual variances plus twice each distinct pairwise covariance:

$$ \operatorname{Var}(S) = \sum_{i=1}^{4}\operatorname{Var}(\varepsilon_i) + 2\sum_{i<j}\operatorname{Cov}(\varepsilon_i,\varepsilon_j) $$

If the four errors are independent and each has variance \(\sigma^2\), all pairwise covariances are zero, so \(\operatorname{Var}(S)=4\sigma^2\). If only neighboring pairs have a common positive covariance \(c\), there are three such pairs, giving

$$ \operatorname{Var}(S)=4\sigma^2+2(3c)=4\sigma^2+6c $$

The variance is then larger than \(4\sigma^2\) when \(c>0\). This derivation shows why treating related errors as independent can misrepresent uncertainty: the independence-based calculation leaves out the covariance terms. An ordered residual pattern is a practical warning that those terms may matter, not a calculation of them.

The order must be interpreted in context. If observations are days, inspect calendar time; if they are production items, inspect production sequence. A visible trend might point to a shift in conditions, while a cycle might correspond to a repeating operating schedule. These are possibilities to investigate, not conclusions that can be read off the plot alone. Rearranging the observations before plotting can hide the pattern; sorting by residual size can create an apparent order pattern that was never present.

Common Mistakes

  • Calling a pattern proof of dependence. A trend or cycle is evidence that the independence assumption may be questionable, not proof of a specific cause. Describe the pattern and consider how the data were collected.
  • Assuming a messy scatter proves independence. A plot with no obvious structure does not guarantee that errors are independent, particularly with few observations. State that no clear pattern was seen.
  • Plotting in an arbitrary or changed order. Row order is useful only if it preserves a meaningful sequence. Use collection time or the original observation order, and do not sort the residuals first.
  • Confusing dependence with changing spread or curvature. An ordered pattern concerns the relationship among errors across observations. Check the shape and spread of residuals in their appropriate plots as separate questions.
  • Interpreting residuals as the true errors. Residuals are calculated from a fitted model. They help reveal possible structure in the errors, but they are not the unobserved errors themselves.
Key takeaway: Plot residuals against meaningful observation order and look for runs, trends, and cycles. Treat visible structure as a warning to investigate possible dependence or omitted process changes; treat a featureless plot as limited evidence, not a guarantee of independence.

Check Your Understanding

Use the ideas in this tutorial to answer the following questions.

  1. In a plot of residuals against collection day, what does a long run of positive residuals suggest about the model's predictions over that period?
  2. How does a repeating up-and-down residual pattern differ from a sustained trend?
  3. Why should observations not be rearranged before making an ordered residual plot?
  4. A short ordered plot shows no obvious pattern. What can you reasonably conclude, and what can you not conclude?
  5. In one sentence, distinguish residual dependence from unequal residual spread.