In parametric statistics, the least-squares estimator is often used to estimate the coefficients of a linear regression. The least-squares estimator optimizes a certain criterion (namely it minimizes the sum of the square of the residuals). In this article, after setting the mathematical context of linear regression, we will motivate the use of the least-squares estimator
and derive its expression (as seen for example in the article regression analysis):

We conclude by giving some qualities of this estimator and a geometrical interpretation.
Assumptions
For
, let Y be a random variable taking values in
, we call observation.
We next define the function η, linear in
:
where
- For
,
is a random variable taking values in
and is called a factor and
is a scalar, for
, and
, where
denotes the transpose of vector
.
Let
. We can write
. Define the error to be:
We suppose that there exists a true parameter
such that
. This means that, given the random variables
, the best prediction we can make of Y is
. Henceforth,
will denote
and η will represent
.
Least-squares estimator
The idea behind the least-squares estimator is to see linear regression as an orthogonal projection. Let F be the L2-space of all random variables whose square has a finite Lebesgue integral. Let G be the linear subspace of
generated by
(supposing that
and
). We show in this paragraph that the function
is an orthogonal projection of Y on G and we will construct the least-squares estimator.
Seeing linear regression as an orthogonal projection
We have
, but
is a projection, which means that
is a projection of Y on G. What is more, this projection is an orthogonal one.
To see this, we can build a scalar product in F: for all couples of random variables
, we define
. It is indeed a scalar product because if
, then
almost everywhere (where
is the norm corresponding to this scalar product).
For all
,
|
|
|
|
|
|
|
|
|
|
|
|
Therefore,
is orthogonal to any
and hence to the whole of the subspace G, which means that
is a projection of Y on G, orthogonal with respect to the scalar product we have just defined. We have therefore shown:
Estimating the coefficients
If, for each
we have a sample of size
of
, along with a vector
of n observations of Y, we can build an estimation of the coefficients of this orthogonal projection. To do this, we can use an estimation of the scalar product defined earlier.
For all couples of samples of size n
of random variables U and V, we define
, where
is the transpose of vector
, and
. Note that the scalar product
is defined in
and no longer in F.
Let us define the design matrix (or random design), a
random matrix:
We can now adapt the minimization of the sum of the residuals: the least-squares estimator
will be the value, if it exists, of
which minimizes
. Therefore,
.
This yields
. If
is of full rank, then so is
. In that case we can compute the least-squares estimator explicitly by inverting the
matrix
:
Qualities and geometrical interpretation
Qualities of this estimator
Not only is the least-square estimator easy to compute, but under the Gauss-Markov assumptions, the Gauss-Markov theorem states that the least-square estimators is the best linear unbiased estimator (BLUE) of
.
The vector of errors
is said to fulfil the Gauss-Markov assumptions if:

(uncorrelated but not necessarily independent; homoscedastic but not necessarily identically distributed)
where
and
is the
identity matrix.
This decisive advantage has lead to a sometimes abusive use of least-squares. Least-squares depends on the fulfilment of the Gauss-Markov hypothesis and applying this method in a situation where these conditions are not met can lead to inaccurate results. For example, in the study of time-series, it is often difficult to assume independence of the residuals.
Geometrical interpretation
The situation described by the linear regression problem can be geometrically seen as follows:
The least-squares is also an M-estimator of
-type for
.