Estimating the Mean Square Error, MSE
In linear regression, we are modeling the dependent variable using this model:
Y = β0 + β1X + ε
Here, Y is the dependent variable, X is the independent variable, β0 is the expected value of Y when X = 0 in the population, β1 is the effect of X on Y in the population, and ε is random variation unexplained by the model.
To perform statistical inference, we make the usual assumption that
ε ~ Normal(0, σ²)
The mean square error is an estimate of that σ². It is also a measure of the variance unexplained by the model and data. There are different methods for estimating this value. Ordinary least squares is one method. Its strengths are that it is easy to perform, it is exact, and that it is straight forward to create the estimators.
The Problem
Example #711: Let us model (explain) the weight of a leaf using its thickness. To explore this, we collect data. The data consist of two measurements on each unit (leaf): thickness and weight. Thus, our data are
Data table
Leaf Number | Thickness [μm] | Weight [g] |
1 | 5.5 | 0.9 |
2 | 4.9 | 1.1 |
3 | 6.8 | 0.7 |
4 | 5.2 | 0.8 |
5 | 5.7 | 3 |
6 | 7 | -1.7 |
7 | 3.6 | 3.5 |
8 | 6.2 | 0.1 |
9 | 4.4 | 2.7 |
10 | 5.9 | 1.2 |
With this information, we estimated the linear model to be
weight = 7.5086 + (-1.1374) thickness
What is the mean square error?
Information given:
To summarize the above, the values of import are:
Summary statistics from the problem
\( \bar{x} \)
| = |
5.52 |
\( \bar{y} \)
| = |
1.23 |
\( b_0 \)
| = |
7.5086 |
\( b_1 \)
| = |
-1.1374 |
Note that \( b_0 \) is important in estimating the y-intercept. If you are unsure how to calculate it, or if you would like more practice doing so, please see the OLS estimate of the y-intercept tutorial.
Note also that \( b_1 \) is important in estimating the mean square error. If you are unsure how to calculate it, or if you would like more practice doing so, please see the OLS estimate of the slope tutorial.
Your Answer
You got the correct answer of b1 = 1.0123. Congratulations!
Unfortunately, your answer was not correct. Either try again or click on “Show Solution” below to see how to obtain the correct answer.
Assistance
Hide Solution
$$ \begin{align}
MSE &= \frac{1}{n-2}\ \sum_{i=1}^n (y_i - b_0 - b_1 x_i)^2 \\[3em]
&= \frac{1}{10-2}\ \sum_{i=1}^10 \Big(y_i - 7.5086 - (-1.1374) x_i\Big)^2 \\[1em]
&= \frac{1}{8}\ \sum_{i=1}^10 \Big(y_i - 7.5086 - (-1.1374) x_i\Big)^2 \\[1em]
&= \frac{1}{8}\ \Big[
\Big(0.9 - 7.5086 - (-1.1374)5.5\Big)^2 + \Big(1.1 - 7.5086 - (-1.1374)4.9\Big)^2 + \Big(0.7 - 7.5086 - (-1.1374)6.8\Big)^2 + \Big(0.8 - 7.5086 - (-1.1374)5.2\Big)^2 + \Big(3 - 7.5086 - (-1.1374)5.7\Big)^2 + \Big(-1.7 - 7.5086 - (-1.1374)7\Big)^2 + \Big(3.5 - 7.5086 - (-1.1374)3.6\Big)^2 + \Big(0.1 - 7.5086 - (-1.1374)6.2\Big)^2 + \Big(2.7 - 7.5086 - (-1.1374)4.4\Big)^2 + \Big(1.2 - 7.5086 - (-1.1374)5.9\Big)^2 \Big] \\[1em]
&= \frac{1}{8}\ \Big[
\Big(0.9 - 7.5086 - (-6.2559\Big)^2 + \Big(1.1 - 7.5086 - (-5.5734\Big)^2 + \Big(0.7 - 7.5086 - (-7.7345\Big)^2 + \Big(0.8 - 7.5086 - (-5.9146\Big)^2 + \Big(3 - 7.5086 - (-6.4833\Big)^2 + \Big(-1.7 - 7.5086 - (-7.962\Big)^2 + \Big(3.5 - 7.5086 - (-4.0947\Big)^2 + \Big(0.1 - 7.5086 - (-7.0521\Big)^2 + \Big(2.7 - 7.5086 - (-5.0047\Big)^2 + \Big(1.2 - 7.5086 - (-6.7108\Big)^2 \Big] \\[1em]
&= \frac{1}{8}\ \Big[
\Big(-0.3527\Big)^2 + \Big(-0.8352\Big)^2 + \Big(0.9259\Big)^2 + \Big(-0.794\Big)^2 + \Big(1.9747\Big)^2 + \Big(-1.2466\Big)^2 + \Big(0.0861\Big)^2 + \Big(-0.3565\Big)^2 + \Big(0.1961\Big)^2 + \Big(0.4022\Big)^2 \Big] \\[1em]
&= \frac{1}{8}\ \Big[
\Big(0.1244\Big) + \Big(0.6976\Big) + \Big(0.8573\Big) + \Big(0.6304\Big) + \Big(3.8996\Big) + \Big(1.554\Big) + \Big(0.0074\Big) + \Big(0.1271\Big) + \Big(0.0384\Big) + \Big(0.1618\Big) \Big] \\[1em]
&= \frac{1}{8}\ 8.0981 \\[1em]
&= 1.0123 \\[1em]
\end{align}
$$
For these data, the mean squared error is MSE = 1.0123. This is the point estimate for the value of σ² in the model.
Hide the R Code
Copy and paste the following code into your R script window, then run it from there.
## Import data
thickness = c( 5.5, 4.9, 6.8, 5.2, 5.7, 7, 3.6, 6.2, 4.4, 5.9 )
weight = c( 0.9, 1.1, 0.7, 0.8, 3, -1.7, 3.5, 0.1, 2.7, 1.2 )
## Model the data
mod = lm(weight~thickness)
summary(mod)
In the R output, you have the typical regression table. The mean square error (MSE) is not on the table. It is a component of many parts of the table, but it is not explicitly there. To obtain the MSE, these two lines must also be run:
n=length(thickness)
sum(residuals(mod)^2)/(n-2)
Here, the number outputted is the mean square error. Note that the penultimate line determines the sample size. The final line calculates the residuals, squares them, sums the squares, then divides by n − 2... all in one line!