ArticleslgStudy

mathematics

Ordinary least squares

Ordinary least squares is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Ordinary least squares rather than just read about it. In short: In statistics, ordinary least squares (OLS) is a type of linear least squares method for choosing the unknown parameters in a linear regression model by the principle of least squares: minimizing the sum of the squares of the differences between the observed dependent variable (values of the variable being observed) in the input dataset and the output of the (linear) function of the independent variable. Some source…

Ordinary least squares — main illustration
Ordinary least squares — illustration

Key takeaways

  • Ordinary least squares belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Ordinary least squares to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Ordinary least squares from memory before moving on to harder problems.

Reference excerpt

In statistics, ordinary least squares (OLS) is a type of linear least squares method for choosing the unknown parameters in a linear regression model by the principle of least squares: minimizing the sum of the squares of the differences between the observed dependent variable (values of the variable being observed) in the input dataset and the output of the (linear) function of the independent variable. Some sources consider OLS to be linear regression. Geometrically, this is seen as the sum of the squared distances, parallel to the axis of the dependent variable, between each data point in the set and the corresponding point on the regression surface—the smaller the differences, the better the model fits the data. The resulting estimator can be expressed by a simple formula, especially in the case of a simple linear regression, in which there is a single regressor on the right side of the regression equation. The OLS estimator is consistent for the level-one fixed effects when the regressors are exogenous and forms perfect colinearity (rank condition), consistent for the variance estimate of the residuals when regressors have finite fourth moments and—by the Gauss–Markov theorem—optimal in the class of linear unbiased estimators when the errors are homoscedastic and serially uncorrelated. Under these conditions, the method of OLS provides minimum-variance mean-unbiased estimation when the errors have finite variances. Under the additional assumption that the errors are normally distributed with zero mean, OLS is the maximum likelihood estimator that outperforms any non-linear unbiased estimator.

Linear model

Suppose the data consists of n observations {𝐱i,yi}i=1n. Each observation i includes a scalar response yi and a column vector 𝐱i of p parameters (regressors), i.e., 𝐱i=[xi1,xi2,…,xip]T. In a linear regression model, the response variable, yi, is a linear function of the regressors:

yi=β1 xi1+β2 xi2+⋯+βp xip+εi, or in vector form,

yi=𝐱iT𝜷+εi, where 𝐱i, as introduced previously, is a column vector of the i-th observation of all the explanatory variables; 𝜷 is a p×1 vector of unknown parameters; and the scalar εi represents unobserved random variables (errors) of the i-th observation. εi accounts for the influences upon the responses yi from sources other than the explanatory variables 𝐱i. This model can also be written in matrix notation as

𝐲=𝐗𝜷+𝜺, where 𝐲 and 𝜺 are n×1 vectors of the response variables and the errors of the n observations, and 𝐗 is an n×p matrix of regressors, also sometimes called the design matrix, whose row i is 𝐱iT and contains the i-th observations on all the explanatory variables. Typically, a constant term is included in the set of regressors 𝐗, say, by taking xi1=1 for all i=1,…,n. The coefficient β1 corresponding to this regressor is called the intercept. Without the intercept, the fitted line is forced to cross the origin when 𝐱i=0→. Regressors do not have to be independent for estimation to be consistent; for example, they may be non-linearly dependent. Short of perfect multicollinearity, parameter estimates may still be consistent; however, as multicollinearity increases the standard errors of such estimates increase, reducing their precision. When there is perfect multicollinearity, it is no longer possible to obtain unique estimates for the coefficients of the related regressors; estimation of these parameters cannot converge and therefore cannot be consistent. As a concrete example in which regressors are nonlinearly dependent yet estimation may still be consistent, we might suspect that the response depends linearly on both a value and its square; in that case, we would include one regressor whose value is the square of another regressor. The model would then be quadratic in the second regressor but would still be considered a linear model because it remains linear in the parameters (𝜷).

Matrix/vector formulation Consider an overdetermined system

∑j=1pxijβj=yi, (i=1,2,…,n), of n linear equations in p unknown coefficients, β1,β2,…,βp, with n>p. This can be written in matrix form as

𝐗𝜷=𝐲, where

𝐗=[X11X12⋯X1pX21X22⋯X2p⋮⋮⋱⋮Xn1Xn2⋯Xnp],𝜷=[β1β2⋮βp],𝐲=[y1y2⋮yn]. (Note: for a linear model as above, not all elements in 𝐗 contain information on the data points. The first column is populated with ones, Xi1=1. Only the other columns contain actual data. So here p is equal to the number of regressors plus one). Such a system usually has no exact solution, so the goal is instead to find the coefficients 𝜷 which fit the equations "best", in the sense of solving the quadratic minimization problem

𝜷̂=argmin𝜷S(𝜷), where the objective function S is given by: S(𝜷)=∑i=1n|yi−∑j=1pXijβj|2=‖𝐲−𝐗𝜷‖2. A justification for choosing this criterion is given in Properties below. This minimization problem has a unique solution, provided that the p columns of the matrix 𝐗 are linearly independent, given by solving the so-called normal equations:

(𝐗T𝐗)𝜷̂=𝐗T𝐲 . The matrix 𝐗T𝐗 is known as the normal matrix or Gram matrix and the matrix 𝐗T𝐲 is known as the moment matrix of regressand by regressors. Finally, 𝜷̂ is the coefficient vector of the least-squares hyperplane, expressed as

𝜷̂=(𝐗⊤𝐗)−1𝐗⊤𝐲. or

𝜷̂=𝜷+(𝐗⊤𝐗)−1𝐗⊤𝜺.

Estimation Suppose b is a "candidate" value for the parameter vector β. The quantity yi − xiTb, called the residual for the i-th observation, measures the vertical distance between the data point (xi, yi) and the hyperplane y = xTb, and thus assesses the degree of fit between the actual data and the model. The sum of squared residuals (SSR) (also called the error sum of squares (ESS) or residual sum of squares (RSS)) is a measure of the overall model fit:

S(b)=∑i=1n(yi−xiTb)2=(y−Xb)T(y−Xb), where T denotes the matrix transpose, and the rows of X, denoting the values of all the independent variables associated with a particular value of the dependent variable, are Xi = xiT. The value of b which minimizes this sum is called the OLS estimator for β. The function S(b) is quadratic in b with positive-definite Hessian, and therefore this function possesses a unique global minimum at b=β̂, which can be given by the explicit formula[proof]

… excerpt ends here. Continue reading the full article.

Illustrations

Ordinary least squares: Okun's law in macroeconomics states that in an economy the GDP growth should depend linearly on the changes in the unemployment rate. Here the ordinary least squares method is used to construct the regression line describing this law.
Okun's law in macroeconomics states that in an economy the GDP growth should depend linearly on the changes in the unemployment rate. Here the ordinary least squares method is used to construct the regression line describing this law.
Ordinary least squares: OLS estimation can be viewed as a projection onto the linear space spanned by the regressors. (Here each of X1 and X2 refers to a column of the data matrix.)
OLS estimation can be viewed as a projection onto the linear space spanned by the regressors. (Here each of X1 and X2 refers to a column of the data matrix.)
Ordinary least squares: Least squares as projection of y onto col(X) for three observations; ŷ = Xβ gives fitted values and y − ŷ is the residual.
Least squares as projection of y onto col(X) for three observations; ŷ = Xβ gives fitted values and y − ŷ is the residual.
Ordinary least squares: Example of a cubic polynomial regression, which is a type of linear regression. Although polynomial regression fits a curve model to the data, as a statistical estimation problem it is linear, in the sense that the conditional expectation function 𝔼[y|x] is linear in the unknown parameters that are estimated from the data. For this reason, polynomial regression is considered to be a special case of multiple linear regression.
Example of a cubic polynomial regression, which is a type of linear regression. Although polynomial regression fits a curve model to the data, as a statistical estimation problem it is linear, in the sense that the conditional expectation function 𝔼[y|x] is linear in the unknown parameters that are estimated from the data. For this reason, polynomial regression is considered to be a special case of multiple linear regression.
Ordinary least squares: Visualization of heteroscedasticity in a scatter plot against 100 random fitted values using Matlab
Visualization of heteroscedasticity in a scatter plot against 100 random fitted values using Matlab

Worked examples

Example 1 — a first encounter with Ordinary least squares

Start with the simplest possible case. Write down what Ordinary least squares claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Ordinary least squares before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Ordinary least squares ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Ordinary least squares

In research
Ordinary least squares appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Ordinary least squares in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Ordinary least squares is common in secondary-school and first-year university syllabi. It links to neighbouring topics Least squares, Parametric statistics, so understanding it makes those chapters shorter.
In everyday life
Look for Ordinary least squares outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Ordinary least squares” →

How to study Ordinary least squares in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Ordinary least squares means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Ordinary least squares out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Ordinary least squares in simple terms?

In statistics, ordinary least squares (OLS) is a type of linear least squares method for choosing the unknown parameters in a linear regression model by the principle of least squares: minimizing the sum of the squares of the differences between the observed dependent variable (values of the variab…

Why does Ordinary least squares matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Ordinary least squares?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Ordinary least squares.

Tags

  • Least squares
  • Parametric statistics

Keep exploring