## S3 method for class 'numeric'
rrse(actual, predicted, ...)
## S3 method for class 'numeric'
weighted.rrse(actual, predicted, w, ...)
rrse(...)
weighted.rrse(...)
root relative squared error
rrse.numeric | R Documentation |
Description
The rrse()
-function calculates the root relative squared error between the predicted and observed <numeric>
vectors. The weighted.rrse()
function computes the weighed root relative squared errorr.
Usage
Arguments
actual
|
A |
predicted
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Calculation
The metric is calculated as,
\[ \text{RRSE} = \sqrt{\frac{\sum_{i=1}^n (y_i - \upsilon_i)^2}{\sum_{i=1}^n (y_i - \bar{y})^2}} \]
Where \(y_i\) are the actual
values, \(\upsilon_i\) are the predicted
values, and \(\bar{y}\) is the mean of the actual
values.
Examples
# 1) fit a linear
# regression
<- lm(
model ~ .,
mpg data = mtcars
)
# 1.1) define actual
# and predicted values
# to measure performance
<- mtcars$mpg
actual <- fitted(model)
predicted
# 2) evaluate in-sample model
# performance using Relative Root Squared Errror (RRSE)
cat(
"Relative Root Squared Errror", rrse(
actual = actual,
predicted = predicted,
),"Relative Root Squared Errror (weighted)", weighted.rrse(
actual = actual,
predicted = predicted,
w = mtcars$mpg/mean(mtcars$mpg)
),sep = "\n"
)