Skip to content

Commit

Permalink
Add message if limits set with optimHess #394
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed Jan 28, 2025
1 parent 685e623 commit a00e32d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: sdmTMB
Title: Spatial and Spatiotemporal SPDE-Based GLMMs with 'TMB'
Version: 0.6.0.9022
Version: 0.6.0.9023
Authors@R: c(
person(c("Sean", "C."), "Anderson", , "[email protected]",
role = c("aut", "cre"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sdmTMB (development version)

* Warn if parameter limits are set with `newton_loops > 0`. #394

* Allow for specifying only lower or upper limits. #394

* Add vignette on multispecies models with sdmTMB (or any case where one wants
Expand Down
5 changes: 5 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,11 @@ sdmTMB <- function(
tmb_opt[["evaluations"]] <- tmb_opt[["evaluations"]] + temp[["evaluations"]]
}
}
if (!is.null(control$upper) || !is.null(control$lower)) {
if (newton_loops > 0) {
cli_inform("Upper or lower limits were set. `stats::optimHess()` will ignore these limits. Set `control = sdmTMBcontrol(newton_loops = 0)` to avoid the `stats::optimHess()` optimization if desired.")
}
}
if (newton_loops > 0) {
if (!silent) cli_inform("attempting to improve convergence with optimHess\n")
for (i in seq_len(newton_loops)) {
Expand Down
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
#' @param lower An optional named list of lower bounds within the optimization.
#' Parameter vectors with the same name (e.g., `b_j` or `ln_kappa` in some
#' cases) can be specified as a numeric vector. E.g.
#' `lower = list(b_j = c(-5, -5))`.
#' `lower = list(b_j = c(-5, -5))`. Note that [stats::optimHess()] does not
#' implement lower and upper bounds, so you must set `newton_loops = 0` if
#' setting limits.
#' @param upper An optional named list of upper bounds within the optimization.
#' @param censored_upper An optional vector of upper bounds for
#' [sdmTMBcontrol()]. Values of `NA` indicate an unbounded right-censored to
Expand Down

0 comments on commit a00e32d

Please sign in to comment.