This function computes the mean-absolute error (MAE).

1 |

`predicted` |
numeric vector that contains the model predicted data points (1st parameter) |

`observed` |
numeric vector that contains the observed data points (2nd parameter) |

`na.rm` |
logical vector that determines whether the missing values should be removed or not. |

(MAE) is expressed as

*n^{-1} ∑ \limits_{i=1}^n{ ≤ft| P_i - O_i \right|}*

*n*the number of observations

*P*the "model estimates or predictions"

*O*the "thought-to-be reliable and pairwise matched observations"

MAE is fully discussed in the Willmott reference, including a comparison to root mean square error (RMSE).

mean-absolute error (MAE) as a numeric vector using the same
units as the given variables. The default choice is that any NA values
will be kept (`na.rm = FALSE`

). This can be changed by
specifying `na.rm = TRUE`

, such as `mae(pre, obs, na.rm = TRUE)`

.

r - Better error message for stopifnot? - Stack Overflow answered by Andrie on Dec 1 2011. See http://stackoverflow.com/questions/8343509/better-error-message-for-stopifnot.

Cort J. Willmott and Kenji Matsuura, "Advantages of the mean-absolute error (MAE) over the root mean square error (RMSE) in assessing average model performance", *Climate Research*, Vol. 30: 79-82, 2005, http://climate.geog.udel.edu/~climate/publication_html/Pdf/WM_CR_05.pdf.

`mape`

for mean absolute percent error (MAPE), `madstat`

for
mean-absolute deviation (MAD), `dr`

for "index of agreement (dr)", `vnse`

for Nash-Sutcliffe model efficiency (NSE), and `rmse`

for
root mean square error (RMSE).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ```
library(ie2misc)
obs <- 1:10 # observed
pre <- 2:11 # predicted
mae(pre, obs)
require(stats)
set.seed(100) # makes the example reproducible
obs1 <- rnorm(100) # observed
pre1 <- rnorm(100) # predicted
# using the vectors pre1 and obs1
mae(pre1, obs1)
# using a matrix of the numeric vectors pre1 and obs1
mat1 <- matrix(data = c(obs1, pre1), nrow = length(pre1), ncol = 2,
byrow = FALSE, dimnames = list(c(rep("", length(pre1))),
c("Predicted", "Observed")))
mae(mat1[, 2], mat1[, 1])
# mat1[, 1] # observed values from column 1 of mat1
# mat1[, 2] # predicted values from column 2 of mat1
# using a data.frame of the numeric vectors pre1 and obs1
df1 <- data.frame(obs1, pre1)
mae(df1[, 2], df1[, 1])
# df1[, 1] # observed values from column 1 of df1
# df1[, 2] # predicted values from column 2 of df1
# using a data.table of the numeric vectors pre1 and obs1
df2 <- data.table(obs1, pre1)
mae(df2[, 2, with = FALSE][[1]], df2[, 1, with = FALSE][[1]])
# df2[, 1, with = FALSE][[1]] # observed values from column 1 of df2
# df2[, 2, with = FALSE][[1]] # predicted values from column 2 of df2
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.