From 32faa315fea26656eea3432b1ea4f2b55474673a Mon Sep 17 00:00:00 2001 From: Len Thomas Date: Thu, 16 Oct 2025 22:36:35 +0100 Subject: [PATCH 1/3] Added conf_level argument to ds - issue 215 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/ds.R | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 91717e8..0a8bde4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ Description: A simple way of fitting detection functions to distance sampling Horvitz-Thompson-like estimator) if survey area information is provided. See Miller et al. (2019) for more information on methods and for example analyses. -Version: 2.0.1 +Version: 2.0.1.9000 URL: https://github.com/DistanceDevelopment/Distance/ BugReports: https://github.com/DistanceDevelopment/Distance/issues Language: en-GB diff --git a/NEWS.md b/NEWS.md index 597d381..290d2d3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# Distance 2.0.2 + +* Added argument conf_level to ds so users can specify level of confidence in computing confidence intervals (Issue #215) + # Distance 2.0.1 * Fixes issue with print dht2 when multipliers are a data.frame (Issue #179) diff --git a/R/ds.R b/R/ds.R index 346a8bc..a2f20d8 100644 --- a/R/ds.R +++ b/R/ds.R @@ -130,6 +130,7 @@ #' @param winebin If you are trying to use our MCDS.exe optimizer on a #' non-windows system then you may need to specify the winebin. Please #' see [`mcds_dot_exe`][mrds::mcds_dot_exe] for more details. +#' @param conf_level level of confidence used in computations of confidence interval width: default 0.95, must be between 0 and 1 #' @param dht.group deprecated, see same argument with underscore, above. #' @param region.table deprecated, see same argument with underscore, above. #' @param sample.table deprecated, see same argument with underscore, above. @@ -340,6 +341,7 @@ ds <- function(data, truncation=ifelse(is.null(data$distend), initial_values=NULL, max_adjustments=5, er_method=2, dht_se=TRUE, optimizer = "both", winebin = NULL, + conf_level = 0.95, # deprecated below here: dht.group, region.table, @@ -531,6 +533,9 @@ ds <- function(data, truncation=ifelse(is.null(data$distend), stop("Cannot supply initial values when using AIC term selection") } + # check conf_level + if(!((conf_level >= 0) | (conf_level <= 1))) stop("Option conf_level is not in the range 0-1") + ### Actually fit some models here # construct the meta data object... @@ -731,7 +736,8 @@ ds <- function(data, truncation=ifelse(is.null(data$distend), dht_options <- list(group = dht_group, ervar = er_var, varflag = er_method, - convert.units = convert_units) + convert.units = convert_units, + ci.width = conf_level) # if no obs_table if(is.null(obs_table)){ From 5088d5bfa75c9d913f0efefed9dd77b6bd5635e0 Mon Sep 17 00:00:00 2001 From: Len Thomas Date: Fri, 17 Oct 2025 12:02:21 +0100 Subject: [PATCH 2/3] Added alpha argument to ds alpha is complement of conf_level argument --- R/ds.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/ds.R b/R/ds.R index a2f20d8..d493a27 100644 --- a/R/ds.R +++ b/R/ds.R @@ -130,7 +130,11 @@ #' @param winebin If you are trying to use our MCDS.exe optimizer on a #' non-windows system then you may need to specify the winebin. Please #' see [`mcds_dot_exe`][mrds::mcds_dot_exe] for more details. -#' @param conf_level level of confidence used in computations of confidence interval width: default 0.95, must be between 0 and 1 +#' @param conf_level level of confidence used in computations of confidence interval width: +#' default 0.95, must be between 0 and 1 +#' @param alpha provides an alternative way to specify `conf_level`. If `alpha` is specified +#' then `conf_level` is set to 1-`alpha`. (This takes precedence over whatever value is given +#' to `conf_level`.) #' @param dht.group deprecated, see same argument with underscore, above. #' @param region.table deprecated, see same argument with underscore, above. #' @param sample.table deprecated, see same argument with underscore, above. @@ -342,6 +346,7 @@ ds <- function(data, truncation=ifelse(is.null(data$distend), optimizer = "both", winebin = NULL, conf_level = 0.95, + alpha, # deprecated below here: dht.group, region.table, @@ -535,6 +540,11 @@ ds <- function(data, truncation=ifelse(is.null(data$distend), # check conf_level if(!((conf_level >= 0) | (conf_level <= 1))) stop("Option conf_level is not in the range 0-1") + # set conf_level if alpha specified + if(!missing(alpha)){ + if(!((alpha >= 0) | (alpha <= 1))) stop("Option alpha is not in the range 0-1") + conf_level <- 1 - alpha + } ### Actually fit some models here From d022e7c46482d4229a28916a54199ec987757afd Mon Sep 17 00:00:00 2001 From: Len Thomas Date: Fri, 17 Oct 2025 12:03:29 +0100 Subject: [PATCH 3/3] Updated News --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 290d2d3..dd69476 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # Distance 2.0.2 -* Added argument conf_level to ds so users can specify level of confidence in computing confidence intervals (Issue #215) +* Added arguments conf_level and alpha to ds so users can specify level of confidence in computing confidence intervals (Issue #215) # Distance 2.0.1