# What's the difference between the variance and the mean squared error?

I'm surprised this hasn't been asked before, but I cannot find the question on stats.stackexchange.

This is the formula to calculate the variance of a normally distributed sample:

$$\frac{\sum(X - \bar{X}) ^2}{n-1}$$

This is the formula to calculate the mean squared error of observations in a simple linear regression:

$$\frac{\sum(y_i - \hat{y}_i) ^2}{n-2}$$

What's the difference between these two formulas? The only difference I can see is that MSE uses $n-2$. So if that's the only difference, why not refer to them as both the variance, but with different degrees of freedom?

• Variance is the average of squared deviation of the observations from the mean. The MSE in contrast is the average of squared deviations of the predictions from the true values. – random_guy Mar 5 '15 at 19:38
• Both "variance" and "mean squared error" have multiple formulas and varying applications. To clarify your question, could you (a) describe what kind of data you are applying these concepts to and (b) give formulas for them? (It's likely that in so doing you will discover the answer to your question, too.) – whuber Mar 5 '15 at 19:41
• There's a more general formula, which both are special cases of: $\frac{\sum_i(y_i-\hat{y}_i)^2}{n-p}$ where $p$ is the number of parameters estimated in obtaining $\hat{y}$ – Glen_b Mar 6 '15 at 3:05

$$\frac{\sum_{i}^{n}(y_i - \hat{y}_i) ^2}{n-2} = \frac{\sum_{i}^{n}\left[y_i - \left(\hat{\beta}_{0} + \hat{\beta}_{x}x_{i}\right)\right] ^2}{n-2}$$
Notice that the numerator sums over a function of both $y$ and $x$, so you lose a degree of freedom for each variable, hence $n-2$. In the formula for the sample variance, the numerator is a function of a single variable, so you lose just one degree of freedom in the denominator.