-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
167 lines (119 loc) · 5.27 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
---
output: github_document
---
# wqbench
<!-- badges: start -->
[![img](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![R-CMD-check](https://github.com/bcgov/wqbench/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bcgov/wqbench/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/bcgov/wqbench/branch/main/graph/badge.svg)](https://app.codecov.io/gh/bcgov/wqbench?branch=main)
<!-- badges: end -->
This package contains the functions and tools to generate aquatic life water quality benchmarks.
## Installation
```{r, eval=FALSE}
# install.packages("devtools")
devtools::install_github("bcgov/wqbench")
```
## Workflow
```{r}
library(wqbench)
```
### Create Data Set for Shiny App
The `wqb_create_data_set()` function will download the US EPA ECOTOX<sup>1</sup> database, create a local .sqlite database, add other data sources and filter conditions, clean and process the data, classify the duration, standardize the effect and output the completed data set needed for the shinywqbench app.
The function will create an RDS file of the data set as well.
It takes a few minutes to download and create the data set.
The default argument for:
- `file_path` will save the raw text files at `"~/Ecotoxicology/ecotox"`.
- `folder_path` will save the .sqlite database and RDS file is at `"~/Ecotoxicology/ecotox_db/"`.
- `version` will download the most recent version of the data set available on the website.
```{r, eval=FALSE}
data_set <- wqb_create_data_set()
```
The data set can be read in after it has been created.
```{r, eval=FALSE}
data_set <- readRDS("~/Ecotoxicology/ecotox_db/ecotox_ascii_09_12_2024.rds")
```
### Generate Benchmark
```{r}
set.seed(101)
```
#### Deterministic Example
```{r}
data <- wqb_filter_chemical(wqbenchdata::aquatic_data, "100016")
data <- wqb_benchmark_method(data)
data_agg <- wqb_aggregate(data)
data_agg <- wqb_af(data_agg)
ctv <- wqb_generate_ctv(data_agg)
ctv
```
To calculate the benchmark for the chemical, divide the critical toxicity value (ctv) by the assessment factors.
```{r}
benchmark <- ctv / (data_agg$af_bc_species * data_agg$af_salmon * data_agg$af_planktonic * data_agg$af_variation)
benchmark
```
*Deterministic* method only generates an estimate, the lcl and ucl columns will always be blank .
```{r}
# Plot data set
wqb_plot(data)
```
```{r, fig.width=14}
# Plot the results
wqb_plot_det(data_agg)
```
#### SSD Example
```{r}
data <- wqb_filter_chemical(wqbenchdata::aquatic_data, "1071836")
data <- wqb_benchmark_method(data)
data_agg <- wqb_aggregate(data)
data_agg <- wqb_af(data_agg)
ctv <- wqb_generate_ctv(data_agg)
ctv
```
To calculate the benchmark for the chemical, divide the critical toxicity value (ctv) by the assessment factors.
```{r}
benchmark <- ctv / (data_agg$af_bc_species * data_agg$af_salmon * data_agg$af_planktonic * data_agg$af_variation)
benchmark
```
*SSD* method can generate a lower and upper confidence interval.
```{r, fig.height=10, fig.width=12}
# Plot data set
wqb_plot(data)
```
```{r}
# Plot the results
fit <- wqb_ssd_fit(data_agg)
wqb_plot_ssd(data_agg, fit)
```
#### Summary Tables
```{r}
wqb_summary_trophic_species(data_agg)
wqb_summary_trophic_groups(data_agg)
wqb_summary_af(data_agg)
```
## Developer Instructions
See the [Developer Instructions](https://bcgov.github.io/wqbench/articles/Developer-instructions.html) on the package website for
instructions on updating the reference data for the database and updating the "Add Data" template
See the [README in the shinywqbench repository](https://github.com/bcgov/shinywqbench?tab=readme-ov-file#shinywqbench) for instructions for updating
and deploying the [shiny app](https://bcgov-env.shinyapps.io/shinywqbench/).
## Getting Help or Reporting an Issue
To report issues, bugs or enhancements, please file an [issue](https://github.com/bcgov/wqbench/issues).
Check out the [support](https://github.com/bcgov/wqbench/blob/main/.github/SUPPORT.md) for more info.
## Code of Conduct
Please note that the shinywqbench project is released with a [Contributor Code of Conduct](https://github.com/bcgov/wqbench/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
## License
The code is released under the Apache License 2.0
> Copyright 2023 Province of British Columbia
>
> Licensed under the Apache License, Version 2.0 (the "License");
> you may not use this file except in compliance with the License.
> You may obtain a copy of the License at
>
> https://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an "AS IS" BASIS,
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> See the License for the specific language governing permissions and
> limitations under the License.
## Reference
1. Olker, J. H., Elonen, C. M., Pilli, A., Anderson, A., Kinziger, B., Erickson, S., Skopinski, M., Pomplun, A., LaLone, C. A., Russom, C. L., & Hoff, D. (2022). The ECOTOXicology Knowledgebase: A Curated Database of Ecologically Relevant Toxicity Tests to Support Environmental Research and Risk Assessment. Environmental Toxicology and Chemistry, 41(6):1520-1539. https://doi.org/10.1002/etc.5324