Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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) <doi:10.18637/jss.v089.i01> for more information on
methods and <https://examples.distancesampling.org/> 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
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions R/get_truncation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion R/summarize_ds_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 4 additions & 1 deletion man/summarize_ds_models.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/test_ds.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))
})
Loading