Skip to contents

Calculate the mean percentage error of a numeric vector.

Usage

mpe_vec(truth, estimate, na_rm = TRUE)

Arguments

truth

Numeric vector containing the actual values.

estimate

Numeric vector containing the forecasts.

na_rm

Logical value. If TRUE, missing values are removed.

Value

A numeric value.

Details

mpe_vec() computes the average signed percentage forecast error: ((truth - estimate) / truth) * 100. Positive values indicate that forecasts are, on average, below the observed values in percentage terms. Negative values indicate that forecasts are, on average, above the observed values.

This metric is undefined when truth is zero and may return Inf, -Inf, or NaN in such cases.

Examples

truth <- c(10, 20, 40)
estimate <- c(8, 22, 30)

mpe_vec(truth, estimate)
#> [1] 11.66667

truth_na <- c(10, 20, NA)
estimate_na <- c(8, 22, 25)
mpe_vec(truth_na, estimate_na)
#> [1] 5