Skip to contents

Root Mean Squared Error (RMSE)

Usage

rmse(data, ...)

# S3 method for class 'data.frame'
rmse(data, truth, estimate, na_rm = TRUE, ...)

rmse_vec(truth, estimate, na_rm = TRUE, ...)

Arguments

data

A data.frame containing the columns specified by the truth and estimate arguments.

...

Not currently used.

truth

The column identifier for the true results (that is numeric). This should be an unquoted column name although this argument is passed by expression and supports quasiquotation (you can unquote column names). For _vec() functions, a numeric vector.

estimate

The column identifier for the predicted results (that is also numeric). As with truth this can be specified different ways but the primary method is to use an unquoted variable name. For _vec() functions, a numeric vector.

na_rm

A logical value indicating whether NA values should be stripped before the computation proceeds.

Value

A tibble with columns .metric, .estimator, and .estimate and 1 row of values.

For grouped data frames, the number of rows returned will be the same as the number of groups.

For rmse_vec(), a single numeric value (or NA).

Details

The RMSE is estimated as follows: $$ RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n}{(sim_i - obs_i)^2}} $$ where:

  • \(sim\) defines model simulations at time step \(i\)

  • \(obs\) defines model observations at time step \(i\)

See also

Other numeric metrics: mse(), pbias()

Other accuracy metrics: mse()

Examples

library(tidyhydro)

# Supply truth and predictions as bare column names
rmse(avacha, obs, sim)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 rmse    standard        25.0

# Or as numeric vectors
rmse_vec(avacha$obs, avacha$sim)
#> [1] 25.01887