These are standard error and deviation measures for numeric data. "Deviation" means the natural variation of the values of a numeric vector around its central tendency (usually the mean or median). "Error" means the average discrepancy between the actual values of a numeric vector and its predicted values.
mae(actual, pred, na.rm = FALSE)rmse(actual, pred, na.rm = FALSE)
mad(x, na.rm = FALSE, version = "mean", ...)
In all cases, if any value in actual
or pred
is NA
and na.rm = FALSE
, then the function returns NA
.
mae()
returns the mean absolute error (MAE) of predicted values pred
compared to the actual
values.
rmse()
returns the root mean squared error (RMSE) of predicted values pred
compared to the actual
values.
mad()
returns either the mean absolute deviation (MAD) of values relative to their mean (default) or the median absolute deviation relative to their median. See details.
numeric vector. Actual (true) values of target outcome data.
numeric vector. Predictions corresponding to each respective element in actual
.
logical(1). TRUE
if missing values should be removed; FALSE
if they should be retained. If TRUE
, then if any element of either actual
or pred
is missing, its paired element will be also removed.
numeric vector. Values for which to calculate the MAD.
character(1). By default (version = 'mean'
), mad()
returns the mean absolute deviation (MAD) of values relative to their mean. If version = 'median'
, it calls the stats::mad()
function instead, the median absolute deviation relative to their median (MedAD, sometimes also called MAD). Any other value gives an error. See details.
Arguments to pass to stats::mad()
if version = 'median'
. See the version
argument for details.
Mean absolute deviation (MAD)
mad()
returns the mean absolute deviation (MAD) of values relative to their mean. This is useful as a default benchmark for the mean absolute error (MAE), as the standard deviation (SD) is a default benchmark for the root mean square error (RMSE).
NOTE: This function name overrides stats::mad()
(median absolute deviation relative to their median). To maintain the functionality of stats::mad()
, specify the version
argument.
a <- c(3, 5, 2, 7, 9, 4, 6, 8, 1, 10)
p <- c(2.5, 5.5, 2, 6.5, 9.5, 3.5, 6, 7.5, 1.5, 9.5)
mae(a, p)
rmse(a, p)
mad(a)
Run the code above in your browser using DataLab