# Mean squared prediction error

In statistics the mean squared prediction error or mean squared error of the predictions of a smoothing or curve fitting procedure is the expected value of the squared difference between the fitted values implied by the predictive function ${\displaystyle {\widehat {g}}}$ and the values of the (unobservable) function g. It is an inverse measure of the explanatory power of ${\displaystyle {\widehat {g}},}$ and can be used in the process of cross-validation of an estimated model.

If the smoothing or fitting procedure has projection matrix (i.e., hat matrix) L, which maps the observed values vector ${\displaystyle y}$ to predicted values vector ${\displaystyle {\hat {y}}}$ via ${\displaystyle {\hat {y}}=Ly,}$ then

${\displaystyle \operatorname {MSPE} (L)=\operatorname {E} \left[\left(g(x_{i})-{\widehat {g}}(x_{i})\right)^{2}\right].}$

The MSPE can be decomposed into two terms: the mean of squared biases of the fitted values and the mean of variances of the fitted values:

${\displaystyle n\cdot \operatorname {MSPE} (L)=\sum _{i=1}^{n}\left(\operatorname {E} \left[{\widehat {g}}(x_{i})\right]-g(x_{i})\right)^{2}+\sum _{i=1}^{n}\operatorname {var} \left[{\widehat {g}}(x_{i})\right].}$

Knowledge of g is required in order to calculate the MSPE exactly; otherwise, it can be estimated.

## Computation of MSPE over out-of-sample data

The mean squared prediction error can be computed exactly in two contexts. First, with a data sample of length n, the data analyst may run the regression over only q of the data points (with q < n), holding back the other n – q data points with the specific purpose of using them to compute the estimated model’s MSPE out of sample (i.e., not using data that were used in the model estimation process). Since the regression process is tailored to the q in-sample points, normally the in-sample MSPE will be smaller than the out-of-sample one computed over the n – q held-back points. If the increase in the MSPE out of sample compared to in sample is relatively slight, that results in the model being viewed favorably. And if two models are to be compared, the one with the lower MSPE over the n – q out-of-sample data points is viewed more favorably, regardless of the models’ relative in-sample performances. The out-of-sample MSPE in this context is exact for the out-of-sample data points that it was computed over, but is merely an estimate of the model’s MSPE for the mostly unobserved population from which the data were drawn.

Second, as time goes on more data may become available to the data analyst, and then the MSPE can be computed over these new data.

## Estimation of MSPE over the population

When the model has been estimated over all available data with none held back, the MSPE of the model over the entire population of mostly unobserved data can be estimated as follows.

For the model ${\displaystyle y_{i}=g(x_{i})+\sigma \varepsilon _{i}}$ where ${\displaystyle \varepsilon _{i}\sim {\mathcal {N}}(0,1)}$, one may write

${\displaystyle n\cdot \operatorname {MSPE} (L)=g^{\text{T}}(I-L)^{\text{T}}(I-L)g+\sigma ^{2}\operatorname {tr} \left[L^{\text{T}}L\right].}$

Using in-sample data values, the first term on the right side is equivalent to

${\displaystyle \sum _{i=1}^{n}\left(\operatorname {E} \left[g(x_{i})-{\widehat {g}}(x_{i})\right]\right)^{2}=\operatorname {E} \left[\sum _{i=1}^{n}\left(y_{i}-{\widehat {g}}(x_{i})\right)^{2}\right]-\sigma ^{2}\operatorname {tr} \left[\left(I-L\right)^{T}\left(I-L\right)\right].}$

Thus,

${\displaystyle n\cdot \operatorname {MSPE} (L)=\operatorname {E} \left[\sum _{i=1}^{n}\left(y_{i}-{\widehat {g}}(x_{i})\right)^{2}\right]-\sigma ^{2}\left(n-\operatorname {tr} \left[L\right]\right).}$

If ${\displaystyle \sigma ^{2}}$ is known or well-estimated by ${\displaystyle {\widehat {\sigma }}^{2}}$, it becomes possible to estimate MSPE by

${\displaystyle n\cdot \operatorname {\widehat {MSPE}} (L)=\sum _{i=1}^{n}\left(y_{i}-{\widehat {g}}(x_{i})\right)^{2}-{\widehat {\sigma }}^{2}\left(n-\operatorname {tr} \left[L\right]\right).}$

Colin Mallows advocated this method in the construction of his model selection statistic Cp, which is a normalized version of the estimated MSPE:

${\displaystyle C_{p}={\frac {\sum _{i=1}^{n}\left(y_{i}-{\widehat {g}}(x_{i})\right)^{2}}{{\widehat {\sigma }}^{2}}}-n+2p.}$

where p the number of estimated parameters p and ${\displaystyle {\widehat {\sigma }}^{2}}$ is computed from the version of the model that includes all possible regressors.