Skip to content

Commit

Permalink
Merge pull request #363 from poissonconsulting/dev
Browse files Browse the repository at this point in the history
- Combine `multi_ci = TRUE` and `weight = TRUE` into `ci_method = "weighted_samples"
  • Loading branch information
joethorley authored Apr 24, 2024
2 parents cb0ef94 + 2d4d383 commit 2ba1e6e
Show file tree
Hide file tree
Showing 33 changed files with 462 additions and 422 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export(ssd_hc)
export(ssd_hc_bcanz)
export(ssd_hc_burrlioz)
export(ssd_hp)
export(ssd_hp_bcanz)
export(ssd_is_censored)
export(ssd_match_moments)
export(ssd_pal)
Expand Down
41 changes: 27 additions & 14 deletions R/bcanz.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ ssd_dists_bcanz <- function(npars = c(2L, 5L)) {
ssd_fit_bcanz <- function(data, left = "Conc", dists = ssd_dists_bcanz()) {
ssd_fit_dists(data,
left = left,
dists = dists,
nrow = 6L,
rescale = FALSE,
reweight = FALSE,
computable = TRUE,
at_boundary_ok = FALSE,
min_pmix = 0
dists = dists
)
}

Expand All @@ -66,7 +60,7 @@ ssd_fit_bcanz <- function(data, left = "Conc", dists = ssd_dists_bcanz()) {
#' Gets hazard concentrations with confidence intervals that protect
#' 1, 5, 10 and 20% of species using settings adopted by
#' BC, Canada, Australia and New Zealand for official guidelines.
#' This function can take several minutes to run with required 10,000 iterations.
#' This function can take several minutes to run with recommended 10,000 iterations.
#'
#' @inheritParams params
#' @return A tibble of corresponding hazard concentrations.
Expand All @@ -76,15 +70,34 @@ ssd_fit_bcanz <- function(data, left = "Conc", dists = ssd_dists_bcanz()) {
#' @examples
#' fits <- ssd_fit_bcanz(ssddata::ccme_boron)
#' ssd_hc_bcanz(fits, nboot = 100)
ssd_hc_bcanz <- function(x, nboot = 10000, delta = 10, min_pboot = 0.95) {
ssd_hc_bcanz <- function(x, nboot = 10000, min_pboot = 0.95) {
ssd_hc(x,
proportion = c(0.01, 0.05, 0.1, 0.2),
ci = TRUE,
level = 0.95,
nboot = nboot,
average = TRUE,
delta = delta,
min_pboot = min_pboot,
parametric = TRUE
min_pboot = min_pboot
)
}

#' BCANZ Hazard Proportion
#'
#' Gets proportion of species affected at specified concentration(s)
#' using settings adopted by BC, Canada, Australia and New Zealand for official guidelines.
#' This function can take several minutes to run with recommended 10,000 iterations.
#'
#' @inheritParams params
#' @return A tibble of corresponding hazard concentrations.
#' @seealso [`ssd_hp()`].
#' @family BCANZ
#' @export
#' @examples
#' fits <- ssd_fit_bcanz(ssddata::ccme_boron)
#' ssd_hp_bcanz(fits, nboot = 100)
ssd_hp_bcanz <- function(x, conc = 1, nboot = 10000, min_pboot = 0.95) {
ssd_hp(x,
conc = conc,
ci = TRUE,
nboot = nboot,
min_pboot = min_pboot
)
}
10 changes: 7 additions & 3 deletions R/hc.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ ssd_hc.fitdists <- function(
nboot = 1000,
min_pboot = 0.95,
multi_est = TRUE,
multi_ci = TRUE,
weighted = TRUE,
ci_method = "weighted_samples",
parametric = TRUE,
delta = 9.21,
samples = FALSE,
Expand All @@ -146,6 +145,11 @@ ssd_hc.fitdists <- function(
chk_vector(proportion)
chk_numeric(proportion)
chk_range(proportion)
chk_string(ci_method)
chk_subset(ci_method, c("weighted_samples", "weighted_arithmetic", "multi_free", "multi_fixed"))

fix_weights <- ci_method %in% c("weighted_samples", "multi_fixed")
multi_ci <- ci_method %in% c("multi_free", "multi_fixed")

hcp <- ssd_hcp_fitdists(
x = x,
Expand All @@ -159,7 +163,7 @@ ssd_hc.fitdists <- function(
min_pboot = min_pboot,
parametric = parametric,
multi_ci = multi_ci,
fix_weights = weighted,
fix_weights = fix_weights,
control = control,
samples = samples,
save_to = save_to,
Expand Down
13 changes: 9 additions & 4 deletions R/hp.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ ssd_hp.fitdists <- function(
nboot = 1000,
min_pboot = 0.95,
multi_est = TRUE,
multi_ci = TRUE,
weighted = TRUE,
ci_method = "weighted_samples",
parametric = TRUE,
delta = 9.21,
samples = FALSE,
Expand All @@ -54,7 +53,13 @@ ssd_hp.fitdists <- function(

chk_vector(conc)
chk_numeric(conc)
chk_subset(ci_method, c("weighted_samples", "weighted_arithmetic", "multi_free", "multi_fixed"))

chk_unused(...)


fix_weights <- ci_method %in% c("weighted_samples", "multi_fixed")
multi_ci <- ci_method %in% c("multi_free", "multi_fixed")

hcp <- ssd_hcp_fitdists(
x = x,
Expand All @@ -68,11 +73,11 @@ ssd_hp.fitdists <- function(
min_pboot = min_pboot,
parametric = parametric,
multi_ci = multi_ci,
fix_weights = fix_weights,
control = control,
save_to = save_to,
samples = samples,
hc = FALSE,
fix_weights = weighted,
hc = FALSE
)
hcp <- dplyr::rename(hcp, conc = "value")
hcp
Expand Down
7 changes: 2 additions & 5 deletions R/params.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
#' @param min_pmix A number between 0 and 0.5 specifying the minimum proportion in mixture models.
#' @param npars A whole numeric vector specifying which distributions to include based on the number of parameters.
#' @param all_estimates A flag specifying whether to calculate estimates for all implemented distributions.
#' @param multi_ci A flag specifying whether to treat the distributions as constituting a single distribution which is now the recommended approach (as opposed to taking the mean) when calculating model averaged confidence intervals.
#' @param ci_method A string specifying which method to use for estimating the bootstrap values.
#' Possible values are "multi_free" and "multi_fixed" which treat the distributions as constituting a single distribution but differ in whether the model weights are fixed and "weighted_samples" and "weighted_arithmetic" take bootstrap samples from each distribution proportional to its weight versus calculating the weighted arithmetic means of the lower and upper confidence limits.
#' @param multi_est A flag specifying whether to treat the distributions as constituting a single distribution (as opposed to taking the mean) when calculating model averaged estimates.
#' @param na.rm A flag specifying whether to silently remove missing values or
#' remove them with a warning.
Expand Down Expand Up @@ -105,10 +106,6 @@
#' @param tails A flag or NULL specifying whether to only include distributions with both tails.
#' @param trans A string which transformation to use by default `"log10"`.
#' @param weight A string of the numeric column in data with positive weights less than or equal to 1,000 or NULL.
#' @param weighted A flag which specifies whether to use the original model weights (as opposed to re-estimating for each bootstrap sample) unless `multi_ci = FALSE` in which case it specifies
#' whether to take bootstrap samples from each distribution proportional to
#' its weight versus calculating the weighted arithmetic means of the lower
#' and upper confidence limits.
#' @param x The object.
#' @param xbreaks The x-axis breaks as one of:
#' - `NULL` for no breaks
Expand Down
7 changes: 2 additions & 5 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ predict.fitdists <- function(
nboot = 1000,
min_pboot = 0.95,
multi_est = TRUE,
multi_ci = TRUE,
weighted = TRUE,
ci_method = "weighted_samples",
parametric = TRUE,
delta = 9.21,
control = NULL,
Expand Down Expand Up @@ -69,9 +68,7 @@ predict.fitdists <- function(
average = average,
delta = delta,
parametric = parametric,
multi_ci = multi_ci,
multi_est = multi_est,
weighted = weighted,
ci_method = ci_method,
control = control
)
}
Expand Down
64 changes: 32 additions & 32 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ template:
authors:
Joe Thorley:
href: "https://github.com/joethorley"
Carl Schwarz:
href: "https://www.sfu.ca/stat-actsci/department/profiles/carl-schwarz.html"
David Fox:
href: "https://training.ecotox.science/who-we-are/"
Rebecca Fisher:
href: "https://www.aims.gov.au/about/our-people/dr-rebecca-fisher"
Angeline Tillmans:
href: "https://www.linkedin.com/in/angeline-tillmanns-5b7999a/"
David Fox:
href: "https://training.ecotox.science/who-we-are/"
Carl Schwarz:
href: "https://www.sfu.ca/stat-actsci/department/profiles/carl-schwarz.html"
Province of British Columbia:
href: "https://www2.gov.bc.ca/"
Environment and Climate Change Canada:
Expand All @@ -21,55 +19,42 @@ authors:
destination: docs

reference:
- title: Information
desc: Data frames of information
contents:
- '`boron_pred`'
- '`dist_data`'
- title: Distribution Names
desc: Functions that return character vectors of distribution names
contents:
- '`ssd_dists`'
- '`ssd_dists_all`'
- '`ssd_dists_bcanz`'
- title: Distributional Functions
desc: Distribution, quantile, random functions
contents:
- '`ssd_p`'
- '`ssd_q`'
- '`ssd_r`'
- '`ssd_e`'
- title: Fit
desc: Functions that fit distributions to data
contents:
- '`ssd_fit_dists`'
- '`ssd_fit_bcanz`'
- '`ssd_fit_burrlioz`'
- '`ssd_fit_dists`'
- title: Hazard Concentrations
desc: Functions that calculate hazard concentrations
contents:
- '`ssd_hc`'
- '`ssd_hc_bcanz`'
- '`ssd_wqg_bc`'
- '`ssd_wqg_burrlioz`'
- title: Hazard Proportions
desc: Functions that calculate hazard proportions
contents:
- '`ssd_hp`'
- '`ssd_hp_bcanz`'
- title: Manipulate Fits
desc: Functions that manipulate fits of distributions
contents:
- '`augment.fitdists`'
- '`coef.fitdists`'
- '`estimates.fitdists`'
- '`glance.fitdists`'
- '`is.fitdists`'
- '`predict.fitburrlioz`'
- '`predict.fitdists`'
- '`ssd_ecd`'
- '`ssd_ecd_data`'
- '`ssd_exposure`'
- '`ssd_gof`'
- '`ssd_hp`'
- '`ssd_match_moments`'
- '`subset.fitdists`'
- '`tidy.fitdists`'
- title: Hazard Concentrations
desc: Functions that calculate hazard concentrations
contents:
- '`ssd_hc`'
- '`ssd_hc_bcanz`'
- '`ssd_wqg_bc`'
- '`ssd_wqg_burrlioz`'
- title: Plots
desc: Functions to Generate Plots
contents:
Expand All @@ -84,14 +69,29 @@ reference:
- '`ssd_plot_cdf`'
- '`ssd_plot_data`'
- '`ssdtools-ggproto`'
- title: Distributional Functions
desc: Distribution, quantile, random functions
contents:
- '`ssd_p`'
- '`ssd_q`'
- '`ssd_r`'
- '`ssd_e`'
- title: Miscellaneous
desc: Miscellaneous functions and data
contents:
- '`boron_pred`'
- '`comma_signif`'
- '`dist_data`'
- '`is.fitdists`'
- '`licensing_md`'
- '`npars`'
- '`ssd_data`'
- '`ssd_ecd`'
- '`ssd_ecd_data`'
- '`ssd_exposure`'
- '`ssd_fit_dists`'
- '`ssd_is_censored`'
- '`ssd_match_moments`'
- '`ssd_sort_data`'
- '`pearson1000`'
- title: Deprecated
Expand Down
2 changes: 1 addition & 1 deletion data-raw/data-raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ use_data(dist_data, overwrite = TRUE)
fits <- ssd_fit_dists(ssddata::ccme_boron)

set.seed(99)
boron_pred <- predict(fits, ci = TRUE, multi_ci = FALSE)
boron_pred <- predict(fits, ci = TRUE, ci_method = "weighted bootstrap")
use_data(boron_pred, overwrite = TRUE)
8 changes: 2 additions & 6 deletions man/params.Rd

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

11 changes: 3 additions & 8 deletions man/predict.fitdists.Rd

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

3 changes: 2 additions & 1 deletion man/ssd_fit_bcanz.Rd

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

11 changes: 3 additions & 8 deletions man/ssd_hc.Rd

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

Loading

0 comments on commit 2ba1e6e

Please sign in to comment.