rmse | R Documentation |

This function computes the root mean square error (RMSE).

```
rmse(predicted, observed, na.rm = FALSE)
```

`predicted` |
numeric vector that contains the 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. |

RMSE is expressed as

`\sqrt{n^{-1} \sum \limits_{i=1}^n{ \left| P_i - O_i \right|^2}}`

*n*the number of observations

*P*the "model estimates or predictions"

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

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

mean absolute percent error (RMSE) as a numeric vector. 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 `rmse(pre, obs, na.rm = TRUE)`

.

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, https://web.archive.org/web/20230119121852/climate.geog.udel.edu/~climate/publication_html/Pdf/WM_CR_05.pdf. Retrieved thanks to the Internet Archive: Wayback Machine

`mape`

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

for
mean-absolute error (MAE), `madstat`

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

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

for
Nash-Sutcliffe model efficiency (NSE).

```
library("ie2misc")
obs <- 1:10 # observed
pre <- 2:11 # predicted
rmse(pre, obs)
library("rando")
set_n(100) # makes the example reproducible
obs1 <- r_norm(.seed = 209) # observed
pre1 <- r_norm(.seed = 224) # predicted
# using the vectors pre1 and obs1
rmse(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")))
rmse(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)
rmse(df1[, 2], df1[, 1])
# df1[, 1] # observed values from column 1 of df1
# df1[, 2] # predicted values from column 2 of df1
library("data.table")
# using a data.table of the numeric vectors pre1 and obs1
df2 <- data.table(obs1, pre1)
rmse(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
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.