Learn R Programming

midr (version 0.5.0)

weighted.mse: Weighted Loss Functions

Description

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)

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.

Arguments

x

a numeric vector.

y

an optional numeric vector. If passed, the loss is calculated for the differences between x and y. If not, the loss is calculated for the deviations of x 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, any NA and NaNs are removed from x before the calculation.

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

Run this code
weighted.rmse(x = c(0, 10), y = c(0, 0), w = c(99, 1))
weighted.mae(x = c(0, 10), y = c(0, 0), w = c(99, 1))
weighted.medae(x = c(0, 10), y = c(0, 0), w = c(99, 1))
# compute uninterpreted rate
mid <- interpret(dist ~ speed, cars)
weighted.mse(cars$dist, predict(mid, cars)) / weighted.mse(cars$dist)
mid$ratio

Run the code above in your browser using DataLab