Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy coefficents for linear smoothers #411

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))

})
Loading