Skip to content

Commit

Permalink
Merge pull request #365 from poissonconsulting/dev
Browse files Browse the repository at this point in the history
JOSS paper draft
  • Loading branch information
joethorley authored Apr 25, 2024
2 parents b623a72 + eb52542 commit bc44bae
Show file tree
Hide file tree
Showing 33 changed files with 457 additions and 116 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/paper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Workflow derived from https://github.com/marketplace/actions/open-journals-pdf-generator

on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]

name: paper

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
with:
name: paper
path: paper/paper.pdf

4 changes: 2 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: main
pull_request:
branches: [main, master]
branches: main
release:
types: [published]
workflow_dispatch:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: main
pull_request:
branches: [main, master]
branches: main

name: test-coverage

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ docs/
inst/docs/
scripts/
inst/doc
paper/paper.pdf
28 changes: 16 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,41 @@ Version: 1.0.6.9015
Authors@R: c(
person("Joe", "Thorley", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7683-4592")),
person("Carl", "Schwarz", role = "aut"),
person("Rebecca", "Fisher", , "[email protected]", role = "aut"),
person("David", "Fox", , "[email protected]", role = "aut"),
person("Carl", "Schwarz", role = "aut"),
person("Angeline", "Tillmanns", role = "ctb"),
person("Ali", "Azizishirazi", role = "ctb"),
person("Seb", "Dalgarno", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-3658-4517")),
person("Kathleen", "McTavish", role = "ctb"),
person("Heather", "Thompson", role = "ctb"),
person("Doug", "Spry", role = "ctb"),
person("Rick", "van Dam", role = "ctb"),
person("Graham", "Batley", role = "ctb"),
person("Heather", "Thompson", role = "ctb"),
person("Andy", "Teucher", role = "ctb"),
person("Seb", "Dalgarno", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-3658-4517")),
person("Emilie", "Doussantousse", role = "ctb"),
person("Stephanie", "Hazlitt", role = "ctb"),
person("Yulia", "Cuthbertson", role = "ctb"),
person("Tony", "Bigwood", role = "ctb"),
person("Michael", "Antenucci", role = "ctb"),
person("Ali", "Azizishirazi", role = "ctb"),
person("Nadine", "Hussein", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0003-4470-8361")),
person("Nan-Hung", "Hsieh", role = "ctb"),
person("Sergio", "Ibarra Espinosa", role = "ctb"),
person("Sarah", "Lyons", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-6745-6796")),
person("Stephanie", "Hazlitt", role = "ctb"),
person("Hadley", "Wickham", role = "ctb"),
person("Sergio", "Ibarra Espinosa", role = "ctb"),
person("Andy", "Teucher", role = "ctb"),
person("Emilie", "Doussantousse", role = "ctb"),
person("Nan-Hung", "Hsieh", role = "ctb"),
person("Province of British Columbia", role = c("fnd", "cph")),
person("Environment and Climate Change Canada", role = c("fnd", "cph")),
person("Australian Government Department of Climate Change, Energy, the Environment and Water", role = c("fnd", "cph"))
)
Description: Species sensitivity distributions are cumulative probability
distributions which are fitted to toxicity concentrations for
different species as described by Posthuma et al.(2001)
<isbn:9781566705783>. The ssdtools package uses Maximum Likelihood to
<isbn:9781566705783>. The ssdtools package uses Maximum Likelihood to
fit distributions such as the gamma, log-logistic, log-normal and
Weibull to censored and/or weighted data. Multiple distributions can
log-normal log-normal mixture. Multiple distributions can
be averaged using Akaike Information Criteria. Confidence intervals
on hazard concentrations and proportions are produced by parametric
bootstrapping.
Expand Down
2 changes: 1 addition & 1 deletion R/licensing.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
licensing_md <- function() {
"## Licensing
Copyright 2023 Province of British Columbia,
Copyright 2024 Province of British Columbia,
Environment and Climate Change Canada, and
Australian Government Department of
Climate Change, Energy, the Environment and Water
Expand Down
2 changes: 1 addition & 1 deletion R/ssd-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ssd_plot <- function(data, pred, left = "Conc", right = left,
label = NULL, shape = NULL, color = NULL, size = 2.5,
linetype = NULL, linecolor = NULL,
xlab = "Concentration", ylab = "Species Affected",
ci = TRUE, ribbon = FALSE, hc = 0.05,
ci = TRUE, ribbon = TRUE, hc = 0.05,
shift_x = 3, add_x = 0,
bounds = c(left = 1, right = 1),
trans = "log10", xbreaks = waiver()) {
Expand Down
35 changes: 17 additions & 18 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ knitr::opts_chunk$set(
# ssdtools <img src="man/figures/logo.png" align="right" />

<!-- badges: start -->
[![Lifecycle:Maturing](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![Lifecycle:Stable](https://img.shields.io/badge/Lifecycle-Stable-97ca00)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![R-CMD-check](https://github.com/bcgov/ssdtools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bcgov/ssdtools/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/bcgov/ssdtools/graph/badge.svg?token=gVKHQQD1Jp)](https://codecov.io/github/bcgov/ssdtools)
[![CRAN status](https://www.r-pkg.org/badges/version/ssdtools)](https://cran.r-project.org/package=ssdtools)
Expand All @@ -25,9 +25,9 @@ knitr::opts_chunk$set(
`ssdtools` is an R package to fit and plot Species Sensitivity Distributions (SSD).

SSDs are cumulative probability distributions which are fitted to toxicity concentrations for different species as described by Posthuma et al. (2001).
The ssdtools package uses Maximum Likelihood to fit distributions such as the gamma, log-Gumbel (identical to inverse Weibull), log-logistic, log-normal and Weibull to censored and/or weighted data.
The ssdtools package uses Maximum Likelihood to fit distributions such as the log-normal, log-logistic, log-Gumbel (also known as the inverse Weibull), gamma, Weibull and log-normal log-normal mixture.
Multiple distributions can be averaged using Akaike Information Criteria.
Confidence intervals on hazard concentrations and proportions are produced by parametric bootstrapping.
Confidence intervals on hazard concentrations and proportions are produced by bootstrapping.

## Installation

Expand All @@ -38,49 +38,44 @@ install.packages("ssdtools")

To install the latest development version from [GitHub](https://github.com/bcgov/ssdtools)
```{r, eval = FALSE}
# install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
pak::pak("bcgov/ssdtools")
# install.packages("remotes")
remotes::install_github("bcgov/ssdtools")
```

## Introduction

`ssdtools` provides a data set for several chemicals including Boron.
The dependency `ssddata` provides a example data sets for several chemicals including Boron.
```{r, message=FALSE}
library(ssdtools)
ssddata::ccme_boron
```

Distributions are fit using `ssd_fit_dists()`
The six default distributions are fit using `ssd_fit_dists()`
```{r}
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = c("lnorm", "llogis"))
fits <- ssd_fit_dists(ssddata::ccme_boron)
```

and can be quickly plotted using `autoplot`
```{r, warning = FALSE, message = FALSE}
library(ggplot2)
theme_set(theme_bw())
autoplot(fits) +
scale_colour_ssd()
autoplot(fits)
```

The goodness of fit can be assessed using `ssd_gof`
```{r}
ssd_gof(fits)
```

and the model-averaged 5% hazard concentration estimated by parametric bootstrapping using `ssd_hc`.
and the model-averaged 5% hazard concentration estimated by bootstrapping using `ssd_hc`.
```{r}
set.seed(99)
hc5 <- ssd_hc(fits, ci = TRUE, nboot = 100) # 100 bootstrap samples for speed
hc5 <- ssd_hc(fits, ci = TRUE)
print(hc5)
```

To bootstrap in parallel set `future::plan()`. For example:
```{r, eval=FALSE}
future::multisession(workers = 2)
hc5 <- ssd_hc(fits, ci = TRUE, nboot = 100)
hc5 <- ssd_hc(fits, ci = TRUE)
```

Model-averaged predictions complete with confidence intervals can also be estimated by parametric bootstrapping using the `stats` generic `predict`.
Expand All @@ -94,8 +89,12 @@ set.seed(99)
boron_pred <- predict(fits, ci = TRUE)
```

and plotted together with the original data using `ssd_plot`.
The predictions can be plotted together with the original data using `ssd_plot`.
```{r}
library(ggplot2)
theme_set(theme_bw())
ssd_plot(ssddata::ccme_boron, boron_pred,
shape = "Group", color = "Group", label = "Species",
xlab = "Concentration (mg/L)", ribbon = TRUE
Expand Down
67 changes: 36 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- badges: start -->

[![Lifecycle:Maturing](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![Lifecycle:Stable](https://img.shields.io/badge/Lifecycle-Stable-97ca00)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![R-CMD-check](https://github.com/bcgov/ssdtools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bcgov/ssdtools/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/bcgov/ssdtools/graph/badge.svg?token=gVKHQQD1Jp)](https://codecov.io/github/bcgov/ssdtools)
[![CRAN
Expand All @@ -19,11 +19,11 @@ Distributions (SSD).
SSDs are cumulative probability distributions which are fitted to
toxicity concentrations for different species as described by Posthuma
et al. (2001). The ssdtools package uses Maximum Likelihood to fit
distributions such as the gamma, log-Gumbel (identical to inverse
Weibull), log-logistic, log-normal and Weibull to censored and/or
weighted data. Multiple distributions can be averaged using Akaike
Information Criteria. Confidence intervals on hazard concentrations and
proportions are produced by parametric bootstrapping.
distributions such as the log-normal, log-logistic, log-Gumbel (also
known as the inverse Weibull), gamma, Weibull and log-normal log-normal
mixture. Multiple distributions can be averaged using Akaike Information
Criteria. Confidence intervals on hazard concentrations and proportions
are produced by bootstrapping.

## Installation

Expand All @@ -38,13 +38,14 @@ To install the latest development version from
[GitHub](https://github.com/bcgov/ssdtools)

``` r
# install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
pak::pak("bcgov/ssdtools")
# install.packages("remotes")
remotes::install_github("bcgov/ssdtools")
```

## Introduction

`ssdtools` provides a data set for several chemicals including Boron.
The dependency `ssddata` provides a example data sets for several
chemicals including Boron.

``` r
library(ssdtools)
Expand All @@ -65,21 +66,16 @@ ssddata::ccme_boron
#> # ℹ 18 more rows
```

Distributions are fit using `ssd_fit_dists()`
The six default distributions are fit using `ssd_fit_dists()`

``` r
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = c("lnorm", "llogis"))
fits <- ssd_fit_dists(ssddata::ccme_boron)
```

and can be quickly plotted using `autoplot`

``` r
library(ggplot2)

theme_set(theme_bw())

autoplot(fits) +
scale_colour_ssd()
autoplot(fits)
```

![](man/figures/README-unnamed-chunk-5-1.png)<!-- -->
Expand All @@ -88,31 +84,35 @@ The goodness of fit can be assessed using `ssd_gof`

``` r
ssd_gof(fits)
#> # A tibble: 2 × 9
#> dist ad ks cvm aic aicc bic delta weight
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 lnorm 0.507 0.107 0.0703 239. 240. 242. 0 0.73
#> 2 llogis 0.487 0.0994 0.0595 241. 241. 244. 1.99 0.27
#> # A tibble: 6 × 9
#> dist ad ks cvm aic aicc bic delta weight
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 gamma 0.440 0.117 0.0554 238. 238. 240. 0.005 0.357
#> 2 lgumbel 0.829 0.158 0.134 244. 245. 247. 6.56 0.013
#> 3 llogis 0.487 0.0994 0.0595 241. 241. 244. 3.39 0.066
#> 4 lnorm 0.507 0.107 0.0703 239. 240. 242. 1.40 0.177
#> 5 lnorm_lnorm 0.320 0.116 0.0414 240. 243. 247. 4.98 0.03
#> 6 weibull 0.434 0.117 0.0542 238. 238. 240. 0 0.357
```

and the model-averaged 5% hazard concentration estimated by parametric
and the model-averaged 5% hazard concentration estimated by
bootstrapping using `ssd_hc`.

``` r
set.seed(99)
hc5 <- ssd_hc(fits, ci = TRUE, nboot = 100) # 100 bootstrap samples for speed
hc5 <- ssd_hc(fits, ci = TRUE)
print(hc5)
#> # A tibble: 1 × 10
#> dist percent est se lcl ucl wt method nboot pboot
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <dbl> <dbl>
#> 1 average 5 1.65 0.599 0.923 3.34 1 parametric 100 1
#> # A tibble: 1 × 11
#> dist proportion est se lcl ucl wt method nboot pboot samples
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> <I<lis>
#> 1 average 0.05 1.26 0.781 0.407 3.29 1 parametr… 1000 0.999 <dbl>
```

To bootstrap in parallel set `future::plan()`. For example:

``` r
future::multisession(workers = 2)
hc5 <- ssd_hc(fits, ci = TRUE, nboot = 100)
hc5 <- ssd_hc(fits, ci = TRUE)
```

Model-averaged predictions complete with confidence intervals can also
Expand All @@ -128,9 +128,14 @@ set.seed(99)
boron_pred <- predict(fits, ci = TRUE)
```

and plotted together with the original data using `ssd_plot`.
The predictions can be plotted together with the original data using
`ssd_plot`.

``` r
library(ggplot2)

theme_set(theme_bw())

ssd_plot(ssddata::ccme_boron, boron_pred,
shape = "Group", color = "Group", label = "Species",
xlab = "Concentration (mg/L)", ribbon = TRUE
Expand Down Expand Up @@ -202,7 +207,7 @@ By contributing to this project, you agree to abide by its terms.

## Licensing

Copyright 2023 Province of British Columbia, Environment and Climate
Copyright 2024 Province of British Columbia, Environment and Climate
Change Canada, and Australian Government Department of Climate Change,
Energy, the Environment and Water

Expand Down
Binary file modified man/figures/README-unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/ssd_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bc44bae

Please sign in to comment.