Skip to content

Commit 8a3c72e

Browse files
committed
Fix #389
1 parent 69b18af commit 8a3c72e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: sdmTMB
33
Title: Spatial and Spatiotemporal SPDE-Based GLMMs with 'TMB'
4-
Version: 0.6.0.9014
4+
Version: 0.6.0.9015
55
Authors@R: c(
66
person(c("Sean", "C."), "Anderson", , "sean@seananderson.ca",
77
role = c("aut", "cre"),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# sdmTMB (development version)
22

3+
* Fix bug in `est` column when predicting on new data with Poisson-link
4+
delta models with `type = "link"` and `re_form = NA`. #389
5+
36
* Fix bug in `s95` param reporting from the `tidy()` method. `s95` is present
47
in the logistic threshold models. The model itself was fine but the `s95`
58
parameter was supposed to be reported by `tidy()` as a combination of two

R/predict.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,28 @@ predict.sdmTMB <- function(object, newdata = NULL,
785785
if (type == "response") {
786786
nd$est1 <- object$family[[1]]$linkinv(r$proj_fe[,1])
787787
nd$est2 <- object$family[[2]]$linkinv(r$proj_fe[,2])
788-
nd$est <- nd$est1 * nd$est2
788+
if (object$tmb_data$poisson_link_delta) {
789+
.n <- nd$est1 # expected group density (already exp())
790+
.p <- 1 - exp(-.n) # expected encounter rate
791+
.w <- nd$est2 # expected biomass per group (already exp())
792+
.r <- (.n * .w) / .p # (n * w)/p # positive expectation
793+
nd$est1 <- .p # expected encounter rate
794+
nd$est2 <- .r # positive expectation
795+
nd$est <- .n * .w # expected combined value
796+
} else {
797+
nd$est <- nd$est1 * nd$est2
798+
}
789799
} else {
790800
nd$est1 <- r$proj_fe[,1]
791801
nd$est2 <- r$proj_fe[,2]
792802
if (is.na(model)) {
793803
p1 <- object$family[[1]]$linkinv(r$proj_fe[,1])
794804
p2 <- object$family[[2]]$linkinv(r$proj_fe[,2])
795-
nd$est <- object$family[[2]]$linkfun(p1 * p1)
805+
if (object$tmb_data$poisson_link_delta) {
806+
nd$est <- nd$est1 + nd$est2
807+
} else {
808+
nd$est <- object$family[[2]]$linkfun(p1 * p1)
809+
}
796810
if (se_fit) {
797811
nd$est <- sr_est_rep$proj_rf_delta
798812
nd$est_se <- sr_se_rep$proj_rf_delta

0 commit comments

Comments
 (0)