Skip to content

Commit

Permalink
tidy coefficents for linear smoothers
Browse files Browse the repository at this point in the history
Small fix added to tidy()
  • Loading branch information
ericward-noaa committed Feb 24, 2025
1 parent 39fa30b commit 70d8a30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions R/tidy.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ tidy.sdmTMB <- function(x, effects = c("fixed", "ran_pars", "ran_vals"), model =
)
}

if (x$tmb_data$has_smooths) {
p <- print_smooth_effects(x)
mm <- p$smooth_effects
out <- rbind(out,
data.frame(term = rownames(mm),
estimate = mm[,"bs"],
std.error = mm[,"bs_se"],
stringsAsFactors = FALSE))
}


if (conf.int) {
out$conf.low <- as.numeric(trans(out$estimate - crit * out$std.error))
out$conf.high <- as.numeric(trans(out$estimate + crit * out$std.error))
Expand Down
1 change: 0 additions & 1 deletion sdmTMB.Rproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Version: 1.0
ProjectId: 1e54a969-ff39-402d-83f4-c260f1f06bda

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-tidy.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ test_that("tidy works", {
x <- tidy(fit, "ran_pars", conf.int = TRUE)
x
expect_true(sum(is.na(x$std.error)) == 0L)

# test smooth handling
fit <- sdmTMB(
density ~ s(depth),
data = pcod_2011, mesh = mesh,
family = tweedie(link = "log")
)
x <- tidy(fit)
expect_equal(x$term, c("(Intercept)", "sdepth"))

})

0 comments on commit 70d8a30

Please sign in to comment.