View source: R/weighted_loss.R
| weighted.loss | R Documentation |
weighted.loss() computes various loss metrics (e.g., RMSE, MAE) between two numeric vectors, or for the deviations from the weighted mean of a numeric vector.
weighted.loss(
x,
y = NULL,
w = NULL,
na.rm = FALSE,
method = c("rmse", "mse", "mae", "medae", "r2")
)
x |
a numeric vector. |
y |
an optional numeric vector. If |
w |
a numeric vector of sample weights for each value in |
na.rm |
logical. If |
method |
the loss measure. One of "mse" (mean square error), "rmse" (root mean square error), mae" (mean absolute error), "medae" (median absolute error), or "r2" (R-squared). |
weighted.loss() returns a single numeric value.
# Calculate loss metrics between x and y with weights
weighted.loss(x = c(0, 10), y = c(0, 0), w = c(99, 1), method = "rmse")
weighted.loss(x = c(0, 10), y = c(0, 0), w = c(99, 1), method = "mae")
weighted.loss(x = c(0, 10), y = c(0, 0), w = c(99, 1), method = "medae")
# Verify uninterpreted variation ratio of a fitted MID model without weights
mid <- interpret(dist ~ speed, cars)
1 - weighted.loss(cars$dist, predict(mid, cars), method = "r2")
mid$ratio
# Verify uninterpreted variation ratio of a fitted MID model with weights
w <- 1:nrow(cars)
mid <- interpret(dist ~ speed, cars, weights = w)
1 - weighted.loss(cars$dist, predict(mid, cars), w = w, method = "r2")
mid$ratio
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.