| Assumption | What It Means | How to Check |
|---|---|---|
| 1. Linearity | The relationship between X and Y is linear | Residual plot (should show no pattern) |
| 2. Independence | Observations are independent of each other | Study design (can't test with plots) |
| 3. Normality | Residuals are normally distributed | Q-Q plot, histogram of residuals |
| 4. Equal Variance | Variance of residuals is constant (homoscedasticity) | Residual plot (spread should be even) |
Residual = Observed Y - Predicted Y
Residuals are the errors in our predictions. Good regression means small, random residuals with no patterns.
Open Posit Cloud. This whole module runs on one file: 60 cases, one predictor x, and five different outcomes. Each outcome breaks exactly one assumption, so you can see one fault at a time.
Run this:
d <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/regression_diagnostics.csv")
str(d)
good <- lm(y_good ~ x, data = d)
summary(good)
# a residual is one observed value minus what the line predicted for it
head(round(residuals(good), 3))
What R gives for the reference model:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 20.8702 1.7927 11.64 <2e-16 ***
x 2.9451 0.1718 17.14 <2e-16 ***
Residual standard error: 6.837 on 58 degrees of freedom
Multiple R-squared: 0.8351, Adjusted R-squared: 0.8323
F-statistic: 293.8 on 1 and 58 DF, p-value: < 2.2e-16y_good is the reference case — it meets all four assumptions. Everything below is measured against it.
What it means: The relationship between X and Y is actually linear (a straight line fits well).
How to check: Plot residuals vs. fitted values. Should see random scatter with no pattern.
The four-panel diagnostic plot from Chapter 22 is the workhorse. Its top-left panel — Residuals vs Fitted — is the linearity check.
Run this:
curved <- lm(y_curved ~ x, data = d)
par(mfrow = c(2, 2))
plot(good) # the reference: no pattern in the top-left panel
plot(curved) # compare
par(mfrow = c(1, 1))
summary(curved)
What R gives for y_curved:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 25.6281 3.5884 7.142 0.0000
x -0.1266 0.3439 -0.368 0.7141
Multiple R-squared: 0.0023Look at what just happened. The slope is not significant (p = .71) and R² is 0.002 — by the numbers, x tells you nothing about y_curved. But the residual plot shows a clean U.
There is a strong relationship here. It is just not a straight one, and a straight-line model cannot see it. This is the single best argument for looking at the plot before you trust the p-value.
y_curved has a non-significant slope and R² = .002. Explain to a classmate why "there is no relationship between x and y_curved" would be the wrong conclusion.What it means: Each observation is independent - knowing one observation doesn't tell you about another.
If yes to any, you may need special methods (time series analysis, multilevel models, repeated measures ANOVA).
What it means: The residuals follow a normal distribution.
How to check: Q-Q plot or histogram of residuals.
The top-right panel of plot(model) is the Q-Q plot of the residuals — the same plot you read in the normality modules, applied to residuals instead of raw scores. Chapter 11's rule applies: check the residuals, not y.
Run this:
skew <- lm(y_skew ~ x, data = d)
par(mfrow = c(1, 2))
qqnorm(residuals(good), main = "y_good residuals"); qqline(residuals(good), col = "red")
qqnorm(residuals(skew), main = "y_skew residuals"); qqline(residuals(skew), col = "red")
par(mfrow = c(1, 1))
shapiro.test(residuals(good))
shapiro.test(residuals(skew))
What R gives:
> shapiro.test(residuals(good))
Shapiro-Wilk normality test
W = 0.99131, p-value = 0.947
> shapiro.test(residuals(skew))
Shapiro-Wilk normality test
W = 0.88396, p-value = 3.597e-05What it means: The spread of residuals is the same across all values of X.
How to check: Residual plot - spread should be consistent, not getting wider or narrower.
The bottom-left panel (Scale-Location) is the equal-variance check. You want a flat band; a wedge means the spread grows with the fitted value.
Run this:
fan <- lm(y_fan ~ x, data = d)
par(mfrow = c(2, 2))
plot(fan)
par(mfrow = c(1, 1))
# compare the two residual-vs-fitted pictures directly
par(mfrow = c(1, 2))
plot(fitted(good), residuals(good), main = "y_good"); abline(h = 0, col = "red")
plot(fitted(fan), residuals(fan), main = "y_fan"); abline(h = 0, col = "red")
par(mfrow = c(1, 1))
y_fan was built so its residual spread grows with x. Its slope estimate is still roughly unbiased — what heteroscedasticity damages is the standard errors, and therefore every p-value and confidence interval the model reports.
Outlier: An observation that doesn't fit the pattern (large residual)
Influential point: An observation that strongly affects the regression line
| Type | Description | Impact |
|---|---|---|
| Outlier in Y | Far from regression line vertically | Large residual, but may not affect slope much |
| Outlier in X | Extreme X value (leverage point) | Can strongly pull the regression line |
| Influential point | Both extreme X AND doesn't fit pattern | Changes slope and R² substantially |
y_out is identical to y_good except for a single changed value, at the largest x in the dataset. That is the difference between an outlier and an influential point: an unusual y out at the edge of the x range moves the line, one in the middle mostly does not.
Run this (Chapter 25's Cook's distance check):
out <- lm(y_out ~ x, data = d)
cooks_d <- cooks.distance(out)
plot(cooks_d, type = "h",
main = "Cook's distance",
ylab = "Cook's D")
abline(h = 4 / length(cooks_d), col = "red", lty = 2)
which(cooks_d > 4 / length(cooks_d))
round(max(cooks_d), 3)
# refit without the influential case and compare the slope
coef(out)
coef(lm(y_out ~ x, data = d[-which.max(cooks_d), ]))
What R gives:
> which(cooks_d > 4 / length(cooks_d))
[1] 9 10 43
> round(max(cooks_d), 3)
[1] 1.28 # case 9
slope with case 9 : 2.5216
slope without case 9: 2.8513Three cases clear the 4/n screening threshold, but only case 9 exceeds the far stricter Cook's D > 1 rule — and dropping it moves the slope by 0.33, about two standard errors. The other two are flagged by a deliberately sensitive screen and turn out not to matter.
| Violation | Solutions |
|---|---|
| Non-linearity |
- Transform X or Y (log, square root) - Add polynomial terms (X²) - Use non-linear regression |
| Non-independence |
- Use multilevel/mixed models - Time series methods - Repeated measures ANOVA |
| Non-normal residuals |
- Transform Y - Use robust regression - Note: With large n, less critical |
| Unequal variance |
- Transform Y (often log) - Use weighted least squares - Use robust standard errors |
| Outliers/Influential |
- Investigate: data error or real? - Report with and without - Use robust regression - NEVER just delete without justification |
Make sure you can:
Grading: Credit/no-credit, not scored for correctness — but credit requires a genuine attempt; blank or clearly-unattempted answers earn no credit. Work through it with your partner and say what you actually think; a wrong idea you reasoned your way to is worth more here than a right one you copied.
reg3_lastname1_lastname2.pdf and upload to the course site.