Skip to content

Commit 47ec9bf

Browse files
committed
Add unit test
1 parent 8a3c72e commit 47ec9bf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/testthat/test-poisson-link.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
test_that("Poisson-link prediction issues from GitHub issues #389,", {
2+
skip_on_cran()
3+
dogfish$log_depth <- log(dogfish$depth)
4+
mesh <- make_mesh(dogfish, c("X", "Y"), cutoff = 30)
5+
fit_dpg <- sdmTMB(catch_weight ~ 0 + as.factor(year) + s(log_depth),
6+
family = delta_gamma(type = "poisson-link"),
7+
spatial = "on",
8+
mesh = mesh,
9+
data = dogfish,
10+
offset = log(dogfish$area_swept)
11+
)
12+
p <- predict(fit_dpg, re_form = NA)
13+
p$est_est1est2 <- p$est1 + p$est2
14+
expect_equal(p$est, p$est_est1est2)
15+
expect_equal(p$est_est1est2[1:5],
16+
c(7.01028301430728, 2.34143881755487, 6.96979232578834, 6.99973559970208,
17+
7.03187981132451), tolerance = 1e-3)
18+
19+
pp <- predict(fit_dpg, type = "response")
20+
expect_equal(pp$est[1:5],
21+
c(693.502617933497, 107.803298324919, 8414.54507288536, 5770.52404422525,
22+
6545.06096568627), tolerance = 1e-3)
23+
})

0 commit comments

Comments
 (0)