Skip to content

Commit

Permalink
Merge branch 'master' into make_pkgdown
Browse files Browse the repository at this point in the history
  • Loading branch information
LHMarshall committed Nov 6, 2024
2 parents 51c34e9 + c1e343a commit c652894
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 31 deletions.
24 changes: 10 additions & 14 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ Package: Distance
License: GPL (>= 2)
Title: Distance Sampling Detection Function and Abundance Estimation
LazyLoad: yes
Authors@R:
c(person(given="David Laurence",
family="Miller",
role="aut"),
person(given="T.J.",
family="Clark-Wolf",
role="aut"),
person(given="Laura",
family="Marshall",
role="cre",
email="[email protected]"))
Authors@R: c(
person("Laura", "Marshall", email = "[email protected]" , role = "cre"),
person("David", "Miller", email = "[email protected]", role = "aut"),
person("T.J.", "Clark-Wolf", role = "aut"),
person("Len", "Thomas", email = "[email protected]", role = "ctb"),
person("Jeff", "Laake", role = "ctb"),
person("Eric", "Rexstad", email = "[email protected]", role = "rev"))
Description: A simple way of fitting detection functions to distance sampling
data for both line and point transects. Adjustment term selection, left and
right truncation as well as monotonicity constraints and binning are
supported. Abundance and density estimates can also be calculated (via a
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: 1.0.9
Version: 2.0.0
URL: https://github.com/DistanceDevelopment/Distance/
BugReports: https://github.com/DistanceDevelopment/Distance/issues
Language: en-GB
Depends:
R (>= 3.5.0),
mrds (>= 2.3.0)
mrds (>= 3.0.0)
Imports:
dplyr,
methods,
Expand All @@ -44,4 +40,4 @@ Suggests:
readxl
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Distance 2.0.0

* Requires mrds 3.0.0. mrds is called by ds for fitting detection functions. In mrds there has been a change of optimizer used for CDS detection functions - a constraint solver slsqp now used. This removes the need for external optimizer MCDS.exe in most cases. Other minor changes to optimization have been implemented to improve reliability (see NEWS file of mrds for more info).
* New argument mono_method added so that the previous constraint solver (solnp) can still be used. MCDS.exe is also still available if needed.

# Distance 1.0.9

* Changed the default encounter rate estimator for point transect surveys from P3 to P2. (Issue #138)
Expand Down
4 changes: 3 additions & 1 deletion R/Distance-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#'
#' For help with distance sampling and this package, there is a Google Group
#' <https://groups.google.com/forum/#!forum/distance-sampling>.
#'
#' Bugs can be reported at <https://github.com/DistanceDevelopment/Distance/issues>.
#'
#' @name Distance-package
#' @import mrds
#' @aliases Distance-package Distance
#' @docType package
#' @author David L. Miller <dave@@ninepointeightone.net>
#' @references
#' "_PACKAGE"
#'
#' Key References:
#'
Expand Down
17 changes: 11 additions & 6 deletions R/ds.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
#' @param method optimization method to use (any method usable by
#' [`optim`][stats::optim] or [`optimx`][optimx::optimx]). Defaults to
#' `"nlminb"`.
#' @param mono_method optimization method to use when monotonicity is enforced.
#' Can be either `slsqp` or `solnp`. Defaults to `slsqp`.
#' @param debug_level print debugging output. `0`=none, `1-3` increasing levels
#' of debugging output.
#' @param quiet suppress non-essential messages (useful for bootstraps etc).
Expand Down Expand Up @@ -255,9 +257,9 @@
#' density estimates made with the `Area` column present.
#'
#' @author David L. Miller
#' @seealso [`flatfile`][flatfile], [`AIC.ds`][AIC.ds], [`ds.gof`][ds.gof],
#' [`p_dist_table`][p_dist_table], [`plot.ds`][plot.ds],
#' [`add_df_covar_line`][add_df_covar_line]
#' @seealso \code{\link{flatfile}}, \code{\link[mrds]{AIC.ds}},
#' \code{\link{ds.gof}}, \code{\link{p_dist_table}},
#' \code{\link[mrds]{plot.ds}}, \code{\link{add_df_covar_line}}
#' @export
#'
#' @importFrom stats quantile as.formula
Expand Down Expand Up @@ -334,7 +336,9 @@ ds <- function(data, truncation=ifelse(is.null(cutpoints),
monotonicity=ifelse(formula==~1, "strict", "none"),
region_table=NULL, sample_table=NULL, obs_table=NULL,
convert_units=1, er_var=ifelse(transect=="line", "R2", "P2"),
method="nlminb", quiet=FALSE, debug_level=0,
method="nlminb",
mono_method = "slsqp", # FTP: new slot to specify the constraint R solver
quiet=FALSE, debug_level=0,
initial_values=NULL, max_adjustments=5, er_method=2, dht_se=TRUE,
optimizer = "both",
winebin = NULL,
Expand Down Expand Up @@ -521,6 +525,7 @@ ds <- function(data, truncation=ifelse(is.null(cutpoints),

# set up the control options
control <- list(optimx.method=method, showit=debug_level,
mono.method = mono_method, ## FTP: again, this is needed
optimizer = optimizer, winebin = winebin)

# if initial values were supplied, pass them on
Expand Down Expand Up @@ -719,8 +724,8 @@ ds <- function(data, truncation=ifelse(is.null(cutpoints),
}

# check to see if resulting function is monotonic
mono.chk <- mrds::check.mono(model, n.pts=20)

mono.chk <- mrds::check.mono(model, n.pts=10) # FTP: n.pts was 20, now 10 to match the solver in mrds.
## Now calculate abundance/density using dht()
if(!is.null(region_table) & !is.null(sample_table)){
# if obs_table is not supplied, then data must have the Region.Label and
Expand Down
2 changes: 1 addition & 1 deletion R/print.summary.dsmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param \dots unspecified and unused arguments for S3 consistency
#' @return Nothing, just prints the summary.
#' @author David L. Miller and Jeff Laake
#' @seealso [`summary.ds`][summary.ds]
#' @seealso \code{\link[mrds]{summary.ds}}
#' @keywords utility
#' @export
print.summary.dsmodel <- function (x,...){
Expand Down
2 changes: 1 addition & 1 deletion R/summary.dsmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param object a distance analysis
#' @param \dots unspecified and unused arguments for S3 consistency
#' @return list of extracted and summarized objects
#' @note This function just calls [`summary.ds`][summary.ds] and [`dht`][dht],
#' @note This function just calls \code{\link[mrds]{summary.ds}} and \code{\link[mrds]{dht}},
#' collates and prints the results in a nice way.
#' @author David L. Miller
#' @keywords utility
Expand Down
5 changes: 4 additions & 1 deletion man/Distance-package.Rd

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

10 changes: 7 additions & 3 deletions man/ds.Rd

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

2 changes: 1 addition & 1 deletion man/print.summary.dsmodel.Rd

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

2 changes: 1 addition & 1 deletion man/summary.dsmodel.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_summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ test_that("Error on different truncation distance", {
out <- read.table(text="
\\texttt{t4} Half-normal ~1 0.7789695 0.5842744 0.04637627 0.000000
\\texttt{t42} Half-normal ~1 0.7789695 0.5842744 0.04637627 0.000000
\\texttt{t4hr} \"Hazard-rate with cosine adjustment term of order 2\" ~1 0.8170780 0.5556728 0.07197555 2.501712
\\texttt{t4hr} \"Hazard-rate with cosine adjustment term of order 2\" ~1 0.8162846 0.5543305 0.07156778 2.454826
", header=FALSE)
names(out) <- c("Model", "Key function", "Formula", "C-vM p-value",
"$\\hat{P_a}$", "se($\\hat{P_a}$)", "$\\Delta$AIC")
expect_equal(summarize_ds_models(t4, t42, t4hr), out, fixed=TRUE, tol=par.tol)

# right truncation different
expect_error(summarize_ds_models(t3, t4))
# left
Expand Down

0 comments on commit c652894

Please sign in to comment.