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.




![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.](https://thumb.wikimedia.org/wikipedia/commons/thumb/8/8b/Polyreg_scheffe.svg/500px-Polyreg_scheffe.svg.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)
