Skip to content

Commit

Permalink
Merge pull request #396 from bcgov/joss-paper
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley authored Jan 6, 2025
2 parents 11eff29 + ffb1792 commit 4011ab2
Show file tree
Hide file tree
Showing 117 changed files with 613 additions and 501 deletions.
2 changes: 0 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@
^CRAN-SUBMISSION$
^CODE_OF_CONDUCT\.md$
^vignettes/articles$
^doc$
^Meta$
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master, dev]
branches: [main, master]

name: R-CMD-check

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/paper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

on:
push:
branches: [main]
branches: [main, joss-paper]
pull_request:
branches: [main, dev]
branches: [main, joss-paper]

name: paper

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master, dev]
branches: [main, master]

name: test-coverage.yaml

Expand Down
13 changes: 5 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

*.html

/docs/
/inst/docs/
/paper/paper.pdf
/scripts/boron_samples1
/scripts/checks.md
docs
inst/docs
inst/doc
/ignore
/doc/
/Meta/
scripts

/paper/paper.pdf
12 changes: 7 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ssdtools
Title: Species Sensitivity Distributions
Version: 2.1.0.9001
Version: 2.2.0
Authors@R: c(
person("Joe", "Thorley", , "joe@poissonconsulting.ca", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7683-4592")),
Expand All @@ -11,22 +11,24 @@ Authors@R: c(
person("Seb", "Dalgarno", , "seb@poissonconsulting.ca", role = "ctb",
comment = c(ORCID = "0000-0002-3658-4517")),
person("Kathleen", "McTavish", role = "ctb"),
person("Heather", "Thompson", role = "ctb"),
person("Heather", "Thompson", role = "ctb"),
person("Doug", "Spry", role = "ctb"),
person("Rick", "van Dam", role = "ctb"),
person("Graham", "Batley", role = "ctb"),
person("Tony", "Bigwood", role = "ctb"),
person("Ali", "Azizishirazi", role = "ctb"),
person("Nadine", "Hussein", , "nadine@poissonconsulting.ca", role = "ctb",
comment = c(ORCID = "0000-0003-4470-8361")),
person("Sarah", "Lyons", , "sarah@poissonconsulting.ca", role = "ctb",
comment = c(ORCID = "0000-0002-6745-6796")),
person("Duncan", "Kennedy", , "duncan@poissonconsulting.ca", role = "ctb",
comment = c(ORCID = "0009-0001-4880-5751")),
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("Florencia", "D'Andrea", 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"))
Expand All @@ -38,8 +40,7 @@ Description: Species sensitivity distributions are cumulative probability
fit distributions such as the gamma, log-logistic, log-normal 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.
concentrations and proportions are produced by bootstrapping.
License: Apache License (== 2.0) | file LICENSE
URL: https://github.com/bcgov/ssdtools, https://bcgov.github.io/ssdtools/
BugReports: https://github.com/bcgov/ssdtools/issues
Expand All @@ -51,6 +52,7 @@ Imports:
furrr,
generics,
ggplot2,
ggtext,
glue,
goftest,
graphics,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export(ssd_data)
export(ssd_dists)
export(ssd_dists_all)
export(ssd_dists_bcanz)
export(ssd_dists_shiny)
export(ssd_eburrIII3)
export(ssd_ecd)
export(ssd_ecd_data)
Expand All @@ -100,6 +101,7 @@ export(ssd_hp)
export(ssd_hp_bcanz)
export(ssd_is_censored)
export(ssd_label_comma)
export(ssd_label_comma_hc)
export(ssd_licensing_md)
export(ssd_match_moments)
export(ssd_min_pmix)
Expand Down
34 changes: 19 additions & 15 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<!-- NEWS.md is maintained by https://fledge.cynkra.com, contributors should not edit this file -->

# ssdtools 2.1.0.9001

- Fixed equation rendering for vignettes on website.
- Corrected y-axis labels for bimodal plots in distributions vignette from Cumulative Probability to Probability Density.


# ssdtools 2.1.0.9000

- Same as previous version.

# ssdtools 2.2.0

- Added `ssd_label_comma_hc()` function to label numbers with significant digits and comma and offset hazard concentration value if present in breaks.
- Added `ssd_dists_shiny()` to define distributions for use in shiny app.
- For `plot_coord_scale()` function:
- Added `x_limits = NULL` to allow setting of x-axis limits.
- Added `hc_value = NULL` to pass hazard concentration value.
- Restricted `trans` argument to `"identity"`, `"log10"` or "`log`".
- For `ssd_plot()` function:
- Added `text_size` argument.
- Added `theme_classic = FALSE` argument to switch classic theme.
- Soft-deprecated `size` argument for `label_size`.
- Turned off x-axis minor breaks for all plots (for consistency) as HC major break causing multiple minor breaks in `ssd_plot()`.

# ssdtools 2.1.0

- Added `ssd_xxmulti_fitdists()` functions to accept object of class `fitdists`.
- Set `ssd_xxmulti(..., lnorm.weight = 0)` (instead of 1) to avoid incorrect values with `do.call("ssd_xxmulti", c(..., estimates(fits))` if `fits` does not include the log-normal distribution.
- Added `ssd_xxmulti_fitdists()` family of functions (`ssd_rmulti_fitdists()`, `ssd_pmulti_fitdists()` and `ssd_qmulti_fitdists()`) to accept object of class `fitdists`.
- Set `lnorm.weight = 1` instead of `1` in the `ssd_xxmulti()` family of functions (`ssd_rmulti()`, `ssd_pmulti()` and `ssd_qmulti`) to avoid incorrect values with `do.call("ssd_xxmulti", c(..., estimates(fits))` if `fits` does not include the log-normal distribution.


# ssdtools 2.0.0
Expand Down Expand Up @@ -69,7 +72,7 @@ The following functions and arguments were also added:

- `ssd_hp_bcanz()` and `ssd_hp.fitburrlioz()` to get hazard proportions.
- `ssd_pmulti()`, `ssd_qmulti()` and `ssd_rmulti()` for combined mixture distributions.
- `ssd_exx()` functions to get default parameter estimates for distributions.
- `ssd_exx()` family of functions (i.e. `ssd_elnorm()`, `ssd_egamma()` etc) to get default parameter estimates for distributions.
- `ssd_censor_data()` to censor data.
- `npars = c(2L, 5L)` argument to `ssd_dists_bcanz()` to specify the number of parameters.
- `dists = ssd_dists_bcanz()` to `ssd_fit_bcanz()` to allow other packages to modify.
Expand Down Expand Up @@ -155,7 +158,8 @@ ssdtools version 1.0.0 is the first major release of `ssdtools` with some import

## Fitting

An important change to the functionality of `ssd_fit_dists()` was to switch from model fitting using [`fitdistrplus`](https://github.com/lbbe-software/fitdistrplus) to [`TMB`](https://github.com/kaskr/adcomp) which has resulted in improved handling of censored data.
An important change to the functionality of `ssd_fit_dists()` was to switch from model fitting using [`fitdistrplus`](https://github.com/lbbe-software/fitdistrplus) to [`TMB`](https://github.com/kaskr/adcomp) to allow full control over model specification as well as improved handling of censored data.
The change is internal and does not directly affect the user interface.
Although it was hoped that model fitting would be faster this is currently not the case.

As a result of the change the `fitdists` objects returned by `ssd_fit_dists()` from previous versions of `ssdtools` are not compatible with the major release and should be regenerated.
Expand Down Expand Up @@ -251,7 +255,7 @@ The function `ssd_fit_burrlioz()` was added to approximate the behaviour of [Bur
Hazard concentration estimation is performed by `ssd_hc()` (which is wrapped by `predict()`) and hazard protection estimation by `ssd_hp()`.
By default confidence intervals are estimated by parametric bootstrapping.

To reduce the time required for bootstrapping, parallelization was implemented using the [future](https://github.com/HenrikBengtsson/future) package.
To reduce the time required for bootstrapping, parallelization was implemented using the [future](https://github.com/futureverse/future) package.

The following arguments were added to `ssd_hc()` and `ssd_hp()`

Expand Down
8 changes: 2 additions & 6 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

dgompertz_ssd <- function(x, location, shape) {
.Call(`_ssdtools_dgompertz_ssd`, x, location, shape)
}

dgumbel_ssd <- function(x, location, scale) {
.Call(`_ssdtools_dgumbel_ssd`, x, location, scale)
fun_ssd <- function(x) {
.Call(`_ssdtools_fun_ssd`, x)
}

14 changes: 10 additions & 4 deletions R/censor.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# limitations under the License.

#' Censor Data
#'
#' Censors data to a specified range based on the `censoring` argument.
#' The function is useful for creating test data sets.
#'
#' @inheritParams params
#'
Expand All @@ -27,6 +30,10 @@
ssd_censor_data <- function(data, left = "Conc", ..., right = left, censoring = c(0, Inf)) {
.chk_data(data, left, right)
chk_unused(...)
chk_numeric(censoring)
chk_vector(censoring)
chk_length(censoring, 2L)
chk_not_any_na(censoring)

if (left == right) {
right <- "right"
Expand Down Expand Up @@ -63,11 +70,10 @@ censor_data <- function(data, censoring) {
if (!.is_censored(censoring)) {
return(data)
}
chk_not_any_na(censoring)

data$right[data$left < censoring[1]] <- censoring[1]

data$right[data$left < censoring[1]] <- min(censoring)
data$left[data$left < censoring[1]] <- 0
data$left[data$right > censoring[2]] <- censoring[2]
data$left[data$right > censoring[2]] <- max(censoring)
data$right[data$right > censoring[2]] <- Inf
data
}
Expand Down
2 changes: 0 additions & 2 deletions R/censored.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,4 @@ ssd_is_censored.fitdists <- function(x, ...) {
#' @seealso [`ssd_is_censored()`]
is_censored <- function(x) {
lifecycle::deprecate_stop("0.3.7", "is_censored()", "ssd_is_censored()")
chk_s3_class(x, "fitdists")
ssd_is_censored(x)
}
30 changes: 0 additions & 30 deletions R/d.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,3 @@ any_missing <- function(...) {
x <- unlist(list(...))
any(is.na(x) & !is.nan(x))
}

.ddist <- function(dist, x, ..., log) {
inf <- !is.na(x) & is.infinite(x)
x[inf] <- NA_real_
fun <- paste0("d", dist, "_ssd")
d <- mapply(fun, x, ...)
d[mapply(any_missing, x, ...)] <- NA_real_
d[inf] <- -Inf
if (!log) d <- exp(d)
d
}

ddist <- function(dist, x, ..., log = FALSE, .lgt = FALSE) {
if (!length(x)) {
return(numeric(0))
}

if (!.lgt) {
return(.ddist(dist, x = x, ..., log = log))
}

lte <- !is.na(x) & x <= 0
x[lte] <- NA_real_
d <- .ddist(dist, x = log(x), ..., log = FALSE) / x
d[lte] <- 0
if (log) {
return(log(d))
}
d
}
2 changes: 1 addition & 1 deletion R/devtools-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ release_questions <- function() {
c(
"Have you run `data-raw/data-raw.R`?",
"Have you tested using `ssdtests` package?",
"Have you updated `small-sample-bias.pdf`?",
"Have you run `vignettestatic/small-sample-bias.Rmd`?",
"Have you confirmed all images in .Rmd files have alternative text defined using the `fig.alt` argument?",
"Have you confirmed updated Apache 2.0 license at the top of all code files?",
"Have you confirmed update Creative Commons license for all non-code files?"
Expand Down
15 changes: 15 additions & 0 deletions R/dists.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,18 @@ ssd_dists <- function(bcanz = NULL, tails = NULL, npars = 2:5) {
ssd_dists_all <- function() {
ssd_dists(bcanz = NULL, tails = NULL, npars = 2:5)
}

#' All Shiny Species Sensitivity Distributions
#'
#' Gets a character vector of the names of all the available distributions
#' in the shinyssdtools.
#'
#' @return A unique, sorted character vector of the distributions.
#' @family dists
#' @export
#'
#' @examples
#' ssd_dists_shiny()
ssd_dists_shiny <- function() {
ssd_dists(bcanz = NULL, tails = TRUE, npars = 2:5)
}
33 changes: 10 additions & 23 deletions R/ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ ssd_pal <- function() {
}

#' Discrete color-blind scale for SSD Plots
#'
#' The functions were designed for coloring different groups in a plot of SSD data.
#'
#' @param ... Arguments passed to [ggplot2::discrete_scale()].
#' @family ggplot
#' @export
#' @examples
#' # Use the color-blind palette for a SSD plot
#' ssd_plot(ssddata::ccme_boron, boron_pred, shape = "Group", color = "Group") +
#' scale_colour_ssd()
scale_colour_ssd <- function(...) {
Expand All @@ -52,6 +55,12 @@ scale_color_ssd <- function(...) {

#' @describeIn scale_colour_ssd Discrete color-blind scale for SSD Plots
#' @export
#' @examples
#' # Use the color-blind palette for a histogram of concentrations
#' ggplot2::ggplot(ssddata::ccme_boron, ggplot2::aes(x = Species, y = Conc, fill = Group)) +
#' ggplot2::geom_col() +
#' scale_fill_ssd() +
#' ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust = 1))
scale_fill_ssd <- function(...) {
discrete_scale("fill", palette = ssd_pal(), ...)
}
Expand Down Expand Up @@ -192,16 +201,11 @@ geom_xribbon <- function(mapping = NULL,
#' Species Sensitivity Data Points
#' `r lifecycle::badge('deprecated')`
#'
#' `geom_ssd()` has been deprecated for `geom_ssdpoint()`.
#' Deprecated for `geom_ssdpoint()`.
#'
#' @inheritParams ggplot2::layer
#' @inheritParams ggplot2::geom_point
#' @export
#' @examples
#' \dontrun{
#' ggplot2::ggplot(ssddata::ccme_boron, ggplot2::aes(x = Conc)) +
#' geom_ssd()
#' }
geom_ssd <- function(mapping = NULL,
data = NULL,
stat = "ssdpoint",
Expand All @@ -211,12 +215,6 @@ geom_ssd <- function(mapping = NULL,
show.legend = NA,
inherit.aes = TRUE) {
lifecycle::deprecate_stop("0.3.5", "geom_ssd()", "geom_ssdpoint()")

geom_ssdpoint(
mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, show.legend = show.legend,
inherit.aes = inherit.aes, ...
)
}

#' Plot Species Sensitivity Data
Expand All @@ -229,11 +227,6 @@ geom_ssd <- function(mapping = NULL,
#' @seealso [`geom_ssdpoint()`]
#' @family ggplot2
#' @export
#' @examples
#' \dontrun{
#' ggplot2::ggplot(ssddata::ccme_boron, ggplot2::aes(x = Conc)) +
#' stat_ssd()
#' }
stat_ssd <- function(mapping = NULL,
data = NULL,
geom = "point",
Expand All @@ -243,10 +236,4 @@ stat_ssd <- function(mapping = NULL,
show.legend = NA,
inherit.aes = TRUE) {
lifecycle::deprecate_stop("0.3.5", "stat_ssd()")

layer(
stat = StatSsdpoint, data = data, mapping = mapping, geom = geom,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...)
)
}
Loading

0 comments on commit 4011ab2

Please sign in to comment.