Statistics · medium

What are the assumptions of linear regression, and how do you check them?

Asked in Data Scientist interviews, in the Statistics round.

Short answer

Linear relationship, independent errors, constant error variance, normal errors for inference, and no severe multicollinearity. Check with residual plots, a Durbin Watson or autocorrelation plot, a scale location plot, a Q-Q plot, and VIF.

How to answer it

Definition

Ordinary least squares gives unbiased, efficient estimates with valid standard errors only under a set of assumptions. Different assumptions protect different things, which is why it matters which one is violated.

The assumptions

Linearity            the relationship really is linear in the parameters
Independence         observations are independent of each other
Homoscedasticity     residual variance is constant across fitted values
Normality            the RESIDUALS are roughly normal (matters for inference)
No perfect
  multicollinearity  predictors are not exact linear combinations
Exogeneity           the errors are uncorrelated with the predictors

How to check them

import statsmodels.api as sm

model = sm.OLS(y, sm.add_constant(X)).fit()
resid, fitted = model.resid, model.fittedvalues

# linearity and homoscedasticity: residuals against fitted
#   a curve  -> non-linearity
#   a funnel -> heteroscedasticity
# normality: a Q-Q plot of the residuals
# independence: Durbin-Watson, or residuals against time
# multicollinearity: VIF per predictor
print(model.summary())

The residuals-against-fitted plot is the single highest-value diagnostic: it shows linearity and constant variance at once, and a curve or a funnel is visible immediately.

What each violation costs

Key points

FAQ

The 30-second answer

Linearity, independence, constant error variance, roughly normal residuals, and no perfect collinearity between predictors.
The first thing I would do is plot residuals against fitted values, because that one chart shows linearity and homoscedasticity at once: a curve means the relationship is not linear, a funnel means the variance is not constant. Then a Q-Q plot for normality and VIF for collinearity.
What I would emphasise is that they are not equally serious. Non-normal residuals barely matter at a decent sample size. Heteroscedasticity leaves the coefficients fine and just needs robust standard errors. Non-independence makes the standard errors far too small, so everything looks significant. Non-linearity is the one that actually biases the estimates.

In the interview

Practice this for real