# Calculate MSE for random forest in R using package 'randomForest'

I'm using randomForest to fit a model with continuous response variable. I was reading the An Introduction to Statistical Learning: with Applications in R (Springer Texts in Statistics), in Chapter 8, section 8.3.3 Bagging and Random Forests, it uses the following example:

I followed the exact same command and got the following result:

The MSE from summary is 14.5. The textbook then used the following formula to calculate MSE in test set:

Instead of the test set, I used this formula to calculate the MSE for the training set (the set I used to obtain the model), and here's my code:

However, as you can see, the outcome is way different from the result from summary statistics. I'm not sure why this happens, and which one is the correct MSE, and if I want to use MSE to compare to compare with other models, which MSE should I use?