Skip to content

Commit

Permalink
dht2 now fails when >1 level of stratification is specified, per #46
Browse files Browse the repository at this point in the history
until proper fix is implemented
  • Loading branch information
David Lawrence Miller committed May 10, 2020
1 parent 8ab3899 commit 2a423ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion R/dht2.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Once a detection function is fitted to data, this function can be used to compute abundance estimates over required areas. The function also allows for stratification and variance estimation via various schemes (see below).
#'
#' @param ddf model fitted by \code{\link[Distance]{ds}} or \code{\link[mrds]{ddf}}
#' @param strat_formula a formula giving the stratification structure (see "Stratification" below)
#' @param strat_formula a formula giving the stratification structure (see "Stratification" below). Currently only one level of stratification is supported.
#' @param observations \code{data.frame} to link detection function data (indexed by \code{object} column IDs) to the transects (indexed by \code{Sample.Label} column IDs). See "Data" below.
#' @param transects \code{data.frame} with information about samples (points or line transects). See "Data" below.
#' @param geo_strat \code{data.frame} with information about any geographical stratification. See "Data" below.
Expand Down Expand Up @@ -119,6 +119,11 @@ dht2 <- function(ddf, observations=NULL, transects=NULL, geo_strat=NULL,
# what are the stratum labels specicied in strat_formula?
stratum_labels <- attr(terms(strat_formula), "term.labels")

# TODO: currently break if >1 stratum is defined
if(length(stratum_labels) > 1){
stop("Only one level of stratification is currently supported")
}

if(!is.null(observations) & !is.null(transects)){
if(!is.null(geo_strat)){
# what if there were as.factor()s in the formula?
Expand Down
2 changes: 1 addition & 1 deletion man/dht2.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test_dht2.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ test_that("as.factor works in formula",{
test_that("error thrown if stratum name doesn't exist in flatfile",{

expect_error(dht2(ds.dht.model, flatfile=ff,
strat_formula=~year+boop),
"Column\\(s\\): year, boop not in \\`flatfile\\`")
strat_formula=~boop),
"Column\\(s\\): boop not in \\`flatfile\\`")

})

Expand Down

0 comments on commit 2a423ab

Please sign in to comment.