## S3 method for class 'numeric'
rae(actual, predicted, ...)
## S3 method for class 'numeric'
weighted.rae(actual, predicted, w, ...)
rae(...)
weighted.rae(...)
relative absolute error
rae.numeric | R Documentation |
Description
The rae()
-function calculates the normalized relative absolute error between the predicted and observed <numeric>
vectors. The weighted.rae()
function computes the weigthed relative absolute error.
Usage
Arguments
actual
|
A |
predicted
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Calculation
The Relative Absolute Error (RAE) is calculated as:
\[ \text{RAE} = \frac{\sum_{i=1}^n |y_i - \upsilon_i|}{\sum_{i=1}^n |y_i - \bar{y}|} \]
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 Absolute Error (RAE)
cat(
"Relative Absolute Error", rae(
actual = actual,
predicted = predicted,
),"Relative Absolute Error (weighted)", weighted.rae(
actual = actual,
predicted = predicted,
w = mtcars$mpg/mean(mtcars$mpg)
),sep = "\n"
)