Skip to contents

Mean squared error (MSE) is the mean squared difference between observations and predictions.

Usage

mse(obs, pred, na.rm = TRUE)

Arguments

obs

Numeric observation vector.

pred

Numeric prediction vector paired with obs.

na.rm

Logical; remove incomplete pairs?

Value

One numeric value.

Details

$$\mathrm{MSE} = \frac{1}{n}\sum_{i = 1}^{n}(obs_i - pred_i)^2$$

MSE is non-negative and zero indicates perfect predictions. Smaller values indicate better agreement. Squaring gives larger errors disproportionately more influence, making MSE sensitive to large deviations. Its units are the squared units of the response variable, so rmse() is usually easier to interpret on the original response scale. Missing-value handling follows bias().

References

Hodson, T. O. (2022). Root mean square error (RMSE) or mean absolute error (MAE): When to use them or not. Geoscientific Model Development, 15, 5481-5487. doi:10.5194/gmd-15-5481-2022

Examples

mse(1:3, c(1, 3, 2))
#> [1] 0.6666667