Skip to content

Commit

Permalink
Test for Inf in covariate columns #408
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed Feb 25, 2025
1 parent 5bda313 commit 15d8445
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
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.9028
Version: 0.6.0.9029
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)

* Add check for `Inf`/`-Inf` values before fitting. #408

* Add priors for `breakpt()` and `logistic()` parameters. #403

* Add linear component of smoothers to `tidy()`. #90
Expand Down
6 changes: 6 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,12 @@ sdmTMB <- function(
formula_no_bars_no_sm <- remove_s_and_t2(formula_no_bars)
X_ij[[ii]] <- model.matrix(formula_no_bars_no_sm, data)
mf[[ii]] <- model.frame(formula_no_bars_no_sm, data)
vars <- colnames(mf[[ii]])
for (g in seq_along(vars)) {
if (any(is.infinite(mf[[ii]][, g, drop = TRUE]))) {
cli_abort("Column `{vars[g]}` had an Inf/-Inf value. Please remove this before fitting the model.")
}
}

mt[[ii]] <- attr(mf[[ii]], "terms")
# parse everything mgcv + smoothers:
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,17 @@ test_that("get_index works", {
#
# })

# https://github.com/pbs-assess/sdmTMB/issues/408
test_that("Models error our nicely with Inf or -Inf covariates before get_index()", {
d <- pcod
d$depth_scaled[1] <- -Inf
expect_error(m <- sdmTMB(
data = d,
formula = density ~ 0 + as.factor(year) + depth_scaled,
spatiotemporal = "off", # speed
spatial = "off", # speed
time = "year",
family = delta_gamma(type = "poisson-link")
), regexp = "Inf")
})

0 comments on commit 15d8445

Please sign in to comment.