Tutorials › Regression Analysis (Undergraduate) › A Worked Root Mean Squared Error Calculation

Prediction Metrics and Calibration · Tutorial 771 of 991

A Worked Root Mean Squared Error Calculation

Learn to calculate RMSE accurately from observed outcomes and predictions, and explain what its value says in context.

Intermediate 9 min read

What You'll Learn

  • Set up a case-by-case table of observed outcomes, predictions, errors, absolute errors, and squared errors.
  • Calculate mean squared error and take its square root to obtain RMSE.
  • Keep track of units through each step of the calculation.
  • Explain why an RMSE value does not mean every prediction misses by that amount.
  • Avoid confusing prediction RMSE with a training residual summary that uses a degrees-of-freedom adjustment.

From Individual Prediction Errors to RMSE

A prediction metric summarizes how far a model’s predictions are from the outcomes that were actually observed. Root mean squared error, usually abbreviated RMSE, makes this summary in two stages: it squares each prediction error, averages the squared errors, and then takes the square root. Carrying out those steps case by case helps prevent sign errors and makes clear how the final number relates to the prediction errors.

For this calculation, suppose there are \(n\) matched pairs: an observed outcome \(y_i\) and a prediction \(\hat{y}_i\) for the same case \(i\). The outcomes and predictions must use the same measurement scale. For example, an observed waiting time in minutes must be compared with a prediction in minutes, not with a prediction in hours. We will define the signed difference as prediction minus observation. Reversing that convention would change the signs, but not the squared errors or RMSE.

Definition: For \(n\) cases with observed outcomes \(y_i\) and predictions \(\hat{y}_i\), define the signed prediction error as \(d_i=\hat{y}_i-y_i\). The root mean squared error is $$ \operatorname{RMSE}=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(\hat{y}_i-y_i)^2} =\sqrt{\frac{1}{n}\sum_{i=1}^{n}d_i^2}. $$ The calculation uses all \(n\) paired cases and divides by \(n\).

The signed error records both direction and size: a positive value means the prediction is above the observed outcome, while a negative value means it is below. RMSE squares the signed errors, so both directions contribute nonnegative values. It is therefore a summary of error size, not a measure of whether predictions tend to be too high or too low. The square root returns the result to the same units as the outcomes.

A Reliable Calculation Sequence

For a small dataset, a table is the clearest way to organize the arithmetic. For each case, calculate \(d_i=\hat{y}_i-y_i\), then \(|d_i|\) and \(d_i^2\). Add the squared errors, divide by the number of cases, and take the nonnegative square root. Keep the absolute-error and squared-error columns separate: they answer different arithmetic questions, and RMSE uses the squared-error column.

1
Pair each prediction with its outcome.
Make sure the prediction and observed value belong to the same case and are expressed in the same units.
2
Calculate signed and unsquared errors.
Find \(d_i=\hat{y}_i-y_i\), and then record the absolute error \(|d_i|\) if it is useful for checking the case-by-case size.
3
Square each signed error.
Calculate \(d_i^2\) for every case. Do this before averaging; the mean signed error is not RMSE.
4
Average and take the square root.
Sum the squared errors, divide by \(n\), and take the square root of that mean squared error.

The observed outcome is sometimes written first when defining an error, as \(y_i-\hat{y}_i\). That alternative changes every signed error’s sign, but not its square: \((y_i-\hat{y}_i)^2=(\hat{y}_i-y_i)^2\). Thus, the RMSE is unchanged, provided the same pairs are used.

Worked Example: Four Predictions in Kilograms

Suppose a hypothetical model predicts the weight of four packages. The observed weights are 10, 12, 15, and 18 kg, and the corresponding predictions are 12, 11, 13, and 20 kg. Calculate RMSE, showing how the unsquared and squared errors differ.

CaseObserved \(y_i\) (kg)Predicted \(\hat{y}_i\) (kg)\(d_i=\hat{y}_i-y_i\) (kg)\(|d_i|\) (kg)\(d_i^2\) (kg²)
11012224
21211-111
31513-224
41820224

The signed errors are \(2,-1,-2,2\) kg. Their absolute values are \(2,1,2,2\) kg, while their squares are \(4,1,4,4\) kg². The total squared error is \(4+1+4+4=13\) kg². There are \(n=4\) paired cases, so

$$ \operatorname{RMSE} =\sqrt{\frac{13}{4}\text{ kg}^2} =\sqrt{3.25\text{ kg}^2} \approx 1.803\text{ kg}. $$

For these four predictions, the RMSE is about 1.803 kg. This describes the overall error size under the squared-error calculation; it does not say that each prediction is 1.803 kg from its outcome. In this dataset, the individual absolute errors are 2, 1, 2, and 2 kg.

What the Arithmetic Does to the Errors

The middle quantity, the mean squared error, is measured in squared outcome units. If the outcome is measured in kilograms, each \(d_i^2\) and their mean are measured in kg². Taking the square root changes the units back to kilograms. More generally, if outcomes are in minutes, mean squared error is in min² and RMSE is in minutes. This is one reason to report RMSE rather than only the intermediate mean squared error when describing typical prediction error in context.

Here is a brief justification of the calculation’s structure. Each difference \(d_i\) has the outcome’s units. Multiplication by itself gives \(d_i^2\) squared units; adding and averaging quantities in those same squared units preserves those units. The square root then reverses the squaring of the units. Since every \(d_i^2\) is nonnegative, their mean is nonnegative, so its nonnegative square root is defined, including when every prediction is exact.

$$ [d_i]=\text{outcome units},\qquad [d_i^2]=\text{outcome units}^2,\qquad [\operatorname{RMSE}]=\text{outcome units}. $$

Squaring also affects how strongly different-sized errors contribute. An error of 6 units contributes \(6^2=36\) squared units, while an error of 2 units contributes \(2^2=4\) squared units. The first contributes nine times as much to the sum of squared errors, even though its magnitude is only three times as large. The square root at the end restores the outcome units; it does not undo the fact that larger errors contributed more heavily to the average of squares.

Worked Example: Waiting-Time Predictions

Suppose predictions are made for three hypothetical appointment waiting times. The observed waits are 20, 35, and 40 minutes; the predictions are 18, 40, and 34 minutes. Calculate RMSE in minutes and distinguish the case-by-case error sizes from the squared values used in the calculation.

CaseObserved wait (min)Predicted wait (min)Signed error (min)Absolute error (min)Squared error (min²)
12018-224
235405525
34034-6636

The signed differences are \(18-20=-2\), \(40-35=5\), and \(34-40=-6\) minutes. The absolute errors are 2, 5, and 6 minutes. The corresponding squares are \(4\), \(25\), and \(36\) min², for a total of \(65\) min². Divide by three and take the square root:

$$ \operatorname{RMSE} =\sqrt{\frac{4+25+36}{3}\text{ min}^2} =\sqrt{\frac{65}{3}\text{ min}^2} \approx 4.655\text{ min}. $$

The RMSE is approximately 4.655 minutes for these three predictions. The largest absolute error, 6 minutes, contributes 36 min² to the total, while the 2-minute error contributes 4 min². The reported RMSE is in minutes, not minutes squared, and it is not the error for any one specific appointment.

Comparing Two Sets of Predictions

The same arithmetic can summarize predictions from different models when both sets are evaluated on the same observed outcomes. Using matched cases makes the comparison direct: each model is measured against the same outcomes. In the example below, the calculations show how two sets of errors can have different distributions while still being summarized by a single RMSE each.

Worked Example: Two Models on the Same Four Cases

For four hypothetical outcomes measured in points, the observed values are 8, 10, 12, and 14. Model A predicts 9, 11, 11, and 13. Model B predicts 8, 10, 12, and 17. Calculate each model’s RMSE from these four matched cases.

CaseObserved (points)Model A predictionModel A signed errorModel A squared errorModel B predictionModel B signed errorModel B squared error
18911800
21011111000
31211-111200
41413-111739

For Model A, the squared errors sum to \(1+1+1+1=4\) points². Thus,

$$ \operatorname{RMSE}_{A} =\sqrt{\frac{4}{4}\text{ points}^2} =1\text{ point}. $$

For Model B, the squared errors sum to \(0+0+0+9=9\) points². Thus,

$$ \operatorname{RMSE}_{B} =\sqrt{\frac{9}{4}\text{ points}^2} =\sqrt{2.25\text{ points}^2} =1.5\text{ points}. $$

On these four matched cases, Model A has the smaller RMSE: 1 point, compared with 1.5 points for Model B. Model B predicts three of the outcomes exactly, but its 3-point error contributes \(9\) points². The comparison is specifically about these four predictions and this metric; it does not by itself establish how either model will perform on other cases.

Common Mistakes and Checks

A correct result depends on using the right quantities in the right order. Before interpreting RMSE, check that the observed outcomes and predictions are paired case by case, that they use the same units, and that every included case has a usable observed value and prediction. State which cases were included if some were omitted; changing the included cases changes the calculation.

  • Stopping at the mean squared error. The mean of the squared errors is not yet RMSE. Take its square root before reporting the metric in outcome units.
  • Using signed errors without squaring. Positive and negative errors can offset in a signed sum. RMSE squares each error, so opposing signs cannot cancel.
  • Dividing by the wrong number. For a prediction metric calculated over \(n\) evaluation cases, divide the squared-error sum by \(n\), the number of included pairs.
  • Calling RMSE the error on every case. RMSE is one summary of all included cases. Individual errors can be both smaller and larger than it.
  • Confusing outcome units with squared units. Individual squared errors and mean squared error use squared units; RMSE uses the original outcome units.

The denominator is worth particular attention. Here RMSE summarizes prediction errors over a specified set of cases, so the mean squared error is \(\sum d_i^2/n\). A different residual summary used in a model-fitting setting may apply a degrees-of-freedom adjustment for a different purpose. Do not substitute such an adjustment into this prediction-metric calculation.

Key takeaway: For each paired outcome and prediction, subtract, square, and record the squared error. Average those squared errors over the included cases, then take the square root. Report the result in the outcome’s units and interpret it as a summary across those cases, not as a guaranteed error for any individual prediction.

Check Your Understanding

Use the definition and calculation steps to answer the following questions.

  1. For an observed value of 25 units and a prediction of 22 units, what are the signed error, absolute error, and squared error under the convention used here?
  2. A set of five cases has a total squared error of 80 kg². Calculate its RMSE, including the units.
  3. Why does reversing the signed-error convention leave RMSE unchanged?
  4. A model’s RMSE is 4 minutes. Does that mean every prediction differs from its observed value by exactly 4 minutes? Explain.
  5. Two models are compared using RMSE. Why is it useful to evaluate both on the same matched cases?