A least-squares line can be computed for any set of points with at least two distinct input values. The formulas of Simple Linear Regression always return a slope, an intercept, standard errors and a $p$-value, whether or not the data resemble the model those numbers assume. The line itself is defined without any assumptions: it is the line with the smallest residual sum of squares. But everything said about its uncertainty, the standard errors, confidence intervals, prediction intervals and tests, is derived from a model of how the data were generated, and is only as good as that model.
This article states the assumptions, shows how to check each one with plots of the residuals, and measures what goes wrong when one fails. The running examples are the regression of disease progression on body mass index (BMI) for 442 diabetes patients (Efron, Hastie, Johnstone and Tibshirani, 2004), whose least-squares line is $\widehat{\text{progression}} = -117.77 + 10.233 \times \text{BMI}$, and Anscombe's (1973) four datasets, introduced in Introduction to Regression. A seeded simulation then shows, for each kind of failure, how often the textbook 95% interval for the slope actually contains the true slope.
The model behind the numbers
Simple linear regression assumes the data arose as
$$y_i = \beta_0 + \beta_1 x_i + \varepsilon_i, \qquad i = 1, \dots, n,$$
where $\beta_0$ and $\beta_1$ are fixed unknown coefficients and $\varepsilon_i$ is the error for observation $i$. The standard assumptions concern those errors:
- Linearity. The errors have mean zero at every value of $x$; equivalently, the average of $y$ at each $x$ lies on the straight line $\beta_0 + \beta_1 x$.
- Independence. The errors are independent of one another (in the weakest form, uncorrelated).
- Constant variance. The errors have the same variance $\sigma^2$ at every value of $x$. This is called homoscedasticity, and its failure heteroscedasticity.
- Normality. The errors follow a normal distribution.
The first three are what the standard error formulas use: James, Witten, Hastie and Tibshirani (2021, §3.1.2) state that $\mathrm{SE}(b_1) = \sigma/\sqrt{S_{xx}}$ requires errors that are uncorrelated with a common variance. The fourth is what turns a standard error into an exact $t$ interval or $p$-value in small samples. The initials give the common mnemonic LINE.
Errors are not residuals
The assumptions are about the errors $\varepsilon_i$, the deviations from the true line, which are never observed. What can be computed are the residuals $e_i = y_i - \hat{y}_i$, the deviations from the fitted line. Residuals are the evidence about the errors, but they are not a sample of them, and they behave differently in two ways.
First, the residuals are constrained. The normal equations force $\sum e_i = 0$ and $\sum x_i e_i = 0$, so the residuals always average exactly zero and are always uncorrelated with $x$, whatever the errors are like. That is why the mean-zero part of the linearity assumption cannot be checked by averaging the residuals; it can only be checked by looking for a pattern in them.
Second, residuals do not all have the same variance even when the errors do. Under the model, $\mathrm{Var}(e_i) = \sigma^2 (1 - h_i)$, where
$$h_i = \frac{1}{n} + \frac{(x_i - \bar{x})^2}{S_{xx}}$$
is the leverage of observation $i$, with $S_{xx} = \sum (x_j - \bar{x})^2$. Leverage measures how far an observation's input lies from the center of the inputs. A point with high leverage pulls the fitted line toward itself, so its residual is small even when its error is large. Leverages always lie between $1/n$ and 1, and in simple regression they average $2/n$ (James et al., 2021, §3.3.3). For the diabetes data the average is $2/442 = 0.0045$, and the largest is 0.0314, for the patient with the highest BMI, 42.2. In the fourth of Anscombe's sets, the single point at $x = 19$ has leverage 1.000: the line must pass through it exactly, its residual is zero, and nothing in the residuals reveals how much it controls the fit.
Dividing each residual by its own estimated standard deviation gives the studentized residual $e_i / (\hat{\sigma}\sqrt{1 - h_i})$, where $\hat{\sigma}$ is the residual standard error, which puts all residuals on a common scale. James et al. (2021, §3.3.3) suggest treating studentized residuals beyond 3 in absolute value as possible outliers. The diabetes model has none; 13 of its 442 exceed 2, where about 20 would be expected if the errors were normal.
In order of importance
The four assumptions are not equally important, and they are not the only ones. Gelman, Hill and Vehtari (2020, §11.1) list the assumptions of regression "in decreasing order of importance" and put two before any of the four above:
- Validity. The data must answer the question. The outcome must measure what is of interest, the model should include the relevant predictors, and it must apply to the cases it will be used for.
- Representativeness. The sample must represent the population of interest, in the sense that the distribution of the outcome given the inputs is the same.
- Additivity and linearity, which they call the most important mathematical assumption.
- Independence of errors.
- Equal variance of errors.
- Normality of errors.
No residual plot can detect a failure of the first two. A study of patients at risk of a disease may not describe healthy people, whatever the diagnostics say. For the diabetes data, all 442 participants were diabetes patients, so the line describes how progression varies with BMI among diabetes patients like them, and nothing more.
Among the four mathematical assumptions, the order matters in practice. If the form is wrong, the model is wrong, and repairing its standard errors will not help. If the errors are dependent, every statement about uncertainty is suspect. Unequal variance distorts uncertainty more mildly. Normality matters least of all, except for predicting individual values. The simulation below puts numbers on each of these statements.
Diagnostic plots
Two plots do most of the work. The residuals-versus-fitted plot puts $\hat{y}_i$ on the horizontal axis and $e_i$ on the vertical, with a reference line at zero. With one input, plotting against $x$ shows the same pattern, but plotting against the fitted values carries over unchanged to models with many inputs. If the assumptions hold, the points form a horizontal band of even width around zero, with no curve, no funnel and no clusters. The normal Q-Q plot sorts the residuals and plots them against the quantiles a normal sample of the same size would have; if the residuals are close to normal, the points fall close to a straight line.
Linearity
The residuals-versus-fitted plot is the main check for linearity. If the true relationship curves, the line is too high in some regions and too low in others, and the residuals trace the curve that the line missed. In the second of Anscombe's sets, which follows a parabola exactly, the residuals are $1.14, 1.14, -0.76, 1.27, \dots$, positive in the middle of the input range and negative at both ends.
A violation of linearity biases every prediction in a way that depends on where the input is, and makes the slope a summary of something that is not a straight line. The remedy is to change the model, not its standard errors: transform the input or the output (taking logarithms is the most common), add a squared term, or use a more flexible model. Multiple Linear Regression fits Anscombe's second set exactly with a quadratic.
Independence
Errors are dependent when observations share something the model does not include. Measurements over time are the classic case: if this month's error is positive, next month's is likely to be positive too, a pattern called tracking (James et al., 2021, §3.3.3). Observations clustered in space, repeated measurements of the same person, and members of the same family or school are other common cases. Gelman et al. (2020, §11.1) note that the independence assumption is violated in time series, spatial and multilevel settings.
Dependence is usually a property of how the data were collected, so the first check is to ask how they were collected. When the observations have a natural order, such as time, plotting the residuals in that order shows tracking as long runs above or below zero. The diabetes data have no documented order; the correlation between each residual and the next, in the order of the file, is 0.075.
Positively correlated errors carry less information than the same number of independent ones, because each observation partly repeats its neighbor. The standard errors, which assume independence, are then too small, and intervals too narrow (James et al., 2021, §3.3.3). The simulation below shows how large the effect can be. Remedies model the dependence: time-series models for ordered data, and standard errors or mixed models that account for clusters.
Constant variance
When the spread of the outcome grows with its level, the residuals-versus-fitted plot fans out. This is common for outcomes that are counts, amounts of money or concentrations, where larger values vary more in absolute terms. James et al. (2021, §3.3.3) give the funnel shape as the sign of heteroscedasticity and suggest transforming the response, for example with a logarithm.
The diabetes residuals show mild heteroscedasticity. Split into thirds by fitted value, their standard deviation is 49.6 for fitted values from 66.4 to 128.8, 67.9 for the middle third, and 68.4 for fitted values from 167.7 to 314.1. Part of the reason is visible in the plot: the smallest progression in the data is 25, so a patient with a low fitted value cannot have a large negative residual. The residual for a fitted value $\hat{y}$ can be no lower than $25 - \hat{y}$, the dashed line. Taking the logarithm of progression does not even out the spread here: the standard deviations by thirds become 0.457, 0.528 and 0.415.
With unequal variance, the least-squares line is still unbiased, but it is no longer the most precise estimate available, and the usual standard error is wrong because it averages the variance over all observations. White (1980) gave an estimator of the coefficients' covariance matrix that remains consistent when the errors are heteroscedastic, without a model of how the variance changes. It replaces the single $\hat{\sigma}^2$ with each observation's own squared residual. A variant with better behavior in small samples, called HC3, scales each squared residual by $1/(1 - h_i)^2$; it is a simplified form of the jackknife estimator that MacKinnon and White (1985) studied. For the diabetes slope, the classical standard error is 0.6738 and the HC3 standard error 0.6181, so the mild fan makes little difference to the conclusion. If the form of the variance is known, weighted least squares, which gives noisier observations less weight, is more efficient (Gelman et al., 2020, §11.1).
Normality
The normal Q-Q plot of the diabetes residuals is close to a straight line; the correlation between the sorted residuals and the normal quantiles is 0.9958. The residuals have skewness 0.156 and excess kurtosis $-0.547$, meaning slightly shorter tails than a normal distribution. A Q-Q plot whose points fall below the line at the low end and rise above it at the high end indicates heavy tails, more extreme residuals than a normal distribution produces; one that bows to one side of the line along its whole length indicates skewness.
Normality is the least important assumption for the slope. Least squares does not need it to find the line, and the central limit theorem makes the estimated slope approximately normal in moderate samples whatever the errors' distribution, so intervals and tests for the coefficients are approximately right. Gelman et al. (2020, §11.1) go further: for estimating the regression line, "the assumption of normality is typically barely important at all", and they do not recommend routine normality diagnostics. Normality matters more for prediction intervals, which describe the spread of individual outcomes, not of an average. A 95% prediction interval built from a normal distribution will be wrong for skewed or heavy-tailed errors no matter how large the sample. For the diabetes model, 426 of the 442 patients (96.4%) fall inside their own 95% prediction intervals, consistent with the residuals' near-normal shape.
Outliers and influential points
An outlier is an observation whose output is far from the model's prediction, and a high-leverage point is one whose input is far from the others. A point that is both can change the fit substantially (James et al., 2021, §3.3.3). In the third of Anscombe's sets, ten points lie exactly on one line and the eleventh, at $(13, 12.74)$, lies well above it. With all eleven, the fitted line is $\hat{y} = 3.00 + 0.500\,x$. Without that point it is $\hat{y} = 4.0056 + 0.3454\,x$, the line through the other ten. One point in eleven made the slope 44.8% steeper than the other ten imply.
An outlier is a reason to investigate, not to delete. It may be a recording error, which should be corrected; a case from a different population, which may belong in a separate analysis; or a genuine extreme value, which belongs in the data. Reporting the fit with and without it is often the honest answer.
What a failure costs: a simulation
How much does each failure matter? The question can be answered directly by simulating data where the truth is known. Each scenario below generates 10,000 datasets of $n = 30$ points with inputs drawn uniformly between 0 and 1 and a true line $y = 1 + 2x$, fits a least-squares line to each, and records whether the usual 95% interval for the slope, $b_1 \pm t_{0.975,\,28}\,\mathrm{SE}(b_1)$, contains the true slope 2. If the interval is right, it should do so 95% of the time. The errors differ by scenario:
- All assumptions hold: independent standard normal errors.
- Variance grows with $x$: normal errors with standard deviation $2x$.
- Errors correlated in time: the inputs are sorted, standing for time, and the errors follow a first-order autoregressive process, each error 0.8 times the previous one plus fresh noise, scaled to variance 1.
- Heavy tails: errors from a $t$ distribution with 3 degrees of freedom.
- Skewed errors: exponential errors with their mean subtracted.
| Scenario | Coverage of textbook interval | Coverage of HC3 interval | Actual SD of $b_1$ | Average reported SE |
|---|---|---|---|---|
| All assumptions hold | 0.951 | 0.955 | 0.652 | 0.644 |
| Variance grows with $x$ | 0.921 | 0.937 | 0.821 | 0.733 |
| Errors correlated in time | 0.497 | 0.508 | 1.509 | 0.497 |
| Heavy tails ($t_3$) | 0.950 | 0.960 | 1.118 | 1.040 |
| Skewed errors | 0.954 | 0.963 | 0.651 | 0.632 |
In every scenario the average estimated slope is within 0.013 of the true value 2, so least squares remains unbiased in all of them. What fails is the reported uncertainty.
- Correlated errors are the most damaging. The slope actually varies with a standard deviation of 1.509 across datasets, but its reported standard error averages 0.497, three times too small, and the nominal 95% interval contains the truth only half the time. HC3 does not help, because it corrects for unequal variance, not dependence.
- Unequal variance costs a few points of coverage, 0.921 instead of 0.95, and the HC3 interval brings it to 0.937.
- Non-normal errors barely matter for the slope's interval at $n = 30$: coverage is 0.950 for heavy tails and 0.954 for skewed errors. The heavy tails make the slope less precise, an actual standard deviation of 1.118 against 0.652 with normal errors, but the reported standard error tracks that loss.
These are results for one sample size and particular strengths of each failure, and stronger violations would do more damage, but the ordering matches the ordering of Gelman et al. (2020). The simulation is seeded and can be rerun from tools/experiments/data-science/linear-regression-assumptions.py.
A routine for checking
- Think about validity and representativeness first. What population do the data describe, and how were they collected? Are observations grouped in time, space or by subject?
- Plot residuals against fitted values. Look for curves (linearity) and funnels (variance).
- If the data have an order or a grouping, plot residuals by it. Look for runs and clusters (independence).
- Look for outliers and high-leverage points, using studentized residuals and leverages, and refit without them to see what changes.
- Make a Q-Q plot if individual predictions matter, for prediction intervals.
When an assumption fails, change what the failure calls for. A wrong form calls for a different model; dependence calls for a model of the dependence; unequal variance calls for robust standard errors, weighting or a transformation; and non-normality, if it matters at all, calls for a transformation or for intervals that do not assume normality, such as those from the bootstrap.
In Python
None of these diagnostics needs a specialized library. The residuals come from any fitted model, the leverages from the formula above, and SciPy's probplot computes the points of a Q-Q plot.
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression
data = load_diabetes(scaled=False)
x, y = data.data[:, 2], data.target
model = LinearRegression().fit(x.reshape(-1, 1), y)
fitted = model.predict(x.reshape(-1, 1))
resid = y - fitted
n = len(y)
lev = 1 / n + (x - x.mean()) ** 2 / ((x - x.mean()) ** 2).sum()
sigma = np.sqrt((resid ** 2).sum() / (n - 2))
student = resid / (sigma * np.sqrt(1 - lev))
print(lev.max(), (np.abs(student) > 3).sum()) # 0.0314, 0
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 3.5))
ax1.scatter(fitted, resid, s=8)
ax1.axhline(0, color="gray")
ax1.set_xlabel("fitted value")
ax1.set_ylabel("residual")
stats.probplot(resid, dist="norm", plot=ax2) # normal Q-Q plot
plt.show()
The figures and numbers in this article are computed by tools/experiments/data-science/linear-regression-assumptions.py in the site's repository.
References
- Anscombe, F. J. (1973). Graphs in statistical analysis. The American Statistician, 27(1), 17–21. record · 4 pages
- Efron, B., Hastie, T., Johnstone, I., and Tibshirani, R. (2004). Least angle regression. The Annals of Statistics, 32(2), 407–499. record · 12 pages
- Gelman, A., Hill, J., and Vehtari, A. (2020). Regression and Other Stories. Cambridge University Press. record · 6 pages
- James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. record · 30 pages
- MacKinnon, J. G., and White, H. (1985). Some heteroskedasticity-consistent covariance matrix estimators with improved finite sample properties. Journal of Econometrics, 29(3), 305–325. record
- White, H. (1980). A heteroskedasticity-consistent covariance matrix estimator and a direct test for heteroskedasticity. Econometrica, 48(4), 817–838. record · 2 pages