Regression in Practice

The applied regression unit of the Data Science collection. The vocabulary of inputs, outputs and residuals, the least-squares line and its link to correlation, the assumptions behind standard errors and intervals with a simulation of what each failure costs, multiple regression with indicators, interactions, collinearity and polynomial terms, and logistic regression for yes-or-no outcomes, worked on a diabetes study of 442 patients and the 23 shuttle flights before the Challenger accident.

Regression models how an outcome depends on one or more inputs. This unit of the Data Science collection treats it as a working method: how to fit a model, read its coefficients, check it, and know when its numbers can be trusted. It starts with the vocabulary of inputs, outputs and residuals, derives the least-squares line and its connection to correlation, examines what must hold for its standard errors and intervals to mean what they say, extends the model to several inputs, polynomial terms and interactions, and ends with logistic regression for yes-or-no outcomes.

Two datasets run through the unit. The first is a diabetes study of 442 patients (Efron, Hastie, Johnstone and Tibshirani, 2004), with ten baseline measurements and a measure of disease progression one year later, distributed with scikit-learn so that every number can be reproduced. The second is the record of the 23 space shuttle flights before the Challenger accident, with launch temperature and O-ring distress, from the UCI Machine Learning Repository (Draper, 1993). Every number on these pages is computed by a script in tools/experiments/data-science/, and each article ends with worked problems that extend it on the same data and with open questions an experiment could settle.

How the unit relates to the Statistics collection. These pages are the applied tier. They derive what a practitioner needs on the page (the least-squares line, its standard errors, the omitted-variable identity, the score equations of logistic regression) and link to the Statistics collection for the general proofs. The theory under the whole unit is in two Statistics units: Linear Models for least squares, its geometry, its optimality and its exact tests, and Generalized Linear Models for logistic regression and its relatives. Each article names the exact theorem it relies on.

What it assumes. Means, standard deviations and the normal distribution, as in the collection's Probability and Statistics articles; for the matrix form of multiple regression, products, transposes and inverses of matrices.

Articles

Read in order; each article builds on the ones before it.

  • Introduction to Regression: the vocabulary every regression method shares. Inputs and outputs, describing a scatter plot by direction, form and strength, Anscombe's quartet as the case for plotting first, the model as a function plus error, predictions and residuals, the mean as the baseline a model must beat, and why predictions outside the data, including combinations of in-range inputs, are unsupported.
  • Simple Linear Regression: the least-squares line derived from the normal equations and worked by hand on five patients; the slope as the correlation rescaled into the data's units; regression to the mean; $R^2$ as explained variation and its equality with $r^2$; standard errors, confidence intervals and prediction intervals for the 442 patients.
  • Linear Regression Assumptions: what must hold for standard errors and intervals to be right, in order of importance. Errors against residuals, leverage, residual and Q-Q plots, robust (HC3) standard errors, and a seeded simulation showing that correlated errors cut the coverage of a nominal 95% interval to about one half while non-normal errors barely matter, with the factor behind it derived exactly.
  • Multiple Linear Regression: several inputs at once. The normal equations in matrix form, what "holding the others constant" means and the exact identity linking simple and multiple slopes, adjusted $R^2$, indicator variables, collinearity and the variance inflation factor, interactions, polynomial terms, and overfitting measured by cross-validation.
  • Logistic Regression: the probability of a yes-or-no outcome. Why a straight line fails, odds and log-odds, maximum likelihood by Newton's method worked step by step, odds ratios and the divide-by-4 rule, Wald and likelihood-ratio tests, separation, classification cutoffs, and what the Challenger data could and could not say about a launch at 31 °F.

Where the rest of the site goes deeper

The Statistics collection proves the results these pages use. The Geometry of Least Squares treats least squares as orthogonal projection, with the hat matrix and the Frisch–Waugh–Lovell theorem. The Gauss–Markov Theorem proves that least squares is the best linear unbiased estimator, and Aitken's extension to weighted least squares. The Normal Linear Model and The General Linear Hypothesis derive the exact $t$ and $F$ tests. Leverage, Influence and Residual Diagnostics derives Cook's distance and the deletion formulas, and Ridge and Lasso Regression treats shrinkage on the same diabetes patients. For binary outcomes, Link Functions and the Structure of a Generalized Linear Model, Iteratively Reweighted Least Squares and Deviance and Inference for Generalized Linear Models prove the model, its fitting algorithm and its tests, including when the estimate fails to exist; Multinomial and Softmax Regression extends it to more than two classes.

Within Data Science, the next unit asks how well a fitted model will do on data it has not seen, starting with The Bias-Variance Tradeoff and Cross-Validation. Regression trees, which split the inputs into regions instead of fitting a line, are in Regression Trees. The causal reading of a coefficient, which no regression supplies by itself, is the subject of Potential Outcomes.

Some subjects the open questions on these pages point to have no page on the site yet: smoothing and nonparametric regression (splines, local polynomial fits), quantile and robust regression, and models for measurement error in the inputs. They would belong to a later collection.

References

Each article lists its own references. Two textbooks cover the unit as a whole at the level of these pages: record

  • Gelman, A., Hill, J., and Vehtari, A. (2020). Regression and Other Stories. Cambridge University Press. record · 7 pages
  • James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. record · 39 pages

The datasets: record