- Introduced by
- Adrien-Marie Legendre (1805); Carl Friedrich Gauss (1809)
- Year
- 1805
- Type
- Linear parameter estimation
What does it do?
Ordinary Least Squares (OLS) estimates the parameters of a linear regression model by choosing the coefficients that minimize the sum of squared differences between observed and fitted values.
Legendre published the least-squares criterion in 1805, and Gauss, who claimed to have used the method from 1795, published the theory in 1809. Under the classical assumptions of the Gauss-Markov theorem, OLS gives the Best Linear Unbiased Estimator (BLUE) of the regression coefficients.
The intuition behind the method
Imagine drawing a straight line through a cloud of data points. OLS chooses the line, or in several predictors the hyperplane, that makes the squared vertical distances from the data points to the fitted surface as small as possible in total. Squaring the distances means large errors count disproportionately, and it gives the minimization problem a unique closed-form solution whenever the predictors are not perfectly collinear. Each coefficient is read as the expected change in the outcome for a one-unit increase in that predictor, holding the other predictors constant. That reading is a statement about association in the fitted model; it becomes a causal reading only if the exogeneity assumption holds.
History
Adrien-Marie Legendre first published the least-squares method in the appendix 'Sur la Méthode des moindres quarrés' of his 1805 work on cometary orbits. Carl Friedrich Gauss claimed to have used the method since 1795, but that claim is contested, and his 1809 work on celestial mechanics gave a fuller theoretical treatment, including the normal equations. The matrix formulation, the optimality result now called the Gauss-Markov theorem, and the extension to multiple regression were developed over the following century by Markov, Aitken and others. OLS remains the standard estimation method in econometrics and applied statistics.
When to use it
Use OLS when the outcome is continuous and you expect its relationship with one or more predictors to be linear in the parameters. The estimator is justified when the classical conditions hold: (1) the model is linear in the parameters; (2) X has full column rank, so there is no perfect multicollinearity; (3) the errors have zero conditional mean, E(ε | X) = 0 (exogeneity); (4) the errors are homoskedastic with constant variance σ²; and (5) the errors are uncorrelated across observations. Under these conditions the Gauss-Markov theorem applies, and exact t- and F-inference in finite samples additionally requires normally distributed errors. Do not rely on conventional OLS standard errors when the error variance may vary across observations; use heteroskedasticity-robust standard errors or Weighted Least Squares instead. Serial correlation calls for GLS-type corrections, and endogenous predictors call for Instrumental Variables or Two-Stage Least Squares.
Limitations and considerations
- Assumes a correctly specified linear functional form; nonlinear relationships need transformed predictors or a nonlinear model.
- Sensitive to outliers and high-leverage observations, because the squared loss gives extreme residuals large weight in the fit.
- Under heteroskedasticity OLS remains unbiased and consistent, but it is no longer the most efficient linear estimator, and the conventional standard errors are invalid unless corrected.
- Produces biased and inconsistent coefficient estimates when a predictor is correlated with the error term (endogeneity).
- When predictors are highly collinear, XᵀX is nearly singular, so the coefficient estimates have large variances and are unstable and hard to interpret individually.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Closed-form solution: β̂ = (XᵀX)⁻¹Xᵀy is computed directly, without iterative optimization, when XᵀX is invertible.
- Under the Gauss-Markov conditions, β̂ is BLUE, the lowest-variance estimator among linear unbiased estimators.
- Each coefficient has a direct interpretation as the expected change in the outcome per unit change in that predictor, holding the others fixed; this reads as causal only when exogeneity is credible.
- Standard inference (t-tests, F-tests, confidence intervals and R²) follows directly from the same covariance formula σ²(XᵀX)⁻¹.
- Small systems can be solved by hand, which makes each step of the estimate easy to check.
Applications
- Economics and econometrics: estimating demand curves, wage equations, production functions, and policy effects.
- Social sciences: modeling outcomes such as test scores or income as functions of individual and contextual predictors.
- Engineering and the natural sciences: fitting empirical relationships between physical variables and calibrating measurement instruments.
- Finance: estimating the beta of an asset in the Capital Asset Pricing Model (CAPM) by regressing its excess returns on market excess returns.
- Epidemiology and public health: modeling a continuous health outcome as a function of exposures, covariates and treatment indicators.
How it works
How it works
The starting point is the linear model y = Xβ + ε, where y is the n×1 vector of outcomes, X is the n×k matrix of predictors (including a column of ones for the intercept), β is the k×1 vector of unknown coefficients, and ε is the error term, assumed to have zero mean and constant variance σ².
Formula
y = X\beta + \varepsilon, \quad \varepsilon \sim (\mathbf{0},\, \sigma^2 I)OLS chooses β to minimize the residual sum of squares S(β) = (y − Xβ)ᵀ(y − Xβ), the total squared vertical distance between the observed values and those implied by a candidate β. Legendre (1805) introduced this criterion as a principle for fitting empirical data.
Formula
\hat{\beta} = \underset{\beta}{\arg\min}\; S(\beta) = \sum_{i=1}^{n}(y_i - x_i^\top \beta)^2 = (y - X\beta)^\top (y - X\beta)Setting the gradient of S(β) with respect to β equal to zero gives the normal equations XᵀXβ̂ = Xᵀy. These k simultaneous linear equations characterize the OLS solution. Gauss (1809) derived and solved them in the context of computing celestial orbits.
Formula
X^\top X\, \hat{\beta} = X^\top yWhen XᵀX is invertible, which holds when no predictor is an exact linear combination of the others, the OLS estimator is the unique solution β̂ = (XᵀX)⁻¹Xᵀy. Under the classical assumptions, the Gauss-Markov theorem states that this estimator is the Best Linear Unbiased Estimator of β, meaning it has the smallest variance among linear unbiased estimators.
Formula
\hat{\beta} = (X^\top X)^{-1} X^\top yAfter estimation, the fitted values ŷ = Xβ̂ and residuals ε̂ = y − ŷ are computed. The estimate of the error variance is σ̂² = ε̂ᵀε̂ / (n − k), where n − k is the residual degrees of freedom (n observations minus k estimated parameters). Residual diagnostics, such as residual plots, normality checks and heteroskedasticity tests, are based on ε̂.
Formula
\hat{y} = X\hat{\beta}, \quad \hat{\varepsilon} = y - \hat{y}, \quad \hat{\sigma}^2 = \dfrac{\hat{\varepsilon}^\top \hat{\varepsilon}}{n - k}The estimated covariance matrix of β̂ is σ̂²(XᵀX)⁻¹, and each coefficient's standard error is the square root of the corresponding diagonal element. Under the normality assumption for ε, the statistic t_j = β̂_j / SE(β̂_j) follows a t-distribution with n − k degrees of freedom and is used to test whether a predictor has a nonzero coefficient; this is the exact finite-sample result. Without normally distributed errors, the t-test and the F-test are approximate and rely on large-sample results. The omnibus F-test assesses the joint significance of the predictors.
Formula
\operatorname{Var}(\hat{\beta}) = \sigma^2 (X^\top X)^{-1}, \quad t_j = \dfrac{\hat{\beta}_j}{\operatorname{SE}(\hat{\beta}_j)} \sim t_{n-k}Common pitfalls
- Reporting conventional standard errors when residual spread varies with the fitted values. Heteroskedasticity-robust (White) standard errors correct the covariance estimate without changing β̂.
- Reading OLS coefficients as causal effects without checking exogeneity. A coefficient measures partial association in the fitted model, and a confounder or reverse causation can produce it even when no causal effect exists.
- Omitting a relevant predictor. If the omitted variable affects the outcome and is correlated with an included regressor, the coefficient on that regressor is biased and inconsistent (omitted variable bias).
- Using R² alone to judge fit. R² never decreases when a predictor is added, even an irrelevant one, and a high R² can coexist with a misspecified model.
- Skipping residual plots. Systematic patterns in the residuals, such as curvature or a funnel shape, indicate violated assumptions that the summary statistics do not reveal.
Frequently asked questions
What does the Gauss-Markov theorem actually guarantee?
Under five classical assumptions (linearity in the parameters, full-rank X, zero conditional mean errors, homoskedasticity, and uncorrelated errors), the Gauss-Markov theorem states that the OLS estimator has the smallest variance among all estimators that are linear in y and unbiased. This is the 'BLUE' property. It does not require normally distributed errors; normality is needed only for exact finite-sample t- and F-inference.
When should I use robust standard errors instead of conventional OLS standard errors?
When the homoskedasticity assumption is in doubt, that is, when the error variance may differ across observations, conventional OLS standard errors are invalid, although the coefficient estimates remain unbiased. Heteroskedasticity-robust (White) standard errors correct the covariance estimate without requiring a model for the variance. They are commonly reported as a precaution even when heteroskedasticity is not strongly suspected.
How is OLS different from Maximum Likelihood Estimation (MLE) for a linear model?
If the errors are independent and identically distributed as Normal(0, σ²), the OLS estimator of β is identical to the MLE. OLS does not need normality to produce the point estimates; normality is needed for exact small-sample distributional results. For non-normal error models, such as logistic or Poisson regression, MLE gives different estimating equations and generally requires iterative optimization rather than the OLS closed form.
What is the difference between OLS and Weighted Least Squares (WLS)?
OLS gives every observation equal weight. WLS minimizes Σwᵢ(yᵢ − xᵢᵀβ)² with a known weight wᵢ for each observation. WLS is efficient when the weights match the true error variance structure, for example when the error variances are known to differ proportionally across observations. If the weights are wrong or estimated poorly, the advantage over OLS is not guaranteed.
Related methods
Sources
Legendre, A.-M. (1805). Nouvelles méthodes pour la détermination des orbites des comètes. Firmin Didot, Paris. [Appendix: Sur la Méthode des moindres quarrés, pp. 72–80.]
Open publication referenceGauss, C. F. (1809). Theoria Motus Corporum Coelestium in Sectionibus Conicis Solem Ambientium. Perthes & Besser, Hamburg.
Open publication referenceWooldridge, J. M. (2019). Introductory Econometrics: A Modern Approach (7th ed.). Cengage Learning.
ISBN: 978-1337558860Greene, W. H. (2018). Econometric Analysis (8th ed.). Pearson.
ISBN: 978-0134461366