## Formulas of MSE and RSS

Residual Sum of Squares (RSS) is the numerator in the formula of Mean Squared Error (MSE). That is, RSS is part of MSE formula.

\[ SSR=\sum_{i=1}^{n} (\hat{y_i}-y_i)^2 \]

\[ MSE=\frac{SSR}{n-p-1}=\frac{\sum_{i=1}^{n} (\hat{y_i}-y_i)^2 }{n-p-1}\]

where,

\( n \) is the number of observations.

\( \hat{y_i} \) is is estimated value.

\( y_i \) is observed value.

\( p \) is the is the number of estimated parameters (excluding the intercept).

## Relationship between MSE and RSS

Thus, RSS is the sum of the squares of **residuals**. Building on RSS, MSE takes the number of observation (i.e., \( n\) ) into consideration. That is, MSE is “mean” of squared **errors** (estimated by squared **residuals**).

Why do we use \( n-p-1 \) rather than \( n\) as the denominator in the formula of MSE? It is because \( n\) leads to a biased estimate of MSE, whereas \( n-p-1 \) leads to an unbiased estimate of MSE. (See the discussion here on Wikipedia.)

## Further Reading

- Difference between Mean Squared Residuals (MSR) and Mean Square Error (MSE)
- Difference between MSD and MSE
- Calculate Sum of Squared Residuals (SSR) in R (R, Python)
- Use sklearn to Calculate SSR in Python
- Calculate Mean Squared Residuals (MSR) in R (R, Python)
- Calculate Mean Squared Error (MSE) (R, Python)
- How to Calculate Mean Squared Deviation in R