relative root mean squared error

rrmse.numeric R Documentation

Description

The rrmse()-function computes the Relative Root Mean Squared Error between the observed and predicted <numeric> vectors. The weighted.rrmse() function computes the weighted Relative Root Mean Squared Error.

Usage

## S3 method for class 'numeric'
rrmse(actual, predicted, normalization = 1L, ...)

## S3 method for class 'numeric'
weighted.rrmse(actual, predicted, w, normalization = 1L, ...)

rrmse(...)

weighted.rrmse(...)

Arguments

actual

A <numeric>-vector of length \(n\). The observed (continuous) response variable.

predicted

A <numeric>-vector of length \(n\). The estimated (continuous) response variable.

normalization

A <numeric>-value of length \(1\) (default: \(1\)). \(0\): mean-normalization, \(1\): range-normalization, \(2\): IQR-normalization.

Arguments passed into other methods.

w

A <numeric>-vector of length \(n\). The weight assigned to each observation in the data.

Value

A <numeric> vector of length 1.

Calculation

The metric is calculated as,

\[ \frac{RMSE}{\gamma} \]

Where \(\gamma\) is the normalization factor.

Examples

# 1) fit a linear
# regression
model <- lm(
  mpg ~ .,
  data = mtcars
)

# 1.1) define actual
# and predicted values
# to measure performance
actual    <- mtcars$mpg
predicted <- fitted(model)

# 2) evaluate in-sample model
# performance using Relative Root Mean Squared Error (RRMSE)
cat(
  "IQR Relative Root Mean Squared Error", rrmse(
    actual        = actual,
    predicted     = predicted,
    normalization = 2
  ),
  "IQR Relative Root Mean Squared Error (weighted)", weighted.rrmse(
    actual        = actual,
    predicted     = predicted,
    w             = mtcars$mpg/mean(mtcars$mpg),
    normalization = 2
  ),
  sep = "\n"
)