diff --git a/DESCRIPTION b/DESCRIPTION index abe74b0..e59676a 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.0.9003 +Version: 2.0.0.9004 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 3397245..eb66c9c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,8 @@ * Fixes issue with print dht2 when multipliers are a data.frame (Issue #179) * Fixes bug when including a uniform with no adjustment terms in the summarize_ds_models function (Issue #180) -* Users to pass a list of models to summarize_ds_models rather than passing them individually. (Issue #) +* Users to pass a list of models to summarize_ds_models rather than passing them individually. (Issue #149) +* Truncation distances greater than the largest cutpoint value for binned data are no longer permitted as these cause fitting issues. (Issue #175) # Distance 2.0.0 diff --git a/R/get_truncation.R b/R/get_truncation.R index 37dc525..7662029 100644 --- a/R/get_truncation.R +++ b/R/get_truncation.R @@ -54,5 +54,15 @@ get_truncation <- function(truncation, cutpoints, data){ stop("Truncation must be supplied as a single number/string or a list with elements \"left\" and \"right\".") } } + + # Final check that truncation is not greater than largest cutpoint + if(!is.null(cutpoints)){ + if(width > cutpoints[length(cutpoints)]){ + warning(paste("Truncation width is greater than the largest bin distance, re-setting truncation to be largest cutpoint value: ", cutpoints[length(cutpoints)], sep = ""), immediate. = TRUE, call. = FALSE) + # Make truncation largest cutpoint + width <- cutpoints[length(cutpoints)] + } + } + list(left=left, width=width) } diff --git a/R/summarize_ds_models.R b/R/summarize_ds_models.R index cb05f88..56558b4 100644 --- a/R/summarize_ds_models.R +++ b/R/summarize_ds_models.R @@ -9,7 +9,9 @@ #' the resulting `data.frame` in R, you may wish to rename the columns for #' ease of access. #' -#' @param ... models to be summarised +#' @param ... models to be summarised (to be deprecated) +#' @param models a named list of models to be summarised. If the list is not +#' named then default names of 'model 1', 'model 2' etc. are used. #' @param sort column to sort by (default `"AIC"`) #' @param output should the output be given in `"latex"` compatible format #' or as `"plain"` text? diff --git a/man/summarize_ds_models.Rd b/man/summarize_ds_models.Rd index 27dffbf..b92975a 100644 --- a/man/summarize_ds_models.Rd +++ b/man/summarize_ds_models.Rd @@ -13,7 +13,10 @@ summarize_ds_models( ) } \arguments{ -\item{...}{models to be summarised} +\item{...}{models to be summarised (to be deprecated)} + +\item{models}{a named list of models to be summarised. If the list is not +named then default names of 'model 1', 'model 2' etc. are used.} \item{sort}{column to sort by (default \code{"AIC"})} diff --git a/tests/testthat/test_ds.R b/tests/testthat/test_ds.R index 7ce90f3..2d830ab 100644 --- a/tests/testthat/test_ds.R +++ b/tests/testthat/test_ds.R @@ -56,6 +56,12 @@ test_that("binning works", { # first cutpoint not zero when no left truncation expect_error(ds(egdata,4,cutpoints=c(2,3,4)), "The first cutpoint must be 0 or the left truncation distance!") + + expect_warning(ds.obj <- ds(egdata,list(left = 2, right = 5),cutpoints=c(2,3,4)), + "Truncation width is greater than the largest bin distance, re-setting truncation to be largest cutpoint value: 4") + + # Check that the width has been modified correctly + expect_equal(ds.obj$ddf$meta.data$width, 4) tst_distances <- data.frame(distance = c(0, 0, 0, 10, 50, 70, 110)) expect_equal(as.vector(table(create_bins(tst_distances, diff --git a/tests/testthat/test_summarize.R b/tests/testthat/test_summarize.R index 3b41f5d..aab6d94 100644 --- a/tests/testthat/test_summarize.R +++ b/tests/testthat/test_summarize.R @@ -85,4 +85,8 @@ test_that("Passing in models via a list",{ test3 <- summarize_ds_models(list(ds.model, ds.model.cos, ds.model.hr)) expect_identical(test1[,2:7], test3[,2:7]) + expect_identical(test3[,1], c("\\texttt{model 1}", "\\texttt{model 2}", "\\texttt{model 3}")) + + test4 <- summarize_ds_models(list(m1 = ds.model, m2 = ds.model.cos, m3 = ds.model.hr)) + expect_identical(test4[,1], c("\\texttt{m1}", "\\texttt{m2}", "\\texttt{m3}")) })