Skip to content

Commit 9ba405e

Browse files
committed
Multiply size for binomial simulate w. no obs error #465
1 parent 54a0586 commit 9ba405e

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

R/tmb-sim.R

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,6 @@ simulate.sdmTMB <- function(object, nsim = 1L, seed = sample.int(1e6, 1L),
483483

484484
if (!return_tmb_report) {
485485
if (is_delta(object)) {
486-
if (object$family[[1]]$family == "binomial" &&
487-
object$family$type == "standard" &&
488-
!observation_error) {
489-
ret <- lapply(ret, function(.x) {
490-
.x[,1] <- stats::plogis(.x[,1]) # using robust dbinom in logit space
491-
.x
492-
})
493-
}
494486
if (is.na(model[[1]])) {
495487
ret <- lapply(ret, function(.x) .x[,1] * .x[,2])
496488
} else if (model[[1]] == 1) {
@@ -502,13 +494,6 @@ simulate.sdmTMB <- function(object, nsim = 1L, seed = sample.int(1e6, 1L),
502494
}
503495
}
504496

505-
if (!is_delta(object) && !observation_error) {
506-
if (object$family$family == "binomial") {
507-
# using robust dbinom in logit space
508-
ret <- lapply(ret, function(.x) stats::plogis(.x))
509-
}
510-
}
511-
512497
ret <- do.call(cbind, ret)
513498

514499
if (!is.null(newdata)) {

src/sdmTMB.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,11 @@ Type objective_function<Type>::operator()()
885885
if (!sim_obs) {
886886
for (int m = 0; m < n_m; m++) {
887887
for (int i = 0; i < n_i; i++) {
888-
y_i(i,m) = mu_i(i,m);
888+
if (family(m) == binomial_family && !poisson_link_delta) {
889+
y_i(i,m) = invlogit(mu_i(i,m)) * size(i); // hardcoded invlogit b/c mu_i in logit space
890+
} else {
891+
y_i(i,m) = mu_i(i,m);
892+
}
889893
}
890894
}
891895
}

0 commit comments

Comments
 (0)