## S3 method for class 'numeric'
mae(actual, predicted, ...)
## S3 method for class 'numeric'
weighted.mae(actual, predicted, w, ...)
mae(...)
weighted.mae(...)
mean absolute error
mae.numeric | R Documentation |
Description
The mae()
-function computes the mean absolute error between the observed and predicted <numeric>
vectors. The weighted.mae()
function computes the weighted mean absolute error.
Usage
Arguments
actual
|
A |
predicted
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Calculation
The metric is calulated as follows,
\[ \frac{\sum_i^n |y_i - \upsilon_i|}{n} \]
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 Mean Absolute Error (MAE)
cat(
"Mean Absolute Error", mae(
actual = actual,
predicted = predicted,
),"Mean Absolute Error (weighted)", weighted.mae(
actual = actual,
predicted = predicted,
w = mtcars$mpg/mean(mtcars$mpg)
),sep = "\n"
)