Skip to content

Commit

Permalink
Add to t2() smoother test as demo
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed Feb 27, 2025
1 parent 15d8445 commit 5d02d6f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/testthat/test-smooths.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,28 @@ test_that("A model with t2() works", {
dat$x1 <- NULL
dat$x2 <- NULL

m_mgcv <- mgcv::gam(observed ~ t2(.x0, .x1, k = 9),
m_mgcv <- mgcv::gam(observed ~ t2(.x0, .x1, k = 4),
data = dat,
method = "REML"
)
p_mgcv <- predict(m_mgcv)
m <- sdmTMB(observed ~ t2(.x0, .x1, k = 9),
m <- sdmTMB(observed ~ t2(.x0, .x1, k = 4),
data = dat,
spatial = 'off'
spatial = 'off', reml = TRUE
)
p <- predict(m, newdata = NULL)
expect_error(pnd <- predict(m, newdata = dat), "t2")
plot(p$est, p_mgcv)
abline(a = 0, b = 1)
expect_gt(cor(p$est, p_mgcv), 0.9999)
expect_equal(as.numeric(p$est), as.numeric(p_mgcv), tolerance = 0.001)

## prediction on newdata isn't quite right:
## switch cli_abort() to cli_warn() in predict.sdmTMB()
## currently on line 328 in predict.R
## pnd <- predict(m, newdata = dat)
## plot(p$est, pnd$est) ## don't match
## expect_equal(as.numeric(p$est), as.numeric(pnd$est), tolerance = 0.001) ## fails
})

test_that("A model with dimensions specified in t2() works", {
Expand Down

0 comments on commit 5d02d6f

Please sign in to comment.