regression: Regression Metrics

regressionR Documentation

Regression Metrics

Description

Case-weighted versions of typical regression metrics:

  • mse(): Mean-squared error.

  • rmse(): Root-mean-squared error.

  • mae(): Mean absolute error.

  • medae(): Median absolute error.

  • mape(): Mean absolute percentage error.

  • prop_within(): Proportion of predictions that are within a given tolerance around the actual values.

  • deviance_normal(): Average (unscaled) normal deviance. Equals MSE, and also the average Tweedie deviance with p = 0.

  • deviance_poisson(): Average (unscaled) Poisson deviance. Equals average Tweedie deviance with p=1.

  • deviance_gamma(): Average (unscaled) Gamma deviance. Equals average Tweedie deviance with p=2.

  • deviance_tweedie(): Average Tweedie deviance with parameter p \in \{0\} \cup [1, \infty), see reference.

Lower values mean better performance. Notable exception is prop_within(), where higher is better.

Usage

mse(actual, predicted, w = NULL, ...)

rmse(actual, predicted, w = NULL, ...)

mae(actual, predicted, w = NULL, ...)

medae(actual, predicted, w = NULL, ...)

mape(actual, predicted, w = NULL, ...)

prop_within(actual, predicted, w = NULL, tol = 1, ...)

deviance_normal(actual, predicted, w = NULL, ...)

deviance_poisson(actual, predicted, w = NULL, ...)

deviance_gamma(actual, predicted, w = NULL, ...)

deviance_tweedie(actual, predicted, w = NULL, tweedie_p = 0, ...)

Arguments

actual

Observed values.

predicted

Predicted values.

w

Optional case weights.

...

Further arguments passed to weighted_mean() (no effect for medae()).

tol

Predictions in [\textrm{actual} \pm \textrm{tol}] count as "within" (only relevant for prop_within()).

tweedie_p

Tweedie power p \in \{0\} \cup [1, \infty).

Value

A numeric vector of length one.

Input range

The values of actual and predicted can be any real numbers, with the following exceptions:

  • mape(): Non-zero actual values.

  • deviance_poisson(): Non-negative actual values and predictions.

  • deviance_gamma(): Strictly positive actual values and predictions.

References

Jorgensen, B. (1997). The Theory of Dispersion Models. Chapman & Hall/CRC. ISBN 978-0412997112.

Examples

y <- 1:10
pred <- c(1:9, 12)
w <- 1:10

rmse(y, pred)
sqrt(mse(y, pred))  # Same

mae(y, pred)
mae(y, pred, w = w)
medae(y, pred, w = 1:10)
mape(y, pred)

prop_within(y, pred)

deviance_normal(y, pred)
deviance_poisson(y, pred)
deviance_gamma(y, pred)

deviance_tweedie(y, pred, tweedie_p = 0)  # Normal
deviance_tweedie(y, pred, tweedie_p = 1)  # Poisson
deviance_tweedie(y, pred, tweedie_p = 2)  # Gamma
deviance_tweedie(y, pred, tweedie_p = 1.5, w = 1:10)


MetricsWeighted documentation built on Nov. 16, 2023, 5:09 p.m.