weighted.mse()
, weighted.rmse()
, weighted.mae()
and weighted.medae()
compute the loss based on the differences of two numeric vectors or deviations from the mean of a numeric vector.
Usage
weighted.mse(x, y = NULL, w = NULL, ..., na.rm = FALSE)
weighted.rmse(x, y = NULL, w = NULL, ..., na.rm = FALSE)
weighted.mae(x, y = NULL, w = NULL, ..., na.rm = FALSE)
weighted.medae(x, y = NULL, w = NULL, ..., na.rm = FALSE)
Arguments
- x
a numeric vector.
- y
an optional numeric vector. If passed, the loss is calculated for the differences between
x
andy
. If not, the loss is calculated for the deviations ofx
from the weighted mean of itself.- w
a numeric vector of sample weights for each value in
x
.- ...
optional parameters.
- na.rm
logical. If
TRUE
, anyNA
andNaN
s are removed fromx
before the calculation.
Value
weighted.mse()
(mean square error), weighted.rmse()
(root mean square error), weighted.mae()
(mean absolute error) and weighted.medae
(median absolute error) returns a single numeric value.
Details
weighted.mse()
returns the mean square error, weighted.rmse()
returns the root mean square error, weighted.mae()
returns the mean absolute error, and weighted.medae()
returns the median absolute error between two weighted vectors x
and y
. If y
is not passed, these functions return the corresponding statistic based on the deviations from the mean of x
.
Examples
weighted.rmse(x = c(0, 10), y = c(0, 0), w = c(99, 1))
#> [1] 1
weighted.mae(x = c(0, 10), y = c(0, 0), w = c(99, 1))
#> [1] 0.1
weighted.medae(x = c(0, 10), y = c(0, 0), w = c(99, 1))
#> [1] 0
# compute uninterpreted rate
mid <- interpret(dist ~ speed, cars)
#> 'model' not passed: response variable in 'data' is used
weighted.mse(cars$dist, predict(mid, cars)) / weighted.mse(cars$dist)
#> [1] 0.2263636
mid$ratio
#> [1] 0.2263636