Skip to content

Commit 5d02d6f

Browse files
committed
Add to t2() smoother test as demo
1 parent 15d8445 commit 5d02d6f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/testthat/test-smooths.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,28 @@ test_that("A model with t2() works", {
6565
dat$x1 <- NULL
6666
dat$x2 <- NULL
6767

68-
m_mgcv <- mgcv::gam(observed ~ t2(.x0, .x1, k = 9),
68+
m_mgcv <- mgcv::gam(observed ~ t2(.x0, .x1, k = 4),
6969
data = dat,
7070
method = "REML"
7171
)
7272
p_mgcv <- predict(m_mgcv)
73-
m <- sdmTMB(observed ~ t2(.x0, .x1, k = 9),
73+
m <- sdmTMB(observed ~ t2(.x0, .x1, k = 4),
7474
data = dat,
75-
spatial = 'off'
75+
spatial = 'off', reml = TRUE
7676
)
7777
p <- predict(m, newdata = NULL)
7878
expect_error(pnd <- predict(m, newdata = dat), "t2")
7979
plot(p$est, p_mgcv)
8080
abline(a = 0, b = 1)
8181
expect_gt(cor(p$est, p_mgcv), 0.9999)
8282
expect_equal(as.numeric(p$est), as.numeric(p_mgcv), tolerance = 0.001)
83+
84+
## prediction on newdata isn't quite right:
85+
## switch cli_abort() to cli_warn() in predict.sdmTMB()
86+
## currently on line 328 in predict.R
87+
## pnd <- predict(m, newdata = dat)
88+
## plot(p$est, pnd$est) ## don't match
89+
## expect_equal(as.numeric(p$est), as.numeric(pnd$est), tolerance = 0.001) ## fails
8390
})
8491

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

0 commit comments

Comments
 (0)