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 {\displaystyle n} observations { x i , y i } i = 1 n {\displaystyle \left\{\mathbf {x} _{i},y_{i}\right\}_{i=1}^{n}} . Each observation i {\displaystyle i} includes a scalar response y i {\displaystyle y_{i}} and a column vector x i {\displaystyle \mathbf {x} _{i}} of p {\displaystyle p} parameters (regressors), i.e., x i = [ x i 1 , x i 2 , … , x i p ] T {\displaystyle \mathbf {x} _{i}=\left[x_{i1},x_{i2},\dots ,x_{ip}\right]^{\operatorname {T} }} . In a linear regression model, the response variable, y i {\displaystyle y_{i}} , is a linear function of the regressors:
y i = β 1 x i 1 + β 2 x i 2 + ⋯ + β p x i p + ε i , {\displaystyle y_{i}=\beta _{1}\ x_{i1}+\beta _{2}\ x_{i2}+\cdots +\beta _{p}\ x_{ip}+\varepsilon _{i},}
or in vector form,
y i = x i T β + ε i , {\displaystyle y_{i}=\mathbf {x} _{i}^{\operatorname {T} }{\boldsymbol {\beta }}+\varepsilon _{i},\,}
… 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
E
[
y
|
x
]
{\displaystyle \mathbb {E} [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://upload.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)

