Written and maintained by CASRAI Editorial Board
Last updated
The Mean Squared Error (MSE) formula measures the average squared difference between observed empirical outcomes and the values predicted by a statistical model. Researchers and analysts use MSE to assess model fit, optimize algorithms, compute test statistics in ANOVA (Analysis of Variance), and evaluate estimation risk under the bias-variance tradeoff.
Definition in One Paragraph
Mean Squared Error (MSE) is a statistical loss function that quantifies the average squared deviation between predicted values and observed outcomes. By squaring each residual before averaging, MSE yields strictly non-negative values and penalizes large errors more heavily than small discrepancies, while preventing positive and negative errors from canceling each other out.
Formula for MSE with Every Symbol Explained
The formula for MSE appears in three distinct research contexts: empirical model evaluation, inferential regression modeling, and theoretical estimator analysis.
1. Predictive and Machine Learning Formula
When evaluating predictions across an empirical sample of n observations, sample Mean Squared Error equals the sum of squared errors (SSE) divided by sample size:
MSE = (1 / n) ∑i=1n (yi − ŷi)2
- MSE: Mean Squared Error, expressed in the squared units of the target variable.
- n: Number of sample observations evaluated.
- ∑i=1n: Summation operator across index i = 1 through n.
- yi: Observed empirical value for observation i.
- ŷi (y-hat): Model prediction for observation i.
- (yi − ŷi): Raw prediction error or residual (ei).
- (yi − ŷi)2: Squared residual for observation i.
2. Inferential Regression and ANOVA Formula
In linear regression and experimental ANOVA designs, dividing residual sum of squares by n underestimates population variance. To obtain an unbiased estimator of error variance (σ2), residuals are divided by residual degrees of freedom (DFE = n − p):
MSE = SSE / (n − p) = [∑i=1n (yi − ŷi)2] / (n − p)
- SSE: Sum of Squared Errors (residual sum of squares).
- p: Number of parameters estimated (for simple regression with intercept and slope, p = 2; for multiple regression with k predictors, p = k + 1).
- n − p: Degrees of freedom for error (DFE).
In ANOVA tables, this value is reported as the Mean Square Error (MSResidual) and forms the denominator for F-tests.
3. Estimator Risk and the Bias-Variance Decomposition
In theoretical estimation, the MSE of an estimator θ̂ relative to parameter θ equals the sum of variance and squared bias:
MSE(θ̂) = E[(θ̂ − θ)2] = Var(θ̂) + [Bias(θ̂, θ)]2
- E[·]: Expected value operator across repeated sampling.
- Var(θ̂): Estimator variance, reflecting stability across samples.
- Bias(θ̂, θ): E[θ̂] − θ, representing systematic error.
This relationship is fundamental in regularization methods like Ridge vs LASSO Regression, which introduce slight bias to sharply decrease variance, minimizing overall MSE.
Worked Example with Step-by-Step Arithmetic
Consider a validation dataset of n = 5 observations where researchers evaluate laboratory assay predictions (ŷ) against actual measurements (y):
| Observation (i) | Actual Value (yi) | Predicted Value (ŷi) | Error (ei = yi − ŷi) | Squared Error (ei2) |
|---|---|---|---|---|
| 1 | 12.0 | 10.0 | +2.0 | 4.00 |
| 2 | 15.0 | 16.0 | −1.0 | 1.00 |
| 3 | 18.0 | 15.0 | +3.0 | 9.00 |
| 4 | 20.0 | 22.0 | −2.0 | 4.00 |
| 5 | 25.0 | 24.0 | +1.0 | 1.00 |
| Total | 90.0 | 87.0 | +3.0 | SSE = 19.00 |
Compute the metric across four steps:
- Calculate residuals: Subtract predicted values from actuals (e.g., 12.0 − 10.0 = +2.0).
- Square each residual: Eliminates signs and weights larger errors (e.g., 2.02 = 4.00; 3.02 = 9.00).
- Sum squared errors: SSE = 4.00 + 1.00 + 9.00 + 4.00 + 1.00 = 19.00.
- Divide by sample size or degrees of freedom:
- Sample / ML MSE: 19.00 / 5 = 3.80.
- Regression MSE (with p = 2 parameters): 19.00 / (5 − 2) = 6.33.
- Root Mean Squared Error (RMSE): √3.80 = 1.95 units.
Interpretation: What the Result Means
An MSE of 3.80 indicates that the average squared distance from observations to predictions is 3.80 squared units. Because units are squared, analysts compute RMSE (√3.80 = 1.95) to assess error on the original measurement scale. Lower MSE values reflect closer predictive fit, with 0 denoting zero residual discrepancy.
| Metric | Formula | Scale | Outlier Sensitivity | Primary Use Case |
|---|---|---|---|---|
| MSE | (1 / n) ∑ (yi − ŷi)2 | Squared units | Very high (quadratic) | Mathematical gradient optimization, ANOVA error variance |
| RMSE | √[(1 / n) ∑ (yi − ŷi)2] | Original units | High (quadratic weighting) | Reporting model fit where large errors are particularly costly |
| MAE | (1 / n) ∑ |yi − ŷi| | Original units | Linear (robust) | Audience reporting, datasets containing unvetted outliers |
Assumptions and Common Mistakes
When applying the MSE formula, researchers should guard against five common analytical errors:
- Ignoring Degrees of Freedom: Dividing by n instead of n − p in regression artificially deflates error variance estimates, inflating Type I error in hypothesis tests.
- Cross-Dataset Comparisons: MSE is scale-dependent. An MSE of 0.2 on blood pH may indicate substantial error, while an MSE of 100 on annual revenue reflects high accuracy. Compare MSE only across models fitted to identical data.
- Conflating MSE with Residual Variance: In models without an intercept or with non-zero mean residuals, MSE measures dispersion around zero, not dispersion around the residual mean. Where heteroscedasticity exists, analysts use Weighted Least Squares.
- Outlier Sensitivity: Squaring residuals makes MSE vulnerable to extreme values. A single extreme anomaly can distort model selection unless verified through residual diagnostics.
- Confusing MSE with SEM: Analysts occasionally conflate MSE with the Standard Error of the Mean (SEM). SEM measures the sampling variability of sample means, whereas MSE measures individual prediction residuals.
How to Report It (APA Format)
Under APA 7th Edition rules, statistical symbols for test statistics and fit metrics are italicized (F, p, R2, MSE). In empirical reports, summarize omnibus model fit including degrees of freedom and error terms.
Regression Model Fit Example
“A multiple linear regression analysis was conducted to predict participant recovery time from age and baseline biomarker concentration. The overall model explained a significant proportion of variance, F(2, 47) = 14.82, p < .001, R2 = .387, with an overall mean square error of MSE = 6.33 (RMSE = 2.52 days).”
ANOVA Table Example
“The one-way analysis of variance revealed a statistically significant difference in treatment efficacy between cohorts, F(2, 27) = 4.82, p = .016, MSE = 12.45, ηp2 = .26.”
When reporting higher-order models such as Quadratic Regression Analysis, report the incremental change in R2 alongside reductions in MSE.
How to Calculate MSE in Excel, R, and Python
Researchers can compute MSE easily using verified recipes across common platforms.
1. Excel Formula
With actual observations in A2:A6 and predictions in B2:B6:
- Array Formula: Enter
=SUMSQ(A2:A6 - B2:B6) / COUNT(A2:A6). In modern Excel (365 and 2021), this executes as a dynamic array; in earlier versions, press Ctrl+Shift+Enter. - Helper Column: In cell
C2, enter=(A2 - B2)^2and copy down throughC6. Then calculate=AVERAGE(C2:C6)for sample MSE, or=SUM(C2:C6) / (COUNT(A2:A6) - 2)for regression MSE with two parameters. - RMSE: Wrap the expression in
SQRT():=SQRT(SUMSQ(A2:A6 - B2:B6) / COUNT(A2:A6)).
2. R Code Snippet
# Vectors of observed and predicted values
y <- c(12.0, 15.0, 18.0, 20.0, 25.0)
y_hat <- c(10.0, 16.0, 15.0, 22.0, 24.0)
# 1. Predictive Sample MSE and RMSE
mse_sample <- mean((y - y_hat)^2)
rmse_sample <- sqrt(mse_sample)
cat(sprintf("Sample MSE: %.2f | Sample RMSE: %.2fn", mse_sample, rmse_sample))
# 2. Extract Inferential Regression MSE from Linear Model
model <- lm(y ~ y_hat)
model_anova <- anova(model)
mse_residual <- model_anova["Residuals", "Mean Sq"]
cat(sprintf("Regression Residual MSE: %.2fn", mse_residual))
3. Python Code Snippet
import numpy as np
from sklearn.metrics import mean_squared_error, root_mean_squared_error
# Ground truth and predicted arrays
y_true = np.array([12.0, 15.0, 18.0, 20.0, 25.0])
y_pred = np.array([10.0, 16.0, 15.0, 22.0, 24.0])
# Compute Mean Squared Error (MSE)
mse = mean_squared_error(y_true, y_pred)
# Compute Root Mean Squared Error (RMSE)
# Note: squared=False is deprecated in scikit-learn 1.4+ in favor of root_mean_squared_error
rmse = root_mean_squared_error(y_true, y_pred)
print(f"MSE: {mse:.2f}")
print(f"RMSE: {rmse:.2f}")
Frequently Asked Questions
Is a higher or lower MSE better?
A lower MSE is always better. Because Mean Squared Error measures average squared deviation between model predictions and observed data, smaller values indicate that predictions lie closer to actual observations. An MSE of zero represents a perfect mathematical fit with no residual error.
What is the formula for MSE in Excel?
The standard Excel formula for MSE across actual values in A2:A6 and predictions in B2:B6 is =SUMSQ(A2:A6 - B2:B6) / COUNT(A2:A6). Alternatively, compute squared differences in column C using =(A2 - B2)^2 and average them with =AVERAGE(C2:C6).
What are the formulas for calculating MSE and RMSE?
The formula for Mean Squared Error across n observations is MSE = (1 / n) ∑i=1n (yi − ŷi)2. The formula for Root Mean Squared Error is the square root of MSE: RMSE = √MSE = √[(1 / n) ∑i=1n (yi − ŷi)2], which expresses prediction error in original measurement units.
What is a good MSE value?
There is no single numerical threshold for a good MSE because MSE is entirely scale-dependent. In astronomy or national economics, an MSE of 1,000 might indicate high precision, while in micro-pipetting, an MSE of 0.1 could be unacceptable. To evaluate an MSE value, compare it against a baseline mean model, verify that it is lower than the target variance Var(y), and evaluate it against competing models on the same test dataset.
Sources
- National Institute of Standards and Technology. (2012). NIST/SEMATECH e-Handbook of Statistical Methods. Section 6.4.2: What are Moving Average or Smoothing Techniques? U.S. Department of Commerce. Retrieved November 7, 2026, from https://www.itl.nist.gov/div898/handbook/pmc/section4/pmc42.htm
- Scikit-learn Developers. (2024). sklearn.metrics.mean_squared_error API Reference. Scikit-learn Documentation. Retrieved November 7, 2026, from https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html
- American Psychological Association. (2020). Publication Manual of the American Psychological Association (7th ed.). Section 6.43: Reporting Statistical Results in Psychology. American Psychological Association.







