COLLEGE STATISTICS • DESCRIPTIVE STATISTICS

Least Squares Regression

The foundational method for fitting a line to bivariate data by minimizing the sum of squared residuals.

Historical Context & Motivation

Long before the advent of modern computing, scientists and mathematicians faced a persistent challenge: given a collection of observed data points that did not fall perfectly along a line, how should one determine the best-fitting linear relationship between two variables? Early astronomers, in particular, needed reliable methods to predict planetary positions from noisy telescopic measurements. The desire to extract a clean signal from imperfect observations gave rise to the method of least squares, one of the most consequential ideas in the history of applied mathematics and statistics.

The core insight is deceptively simple: among all possible lines one could draw through a scatterplot, the optimal line is the one that minimizes the total squared vertical distance between each observed point and the line itself. This criterion—minimizing the sum of squared residuals—yields a unique, closed-form solution and possesses a suite of desirable mathematical properties that make it far superior to ad hoc line-drawing.

1805
Legendre Publishes the Method
Adrien-Marie Legendre introduced the method of least squares in his treatise on determining comet orbits, providing the first published account of the technique and its application to astronomical data.
1809
Gauss's Independent Derivation
Carl Friedrich Gauss demonstrated that least squares is the optimal estimation method when errors follow a normal distribution, connecting the technique to probability theory and establishing its theoretical foundations.
1886
Galton Introduces Regression
Sir Francis Galton coined the term 'regression' while studying the hereditary relationship between parent and offspring heights, observing that extreme values tend to regress toward the population mean.
1922
Fisher Formalizes Statistical Theory
R. A. Fisher established the modern framework of maximum likelihood estimation, proving that least squares estimators are maximum likelihood estimators under the assumption of normally distributed errors.
1970s–present
Computational Revolution
The widespread availability of computers transformed regression from a laborious hand-calculation exercise into an instantly accessible tool embedded in every statistical software package, from R and Python to Excel.

The central question that least squares regression addresses remains as relevant today as it was in the early nineteenth century: given a set of paired observations (x, y), what is the single straight line that most faithfully captures the linear trend in the data, and how do we quantify the strength of that relationship? Understanding this method is essential not only for descriptive statistics but also as the gateway to inferential regression, multiple regression, and the broader landscape of statistical modeling.

Core Principles & Definitions

Before diving into formulas, it is important to establish the conceptual architecture of least squares regression. The method rests on a small number of foundational ideas that, once internalized, make the mathematical machinery feel intuitive rather than arbitrary. At its heart, ordinary least squares (OLS) regression fits a straight line ŷ = b₀ + b₁x to bivariate data by choosing the intercept b₀ and slope b₁ that make the sum of squared residuals as small as possible.

1

Residuals

A residual eᵢ = yᵢ − ŷᵢ is the vertical distance between an observed data point and the fitted line. Positive residuals lie above the line; negative residuals lie below it. The least squares criterion minimizes Σeᵢ².
2

Explanatory vs. Response Variable

The explanatory variable (x) is the predictor, plotted on the horizontal axis. The response variable (y) is the outcome we wish to predict, plotted on the vertical axis. The distinction matters because switching roles yields a different regression line.
3

Slope and Intercept

The slope b₁ quantifies the average change in y per one-unit increase in x. The intercept b₀ gives the predicted value of y when x equals zero—a value that may or may not be meaningful depending on context.
4

The Regression Line Passes Through (x̄, ȳ)

A fundamental property of the OLS regression line is that it always passes through the point (x̄, ȳ), the centroid of the data. This serves as a useful check and provides geometric intuition for how the line pivots around the data's center of mass.
5

Coefficient of Determination (R²)

The value measures the proportion of total variability in y that is explained by the linear relationship with x. It ranges from 0 (no linear association) to 1 (perfect linear fit), and equals the square of the Pearson correlation coefficient r.
KEY TAKEAWAY
Think of fitting a regression line like balancing a seesaw at the data's center of gravity (x̄, ȳ). The least squares criterion is analogous to minimizing the total elastic energy in springs connecting each data point vertically to the line—the line settles at the position where the combined tension is at its absolute minimum. Squaring the residuals ensures that large deviations are penalized disproportionately, preventing a few outliers from being masked by compensating errors on the other side.

Visual Explanation

A scatterplot with a fitted regression line is the canonical visualization for understanding least squares. The diagram below displays a set of bivariate data points, the best-fit line, and the vertical residual segments connecting each observed point to its predicted value on the line. Notice how the residuals vary in sign and magnitude—some points sit above the line (positive residuals) and others below (negative residuals). The least squares method finds the unique line that makes the sum of the squared lengths of these segments as small as possible.

Each purple dot represents an observed data pair. The cyan line is the OLS regression line. The dashed pink segments show the residuals—the vertical gaps the method seeks to minimize in a squared sense.

In the diagram above, observe that the residuals are not uniformly small—some points lie quite close to the line while others deviate more substantially. The critical insight is that squaring the residuals before summing accomplishes two things simultaneously. First, it eliminates the sign of the residual so that positive and negative errors cannot cancel each other out, which would happen if we simply summed the raw residuals (that sum is always zero for the OLS line). Second, squaring gives disproportionately greater weight to large deviations, pulling the fitted line toward outlying observations more aggressively than a criterion based on absolute values would.

Mathematical Framework

The mathematical derivation of the least squares estimators proceeds by formulating the sum of squared residuals as a function of the two unknown parameters b₀ and b₁, then applying standard calculus-based optimization. Given n paired observations (x₁, y₁), (x₂, y₂), …, (xₙ, yₙ), we seek the values of b₀ and b₁ that minimize the objective function S(b₀, b₁) = Σᵢ(yᵢ − b₀ − b₁xᵢ)². Setting the partial derivatives ∂S/∂b₀ and ∂S/∂b₁ equal to zero produces the normal equations, whose closed-form solution yields the formulas below.

SLOPE OF THE REGRESSION LINE
b₁ = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)² = Sₓᵧ / Sₓₓ
Here Sₓᵧ = Σ(xᵢ − x̄)(yᵢ − ȳ) is the sum of cross-deviations and Sₓₓ = Σ(xᵢ − x̄)² is the sum of squared deviations of x. Equivalently, b₁ = r × (sᵧ / sₓ), where r is the Pearson correlation, sᵧ is the standard deviation of y, and sₓ is the standard deviation of x.
INTERCEPT OF THE REGRESSION LINE
b₀ = ȳ − b₁ × x̄
This formula guarantees that the regression line passes through the point (x̄, ȳ). The intercept b₀ represents the predicted value of y when x = 0, though this interpretation is meaningful only if x = 0 falls within or near the observed range of x values.
SUM OF SQUARED RESIDUALS (SSE)
SSE = Σ(yᵢ − ŷᵢ)² = Σeᵢ²
SSE (also called the residual sum of squares or RSS) quantifies the total unexplained variation remaining after fitting the line. The least squares line is, by definition, the line that produces the smallest possible SSE.
COEFFICIENT OF DETERMINATION
R² = 1 − SSE / SST = SSR / SST
Here SST = Σ(yᵢ − ȳ)² is the total sum of squares (total variation in y) and SSR = Σ(ŷᵢ − ȳ)² is the regression sum of squares (explained variation). R² is bounded between 0 and 1 for simple linear regression with an intercept, and equals r².
📐 Partition of Variability
A fundamental identity underpins the R² formula: SST = SSR + SSE. The total variability in y decomposes exactly into the portion explained by the regression (SSR) and the portion left unexplained (SSE). This partition is the basis for ANOVA-based significance tests in inferential regression.

Residual Analysis & Diagnostic Checks

Fitting a least squares line is only the first step; responsible data analysis requires examining the residual plot to assess whether the linear model is appropriate for the data at hand. A residual plot graphs the residuals eᵢ on the vertical axis against the fitted values ŷᵢ (or against x) on the horizontal axis. When the linear model is suitable, the residual plot should exhibit a random, patternless scatter centered around zero. Systematic patterns—curves, fans, or clusters—signal that the linear model is misspecified or that key assumptions are violated.

Four residual plot patterns. Top-left (good): random scatter indicates a well-fitted linear model. Top-right (curved): systematic curvature suggests a nonlinear relationship. Bottom-left (fan-shaped): increasing spread signals heteroscedasticity. Bottom-right: an influential outlier with high leverage and a large residual.

The four panels above illustrate the most common residual diagnostic patterns. When the residual plot displays a random cloud with roughly constant vertical spread, as in the top-left panel, the conditions for linear regression are satisfied. A curved pattern (top-right) indicates that a straight line is not an adequate description of the relationship—a quadratic term or a transformation of x may be needed. The fan-shaped pattern (bottom-left) reveals heteroscedasticity, meaning the variance of the residuals increases (or decreases) with the fitted values, violating the constant variance assumption. Finally, isolated points with extreme x-values and large residuals (bottom-right) can exert high leverage and disproportionately influence the slope and intercept of the regression line.

  • Linearity: The relationship between x and y should be approximately linear. Check via the residual plot—no curvature should be evident.
  • Constant variance (homoscedasticity): The spread of residuals should be roughly the same across all values of x. A funnel or fan shape violates this condition.
  • Independence: Residuals should not exhibit systematic patterns over time or across observations. This is especially important for time-series data.
  • No extreme outliers: Points with unusually large residuals or extreme x-values (high leverage) can unduly distort the regression line. Investigate such points before reporting results.

Worked Example

Suppose a researcher collects data on the number of hours studied (x) and exam score (y) for six students. The dataset is: (2, 50), (3, 58), (5, 72), (7, 84), (8, 90), (9, 93). We will compute the least squares regression line, predict the score for a student who studies 6 hours, and calculate R².

Computation table for the least squares regression of exam score on study hours.
Studentx (hours)y (score)xᵢ − x̄yᵢ − ȳ(xᵢ − x̄)(yᵢ − ȳ)(xᵢ − x̄)²
1250−4.667−24.5114.33321.778
2358−3.667−16.560.50013.444
3572−1.667−2.54.1672.778
47840.3339.53.1670.111
58901.33315.520.6671.778
69932.33318.543.1675.444
Sum34447246.00045.333
Computing the Least Squares Regression Line
1
Step 1 — Compute the MeansSum the x-values and the y-values, then divide each by n = 6. We obtain x̄ = 34 / 6 ≈ 5.667 and ȳ = 447 / 6 = 74.5. These means anchor the regression line: it must pass through the centroid (5.667, 74.5).
x̄ ≈ 5.667, ȳ = 74.5
2
Step 2 — Compute Sₓᵧ and SₓₓFrom the computation table, Sₓᵧ = Σ(xᵢ − x̄)(yᵢ − ȳ) = 246.000 and Sₓₓ = Σ(xᵢ − x̄)² = 45.333. These two quantities are all we need to determine the slope.
Sₓᵧ = 246.000, Sₓₓ = 45.333
3
Step 3 — Calculate the Slope b₁Apply the slope formula: b₁ = Sₓᵧ / Sₓₓ = 246.000 / 45.333 ≈ 5.426. This means that, on average, each additional hour of studying is associated with an increase of approximately 5.43 points on the exam.
b₁ ≈ 5.426
4
Step 4 — Calculate the Intercept b₀Use b₀ = ȳ − b₁ × x̄ = 74.5 − 5.426 × 5.667 ≈ 74.5 − 30.748 ≈ 43.752. The intercept suggests a predicted score of about 43.8 for a student who studies zero hours, though extrapolation to x = 0 should be treated with caution.
b₀ ≈ 43.752
5
Step 5 — State the Regression EquationThe least squares regression line is ŷ = 43.752 + 5.426x. For a student who studies 6 hours, the predicted exam score is ŷ = 43.752 + 5.426(6) = 43.752 + 32.556 ≈ 76.3.
ŷ = 43.752 + 5.426x; predicted score at x = 6: ≈ 76.3
6
Step 6 — Compute R²First compute SST = Σ(yᵢ − ȳ)² = (−24.5)² + (−16.5)² + (−2.5)² + (9.5)² + (15.5)² + (18.5)² = 600.25 + 272.25 + 6.25 + 90.25 + 240.25 + 342.25 = 1551.50. Then SSR = b₁ × Sₓᵧ = 5.426 × 246.000 ≈ 1334.8. Thus R² = SSR / SST = 1334.8 / 1551.5 ≈ 0.860. About 86% of the variability in exam scores is explained by the linear relationship with study hours.
R² ≈ 0.860 (86.0% of variability explained)

Strengths & Limitations

Least squares regression is arguably the most widely used statistical method in applied science, but its utility comes with caveats. A clear-eyed understanding of both its strengths and its limitations is essential for responsible data analysis. The table below summarizes the key considerations practitioners should keep in mind when deploying—or deciding not to deploy—ordinary least squares.

Strengths and limitations of ordinary least squares regression.
StrengthsLimitations
Closed-form solution: b₀ and b₁ can be computed exactly using simple formulas—no iterative algorithms or convergence issues.Assumes linearity: OLS is inappropriate when the true relationship between x and y is nonlinear (e.g., exponential, logistic).
Optimal under Gauss–Markov conditions: among all linear unbiased estimators, OLS has the smallest variance (BLUE property).Sensitivity to outliers: because residuals are squared, extreme observations can exert a disproportionate pull on the fitted line.
Interpretability: the slope directly quantifies the average change in y per unit change in x, and R² has an intuitive percentage interpretation.Correlation ≠ causation: a significant regression does not establish that x causes changes in y; lurking variables and confounders may be at work.
Foundation for extension: OLS generalizes naturally to multiple regression, polynomial regression, and the generalized linear model framework.Extrapolation risk: predictions for x-values far outside the observed data range are unreliable and may be seriously misleading.
Universally available: every statistical software package, spreadsheet, and scientific calculator includes OLS regression capability.Requires independent observations and constant variance (homoscedasticity); violations reduce efficiency and can bias standard errors.
KEY TAKEAWAY
Think of OLS regression as a precision-engineered tool: it performs beautifully when applied to the correct task (fitting a linear trend to well-behaved data) but can produce misleading results if used on data that violate its assumptions. Just as a structural engineer must verify load conditions before using a beam-bending formula, a statistician must verify linearity, constant variance, and the absence of influential outliers before trusting an OLS regression line. The residual plot is your primary diagnostic instrument.

Connection to Advanced Theory

Simple linear regression—one explanatory variable, one response—is the entry point into a vast ecosystem of regression methods. Once you master the ideas of minimizing squared residuals, interpreting slopes, and checking residual plots, the conceptual leap to more advanced techniques becomes manageable because the same foundational logic persists. The table below contrasts simple OLS with several extensions you will encounter in subsequent coursework.

Simple linear regression vs. advanced regression methods.
FeatureSimple Linear RegressionAdvanced Extensions
PredictorsOne explanatory variable (x)Multiple regression uses k predictors: ŷ = b₀ + b₁x₁ + b₂x₂ + … + bₖxₖ
Functional formStrictly linear: ŷ = b₀ + b₁xPolynomial regression adds x², x³, etc.; spline regression uses piecewise polynomials
Response typeContinuous (quantitative y)Logistic regression handles binary outcomes; Poisson regression handles counts
EstimationOrdinary least squares with closed-form solutionMaximum likelihood or iteratively reweighted least squares for GLMs; regularization (Ridge, Lasso) for high-dimensional data
Inferencet-tests for slope, F-test for overall model (in inferential statistics)Wald tests, likelihood ratio tests, AIC/BIC model comparison, cross-validation

When you encounter multiple regression in your next course, you will find that the OLS principle—minimize the sum of squared residuals—remains identical; only the dimensionality of the problem changes. Matrix algebra replaces the scalar formulas (the slope becomes a vector, and Sₓₓ becomes a matrix), but the conceptual core is the same. Similarly, logistic regression replaces the squared-error loss with a log-likelihood, yet the idea of optimizing a criterion function to find the best-fitting model parameters carries over directly. Mastering simple least squares regression therefore equips you with the intellectual scaffolding for virtually every regression method you will ever use.

Practice Problems

PROBLEM 1CONCEPTUAL
Explain why minimizing the sum of the raw (unsquared) residuals Σeᵢ is not a suitable criterion for fitting a regression line, and describe the advantage of minimizing Σeᵢ² instead.
PROBLEM 2BASIC CALCULATION
For the data set (1, 3), (2, 5), (3, 6), (4, 8), (5, 11), compute the slope b₁ and intercept b₀ of the least squares regression line.
PROBLEM 3INTERMEDIATE
A dataset of n = 20 observations yields x̄ = 10, ȳ = 25, sₓ = 4, sᵧ = 6, and the Pearson correlation r = 0.85. Determine the equation of the least squares regression line, compute R², and predict ŷ when x = 14.
PROBLEM 4APPLIED
A public health researcher fits a regression of systolic blood pressure (mmHg) on daily sodium intake (grams) for 50 adults and obtains ŷ = 98.4 + 4.2x with R² = 0.41. Interpret the slope and R² in context, and explain why the researcher should not conclude that reducing sodium intake will cause a drop in blood pressure based solely on this regression.
PROBLEM 5CRITICAL THINKING
Prove algebraically that the sum of the residuals for the ordinary least squares regression line equals zero, i.e., Σeᵢ = 0. Start from the normal equation obtained by differentiating the sum of squared residuals with respect to b₀.

Summary

Least squares regression fits a straight line ŷ = b₀ + b₁x to bivariate data by minimizing the sum of squared residuals Σ(yᵢ − ŷᵢ)². The slope b₁ = Sₓᵧ / Sₓₓ quantifies the average change in the response per unit increase in the explanatory variable, while the intercept b₀ = ȳ − b₁x̄ ensures the line passes through the centroid (x̄, ȳ). The coefficient of determination R² measures the proportion of total variability in y explained by the linear relationship with x.

Always examine the residual plot to verify that the conditions of linearity, constant variance, and independence are met before interpreting the regression output. Be wary of outliers with high leverage, avoid extrapolation beyond the observed range of x, and remember that a strong linear association does not establish causation. Mastery of simple OLS regression provides the conceptual foundation for multiple regression, generalized linear models, and the broader landscape of statistical modeling.

Varsity Tutors • College Statistics • Least Squares Regression