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.
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, ...)
Observed values.
Predicted values.
Optional case weights.
Further arguments passed to weighted_mean()
(no effect for medae()
).
Predictions in \([\textrm{actual} \pm \textrm{tol}]\) count as "within"
(only relevant for prop_within()
).
Tweedie power \(p \in \{0\} \cup [1, \infty)\).
A numeric vector of length one.
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.
Jorgensen, B. (1997). The Theory of Dispersion Models. Chapman & Hall/CRC. ISBN 978-0412997112.
y <- 1:10
pred <- c(1:9, 12)
w <- 1:10
rmse(y, pred)
#> [1] 0.6324555
sqrt(mse(y, pred)) # Same
#> [1] 0.6324555
mae(y, pred)
#> [1] 0.2
mae(y, pred, w = w)
#> [1] 0.3636364
medae(y, pred, w = 1:10)
#> [1] 0
mape(y, pred)
#> [1] 2
prop_within(y, pred)
#> [1] 0.9
deviance_normal(y, pred)
#> [1] 0.4
deviance_poisson(y, pred)
#> [1] 0.03535689
deviance_gamma(y, pred)
#> [1] 0.003130978
deviance_tweedie(y, pred, tweedie_p = 0) # Normal
#> [1] 0.4
deviance_tweedie(y, pred, tweedie_p = 1) # Poisson
#> [1] 0.03535689
deviance_tweedie(y, pred, tweedie_p = 2) # Gamma
#> [1] 0.003130978
deviance_tweedie(y, pred, tweedie_p = 1.5, w = 1:10)
#> [1] 0.01912556