Skip to content

Commonly Used Metrics In Hydrological Modelling

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

atsyplenkov/tidyhydro

Repository files navigation

tidyhydro

R-CMD-check Lifecycle: experimental CRAN status GitHub R package version GitHub last commit

The tidyhydro package provides a set of commonly used metrics in hydrology (such as NSE, KGE, pBIAS) for use within a tidymodels infrastructure. Originally inspired by the yardstickand hydroGOF packages, this library is mainly written in C++ and provides a very quick estimation of desired goodness-of-fit criteria.

Installation

You can install the development version of tidyhydro from GitHub with:

# install.packages("devtools")
devtools::install_github("atsyplenkov/tidyhydro")

# OR

# install.packages("pak")
pak::pak("atsyplenkov/tidyhydro")

Example

The tidyhydro package follows the philosophy of yardstick and provides S3 class methods for vectors and data frames. For example, one can estimate NSE and pBIAS for a data frame like this:

library(yardstick)
library(tidyhydro)
data(solubility_test)

nse(solubility_test, solubility, prediction)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 nse     standard       0.879

pbias(solubility_test, solubility, prediction)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 pbias   standard      -0.512

or create a metric_set and estimate several parameters at once like this:

hydro_metrics <- yardstick::metric_set(nse, pbias)

hydro_metrics(solubility_test, solubility, prediction)
#> # A tibble: 2 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 nse     standard       0.879
#> 2 pbias   standard      -0.512

We do understand that sometimes one needs a qualitative interpretation of the model; therefore, we populated every function with a performance argument. When performance = TRUE, the metric interpretation will be returned according to Moriasi et al. (2015).

hydro_metrics(solubility_test, solubility, prediction, performance = TRUE)
#> # A tibble: 2 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>      <chr>    
#> 1 nse     standard   Excellent
#> 2 pbias   standard   Excellent

Benchmarking

Since the package uses Rcpp in the background, it performs slightly faster than its ancestors:

bench::mark(
  tidyhydro = tidyhydro::nse_vec(
    solubility_test$solubility,
    solubility_test$prediction
  ),
  hydroGOF = hydroGOF::NSE(
    sim = solubility_test$prediction,
    obs = solubility_test$solubility
  ),
  check = TRUE,
  relative = TRUE
)
#> # A tibble: 2 × 6
#>   expression   min median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <dbl>  <dbl>     <dbl>     <dbl>    <dbl>
#> 1 tidyhydro   1      1         1.71       1       1   
#> 2 hydroGOF    2.05   1.94      1         16.0     3.51

Alternatives

  • R
    • hydroGOF - Goodness-of-fit functions for comparison of simulated and observed hydrological time series

About

Commonly Used Metrics In Hydrological Modelling

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages