Tutorials › Introduction to Statistics › ANOVA Residuals Versus Raw Data for Diagnostics

Multiple Comparisons and ANOVA Assumptions · Tutorial 882 of 996

ANOVA Residuals Versus Raw Data for Diagnostics

Distinguish the observations ANOVA models from the residuals used to examine how well its assumptions fit the data.

Intermediate 9 min read

What You'll Learn

  • Write the one-way ANOVA model and identify its fitted values.
  • Calculate a residual as an observation minus its group mean.
  • Explain why residuals sum to zero within each group.
  • Distinguish genuine group-mean differences from patterns in residuals.
  • Choose raw-data displays for description and residual displays for model diagnostics.
  • Recognize what residual plots can suggest and what they cannot establish.

Why the Choice of Data Matters

In one-way ANOVA, observations from different groups may have different means. A plot of all the raw observations therefore combines two features: variation among group means and variation of observations around their own group means. Those features answer different questions. Group means describe how the groups differ; residuals show how far individual observations lie from the means predicted by the model.

This distinction matters when checking whether an ANOVA model is a reasonable description of the data. A large gap between two groups can be a real feature of the fitted model, not evidence that the residuals have a pattern. Conversely, raw observations can make it difficult to see a pattern in the variation around the fitted group means. A diagnostic display should match the part of the model being examined.

The One-Way ANOVA Model and Its Residuals

Suppose there are \(k\) groups, with \(n_j\) observations in group \(j\). Write observation \(i\) in group \(j\) as \(Y_{ij}\). The one-way ANOVA model represents each observation as its group mean plus an error:

$$ Y_{ij}=\mu_j+\varepsilon_{ij}, \qquad i=1,\ldots,n_j,\quad j=1,\ldots,k. $$

Here, \(\mu_j\) is the population mean for group \(j\), and \(\varepsilon_{ij}\) is the error for that observation: its departure from the group’s population mean. For the usual one-way ANOVA model, the errors have mean zero, a common variance \(\sigma^2\), are independent, and are normally distributed for the exact F-test. Equivalently, the errors are independent and each has distribution \(N(0,\sigma^2)\). These are model assumptions; the observed residuals are used to look for signs that the model may not describe the data well.

The population means are not known, so the model’s fitted value for an observation in group \(j\) is the sample mean of that group, \(\bar{x}_j\). The residual is the observed value minus its fitted value.

Definition: For observation \(i\) in group \(j\), the one-way ANOVA fitted value is \(\hat{Y}_{ij}=\bar{x}_j\), and its residual is \(e_{ij}=Y_{ij}-\bar{x}_j\). A residual is an estimate of the observation’s unobserved error, not the error itself.

A positive residual means the observation is above its own group mean; a negative residual means it is below. Residuals have the same units as the response variable. The raw observation retains the group’s location on the response scale, while the residual expresses only the observation’s departure from its fitted group mean.

Worked Example: Separating Group Location From Residuals

Suppose a hypothetical experiment records response scores for three observations in each of two groups. Group A has scores 8, 9, and 10; Group B has scores 18, 19, and 20. Calculate the fitted values and residuals.

The group means are

$$ \bar{x}_A=\frac{8+9+10}{3}=9,\qquad \bar{x}_B=\frac{18+19+20}{3}=19. $$

Every observation in Group A has fitted value 9, and every observation in Group B has fitted value 19. Subtract the relevant group mean from each observation:

$$ \begin{aligned} \text{Group A residuals: }&8-9=-1,\quad 9-9=0,\quad 10-9=1,\\ \text{Group B residuals: }&18-19=-1,\quad 19-19=0,\quad 20-19=1. \end{aligned} $$

The raw observations in Group B are all 10 score units higher than the corresponding observations in Group A. That separation reflects the difference between the fitted group means. The residuals, however, are identical in the two groups: \(-1,0,1\). In this small illustration, the groups differ in location but not in their observed spread around their fitted means. The gap between the raw groups is not, by itself, a residual pattern.

Why Residuals Are Centered Within Groups

Residuals from the fitted one-way ANOVA model sum to zero within each group. This is a mathematical consequence of using the sample group mean as the fitted value, not a diagnostic discovery.

$$ \sum_{i=1}^{n_j}e_{ij} =\sum_{i=1}^{n_j}(Y_{ij}-\bar{x}_j) =\sum_{i=1}^{n_j}Y_{ij}-n_j\bar{x}_j =0, $$

because \(\bar{x}_j=(1/n_j)\sum_{i=1}^{n_j}Y_{ij}\). The fitted group mean also minimizes the sum of squared deviations from a single fitted value for that group. To see why, take any proposed fitted value \(c\). The squared deviations can be written as

$$ \sum_{i=1}^{n_j}(Y_{ij}-c)^2 =\sum_{i=1}^{n_j}(Y_{ij}-\bar{x}_j)^2+n_j(\bar{x}_j-c)^2. $$

To obtain this identity, write \(Y_{ij}-c=(Y_{ij}-\bar{x}_j)+(\bar{x}_j-c)\), square and sum. The cross-product is zero because \(\sum_i(Y_{ij}-\bar{x}_j)=0\). Since \(n_j(\bar{x}_j-c)^2\) cannot be negative, the squared deviations are smallest when \(c=\bar{x}_j\). Thus the ANOVA residuals are the departures from the group values that minimize within-group squared error. Their squared sum, \(\sum_j\sum_i e_{ij}^2\), is the within-group sum of squares, also called the residual sum of squares.

Because each group’s residuals are forced to sum to zero, they are not independent of one another in the way the model errors are assumed to be. Residuals are model-based estimates of errors, with constraints introduced by estimating group means. Their plots are useful diagnostic tools, but they should not be treated as direct displays of independent, observed model errors.

Worked Example: Calculating Residuals and the Within-Group Sum of Squares

A hypothetical study records response values of 4, 5, and 7 in Group A, and 8, 9, and 10 in Group B. Find the fitted values, residuals, and residual sum of squares.

For Group A, the mean is \((4+5+7)/3=16/3\), or about 5.333. The residuals are \(4-16/3=-4/3\), \(5-16/3=-1/3\), and \(7-16/3=5/3\). They sum to zero:

$$ -\frac{4}{3}-\frac{1}{3}+\frac{5}{3}=0. $$

For Group B, the mean is \((8+9+10)/3=9\), giving residuals \(-1,0,1\), which also sum to zero. The fitted value is 16/3 for each observation in Group A and 9 for each observation in Group B. The residual sum of squares is

$$ \begin{aligned} SSE &=\left[(-4/3)^2+(-1/3)^2+(5/3)^2\right]+[(-1)^2+0^2+1^2]\\ &=\frac{16+1+25}{9}+2 =\frac{14}{3}+2 =\frac{20}{3}\approx 6.667. \end{aligned} $$

The calculation uses deviations from each group’s own fitted mean, not deviations from one overall mean. The resulting \(SSE\) summarizes the squared within-group departures that remain after fitting the group means.

Raw-Data Displays and Residual Displays

Raw observations are essential for describing the actual responses. A dotplot or other suitable display organized by group can show where the groups are located, their observed ranges, and unusual values. These are useful features to see before or alongside the model. But if the question is whether deviations around the fitted group means show a systematic pattern, raw observations include group location as well as those deviations.

A residual display removes the fitted group means from the observations. For one-way ANOVA, useful basic displays include residuals plotted by group and residuals plotted in the order observations were collected. A plot against fitted values has one fitted value per group, so observations appear in vertical stacks. In such a plot, different horizontal positions correspond to different fitted group means; they do not, on their own, indicate a residual trend. The residual values within each stack are the deviations from that group’s mean.

Residual displays can suggest that the model leaves structure unexplained—for example, a systematic sequence in collection order or visibly different residual spreads among groups. The appropriate interpretation depends on the plot and on the study design. A visual display does not prove that an assumption is satisfied or violated, and it cannot establish independence without information about how the observations were collected. Detailed assessment of particular patterns uses dedicated diagnostic methods.

Worked Example: Choosing Which Display Answers the Question

A hypothetical experiment compares mean completion time, in minutes, across three methods. The recorded times are Method A: 12, 14, 16; Method B: 22, 24, 26; and Method C: 32, 34, 36. The investigator wants to describe the method differences and separately check whether departures from the fitted means appear similar in the observed groups.

First calculate the group means: Method A has \(\bar{x}_A=14\), Method B has \(\bar{x}_B=24\), and Method C has \(\bar{x}_C=34\). Thus the raw data show that the group locations are separated by 10 minutes. For a display focused on that descriptive comparison, plot the raw completion times by method.

For the residuals, subtract each method’s own mean. Each method yields residuals \(-2,0,2\) minutes. A residual-by-group display therefore shows the departures around each fitted mean without including the 10-minute gaps between fitted means. In this hypothetical data set, the observed residual values are the same across the three groups.

The two displays answer different questions. The raw-data display preserves the between-method differences in completion time. The residual display removes those fitted differences so the remaining departures can be inspected. It would be mistaken to call the three separated clusters in the raw data a residual pattern: the clusters are explained by the fitted method means.

Common Mistake: Diagnosing the Raw Group Separation

A common error is to inspect raw observations from groups with different means, notice that the values form separate clusters, and conclude that the ANOVA residuals show a systematic pattern. That reasoning confuses the fitted group effects with the departures left after fitting those effects.

The correction is to identify what is plotted. If the vertical coordinate is the raw response \(Y_{ij}\), the values include both the group mean and the observation’s departure from it. For a residual diagnostic, calculate or plot \(e_{ij}=Y_{ij}-\bar{x}_j\), while retaining group labels or collection order as needed to interpret the display. At the same time, do not make the opposite mistake of assuming that residuals must look satisfactory because their group sums equal zero: that centering happens automatically and does not establish that the model assumptions hold.

Key takeaway: Raw observations describe the response values, including differences in group location. One-way ANOVA residuals are the differences between each observation and its fitted group mean. Use raw data to describe group outcomes and residuals to examine what remains after fitting those means.

Check Your Understanding

Answer each question using the distinction between fitted group means and residuals.

  1. A group has observations 3, 5, and 7. What is its fitted value for each observation, and what are its residuals?
  2. Why do residuals sum to zero within a group when the fitted value is that group’s sample mean?
  3. Two groups have raw responses that are far apart, but their residuals have similar spreads. Why is the raw gap not, by itself, evidence of a residual pattern?
  4. What question does a raw-data display by group answer that a residual display does not answer as directly?
  5. Why does the fact that residuals sum to zero within groups not prove that the ANOVA assumptions are satisfied?