AP Statistics · Exploring two-variable data
Residuals and departures from linearity
1Residuals
A residual is the prediction error for one data point:
$$\text{residual} = y - \hat{y} = \text{actual} - \text{predicted}$$
- Positive residual: the point is above the line (the model underestimated).
- Negative residual: the point is below the line (the model overestimated).
- For the LSRL, the residuals always add to 0.
$\hat{y} = 35 + 2x$. A point $(15, 70)$.
- $\hat{y} = 35 + 30 = 65$.
- Residual $= 70 - 65 = 5$: the actual value is 5 units above the prediction.
Check yourself
The model predicts 82 and the actual value is 78. The residual is:
Show the answer
−4
Actual − predicted.
2Residual plots
A residual plot graphs residuals against $x$ (or $\hat{y}$).
- No pattern (random scatter around 0): a linear model is appropriate.
- A curved pattern: the relationship is non-linear; a straight line is not the best model.
- Fanning out (residuals grow with $x$): the variability of $y$ changes with $x$, so predictions are less reliable for larger $x$.
Read a residual plot: no pattern is good; curves and fans are warning signs
Check yourself
A residual plot shows a clear U-shape. This means:
Show the answer
A linear model is not appropriate
Curvature remains.
3Outliers, leverage and influence in regression
- Outlier in regression: a point with a large residual.
- High-leverage point: an $x$ value far from $\bar{x}$; it can pull the line toward itself.
- Influential point: removing it substantially changes the slope, intercept or correlation. High-leverage points are often influential.
a regression of salary on years of experience includes one CEO with 30 years and a very high salary. Removing that point drops the slope from $2,800 to $1,900 per year: the point is influential.
Check yourself
A point far from the other x-values that changes the slope greatly when removed is:
Show the answer
Influential with high leverage
Leverage plus influence.
4Transforming to achieve linearity
If a scatterplot or residual plot shows curvature, you can transform variables to straighten the relationship:
- Exponential pattern $y = ab^x$: plot $\log y$ against $x$. If linear, $\log y = c + dx$.
- Power pattern $y = ax^p$: plot $\log y$ against $\log x$.
- Square or square-root transformations for other curves.
Choose the model whose residual plot shows no pattern and whose $r^2$ is higher.
bacteria counts grow exponentially. The regression $\widehat{\log y} = 1.2 + 0.15t$ fits well.
- Predict at $t = 10$: $\widehat{\log y} = 2.7$.
- $\hat{y} = 10^{2.7} \approx 501$ bacteria.
Check yourself
If log y against x is linear, the original relationship is:
Show the answer
Exponential
log y = c + dx means y = 10^c (10^d)ˣ.
5Going deeper: residual plots, unusual points and transforming to achieve linearity
A residual is observed − predicted. A residual plot graphs the residuals against x (or against the predicted values).
Reading a residual plot
- No pattern: points scattered randomly above and below zero. A linear model is appropriate.
- A curved pattern (a U or an arch): the relationship is not linear; a line is the wrong model, even if r is high.
- A fan shape (spread growing or shrinking as x increases): predictions are less precise for some values of x than others.
- The residuals from a least-squares line always have a mean of zero.
A high r² does not prove that a line is the right model: a strongly curved relationship can have r² above 0.9. Check the residual plot.
Standard deviation of the residuals, s: "the typical distance between the actual y-values and those predicted by the line." Small s (in the units of y) means precise predictions.
Unusual points
- Outlier (in regression): a point with a large residual; it lies far from the line in the vertical direction.
- High-leverage point: a point whose x-value is far from the other x-values.
- Influential point: a point that, if removed, substantially changes the slope, the intercept or the correlation. High-leverage points are often influential.
twenty students' data show a positive linear trend in study hours (2 to 8) and scores. A twenty-first student studied 20 hours and scored 60.
- This point has high leverage (x far from the rest).
- It lies far below the pattern, so it pulls the right-hand end of the line down: the slope decreases and the correlation weakens. It is influential.
- Had the student scored 150 (on the same trend), the point would have high leverage but little influence on the slope, and it would strengthen r.
- Good practice: report the analysis with and without the point.
A high-leverage point may have a small residual, because it pulls the line toward itself. Looking for large residuals alone can miss the most influential point.
Transforming to achieve linearity: when the scatterplot is curved, transform one or both variables so that the relationship becomes linear, fit a line, then transform back to make predictions.
Exponential model ($y = ab^x$): y is multiplied by a constant factor for each unit increase in x. Taking logarithms of y straightens it: a plot of ln y against x is linear.
a regression of ln(population) on year since 2000 gives ln(predicted population) = 1.20 + 0.35 x. Predict the population when x = 4.
- ln(prediction) = 1.20 + 0.35(4) = 2.60.
- Prediction = e^2.60 = 13.5 (in the original units).
- Forgetting to undo the logarithm (reporting 2.60) is the commonest error.
Power model ($y = ax^p$): taking logarithms of both variables straightens it: a plot of ln y against ln x is linear.
ln(predicted weight) = 0.50 + 2.0 ln(length). Predict the weight for a length of 3.
- ln(3) = 1.099.
- ln(prediction) = 0.50 + 2.0(1.099) = 2.697.
- Prediction = e^2.697 = 14.8.
Other transformations: square roots, reciprocals, or raising x to a power, when theory suggests them (area is related to the square of a length; volume and weight to its cube).
Choosing between models: fit each candidate and compare the residual plots. Prefer the model whose residual plot shows the most random scatter; r² is a secondary guide.
for the same data, a linear model has r² = 0.94 and a clearly U-shaped residual plot; an exponential model has r² = 0.99 and a patternless residual plot.
- The linear model's high r² is misleading.
- The exponential model is more appropriate, chiefly because of its residual plot.
Residual plots from a calculator or computer output should be sketched and labelled when you use them as evidence.
Common mistakes
- Judging linearity from r or r² alone.
- Calling any point far from the others an "outlier" without saying in which direction.
- Confusing leverage (unusual x) with a large residual (unusual y for its x).
- Forgetting to back-transform a prediction.
- Saying a residual plot "is linear"; the aim is no pattern.
- Writing the log-model equation without "ln" on the predicted variable.
Check yourself
A residual plot shows a clear U-shaped pattern. What does this indicate?
Show the answer
A linear model is not appropriate for the data
A pattern in the residuals shows that the form of the relationship is not linear.
6For top marks
- Calculate and interpret residuals in context: "The actual ... was 5 ... higher than predicted."
- Use the residual plot (not just $r$) to judge whether a linear model is appropriate.
- Identify outliers, high-leverage and influential points and explain their effect.
- When using a transformed model, back-transform predictions to the original units.
"The residual plot shows a curved pattern, so although $r = 0.93$, a linear model is not appropriate; a log transformation of $y$ removes the curve."
Check yourself
A high r with a curved residual plot means:
Show the answer
A non-linear model may fit better
Check the residuals.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera