-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
93 lines (71 loc) · 3.53 KB
/
README.Rmd
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
requireNamespace("hydroGOF", quietly = TRUE)
requireNamespace("bench", quietly = TRUE)
```
# tidyhydro
<!-- badges: start -->
[![R-CMD-check](https://github.com/atsyplenkov/tidyhydro/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/atsyplenkov/tidyhydro/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/tidyhydro)](https://CRAN.R-project.org/package=tidyhydro)
![GitHub R package version](https://img.shields.io/github/r-package/v/atsyplenkov/tidyhydro?label=github)
![GitHub last commit](https://img.shields.io/github/last-commit/atsyplenkov/tidyhydro)
<!-- badges: end -->
The `tidyhydro` package provides a set of commonly used metrics in hydrology (such as NSE, KGE, pBIAS) for use within a [`tidymodels`](https://www.tidymodels.org/) infrastructure. Originally inspired by the [`yardstick`](https://github.com/tidymodels/yardstick/tree/main)and [`hydroGOF`](https://github.com/hzambran/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](https://github.com/atsyplenkov/tidyhydro) with:
``` r
# 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`](https://github.com/tidymodels/yardstick/tree/main) and provides S3 class methods for vectors and data frames. For example, one can estimate `NSE` and `pBIAS` for a data frame like this:
```{r example}
library(yardstick)
library(tidyhydro)
data(solubility_test)
nse(solubility_test, solubility, prediction)
pbias(solubility_test, solubility, prediction)
```
or create a [`metric_set`](https://yardstick.tidymodels.org/reference/metric_set.html) and estimate several parameters at once like this:
```{r metricset}
hydro_metrics <- yardstick::metric_set(nse, pbias)
hydro_metrics(solubility_test, solubility, prediction)
```
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](https://elibrary.asabe.org/abstract.asp?aid=46548&t=3&dabs=Y&redir=&redirType=)).
```{r interpretation}
hydro_metrics(solubility_test, solubility, prediction, performance = TRUE)
```
## Benchmarking
Since the package uses `Rcpp` in the background, it performs slightly faster than its ancestors:
```{r benchmarking}
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
)
```
## Alternatives
- R
- [`hydroGOF`](https://github.com/hzambran/hydroGOF) - Goodness-of-fit functions for comparison of simulated and observed hydrological time series