Skip to content

Commit

Permalink
Merge pull request #362 from poissonconsulting/dev
Browse files Browse the repository at this point in the history
- Add `npars` argument to `ssd_dists_bcanz()`.
  • Loading branch information
joethorley committed Apr 10, 2024
2 parents 8c6cb7a + b83a8ab commit cb0ef94
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
44 changes: 26 additions & 18 deletions R/bcanz.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@
#' Gets a character vector of the names of the distributions
#' adopted by BC, Canada, Australia and New Zealand for official guidelines.
#'
#' @inheritParams params
#' @return A unique, sorted character vector of the distributions.
#' @seealso [`ssd_dists()`]
#' @family dists BCANZ
#' @export
#'
#' @examples
#' ssd_dists_bcanz()
ssd_dists_bcanz <- function() {
ssd_dists(bcanz = TRUE)
#' ssd_dists_bcanz(npars = 2)
ssd_dists_bcanz <- function(npars = c(2L, 5L)) {
chk_whole_numeric(npars)
chk_not_any_na(npars)
chk_unique(npars)
check_dim(npars, values = 1:2)
chk_subset(npars, c(2L, 5L))

ssd_dists(bcanz = TRUE, npars = npars)
}

#' Fit BCANZ Distributions
Expand All @@ -42,14 +50,14 @@ ssd_dists_bcanz <- function() {
#' ssd_fit_bcanz(ssddata::ccme_boron)
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
left = left,
dists = dists,
nrow = 6L,
rescale = FALSE,
reweight = FALSE,
computable = TRUE,
at_boundary_ok = FALSE,
min_pmix = 0
)
}

Expand All @@ -70,13 +78,13 @@ ssd_fit_bcanz <- function(data, left = "Conc", dists = ssd_dists_bcanz()) {
#' ssd_hc_bcanz(fits, nboot = 100)
ssd_hc_bcanz <- function(x, nboot = 10000, delta = 10, 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
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
)
}
10 changes: 4 additions & 6 deletions R/dists.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#'
#' Gets a character vector of the names of the available distributions.
#'
#' @param bcanz A flag or NULL specifying whether to only include distributions in the set that is approved by BC, Canada, Australia and New Zealand for official guidelines.
#' @param tails A flag or NULL specifying whether to only include distributions with both tails.
#' @param npars A whole numeric vector specifying which distributions to include based on the number of parameters.
#' @inheritParams params
#' @return A unique, sorted character vector of the distributions.
#' @family dists
#' @export
Expand All @@ -31,11 +29,11 @@
ssd_dists <- function(bcanz = NULL, tails = NULL, npars = 2:5) {
chk_null_or(bcanz, vld = vld_flag)
chk_null_or(tails, vld = vld_flag)

chk_whole_numeric(npars)
chk_not_any_na(npars)
chk_range(npars, c(2L, 5L))

dists <- ssdtools::dist_data
if (!is.null(bcanz)) {
dists <- dists[dists$bcanz == bcanz, ]
Expand All @@ -44,7 +42,7 @@ ssd_dists <- function(bcanz = NULL, tails = NULL, npars = 2:5) {
dists <- dists[dists$tails == tails, ]
}
dists <- dists[dists$npars %in% npars, ]

dists$dist
}

Expand Down
3 changes: 3 additions & 0 deletions R/params.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @param at_boundary_ok A flag specifying whether a model with one or more
#' parameters at the boundary should be considered to have converged (default = FALSE).
#' @param average A flag specifying whether to provide model averaged values as opposed to a value for each distribution.
#' @param bcanz A flag or NULL specifying whether to only include distributions in the set that is approved by BC, Canada, Australia and New Zealand for official guidelines.
#' @param breaks A character vector
#' @param bounds A named non-negative numeric vector of the left and right bounds for
#' uncensored missing (0 and Inf) data in terms of the orders of magnitude
Expand Down Expand Up @@ -59,6 +60,7 @@
#' proportion of bootstrap samples that must successfully fit (return a likelihood)
#' to report the confidence intervals.
#' @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 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.
Expand Down Expand Up @@ -100,6 +102,7 @@
#' @param shift_x The value to multiply the label x values by (after adding `add_x`).
#' @param silent A flag indicating whether fits should fail silently.
#' @param size A number for the size of the labels.
#' @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
Expand Down
6 changes: 6 additions & 0 deletions man/params.Rd

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

6 changes: 5 additions & 1 deletion man/ssd_dists_bcanz.Rd

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

3 changes: 2 additions & 1 deletion tests/testthat/test-dists.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ test_that("dists 5 pars", {
})

test_that("dists bcanz", {
expect_identical(ssd_dists(bcanz = TRUE), ssd_dists_bcanz())
expect_identical(ssd_dists_bcanz(), ssd_dists(bcanz = TRUE))
expect_identical(ssd_dists_bcanz(npars = 2L), c("gamma", "lgumbel", "llogis", "lnorm", "weibull"))
})

0 comments on commit cb0ef94

Please sign in to comment.