Skip to content

Commit

Permalink
Add offset_i to another predict() in residuals
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed May 11, 2023
1 parent 2492b00 commit 67d0b8e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ residuals.sdmTMB <- function(object,
)

if (type %in% c("mle-laplace", "response", "pearson")) {
mu <- tryCatch({linkinv(predict(object, newdata = NULL)[[est_column]])}, # newdata = NULL; fast
error = function(e) NA)
if (is.na(mu[[1]])) {
mu <- linkinv(predict(object, newdata = object$data, offset = object$tmb_data$offset_i)[[est_column]]) # not newdata = NULL
}
# mu <- tryCatch({linkinv(predict(object, newdata = NULL)[[est_column]])}, # newdata = NULL; fast
# error = function(e) NA)
# if (is.na(mu[[1]])) {
mu <- linkinv(predict(object, newdata = object$data, offset = object$tmb_data$offset_i)[[est_column]]) # not newdata = NULL
# }
} else if (type == "mvn-laplace") {
mu <- linkinv(predict(object, nsim = 1L, model = model)[, 1L, drop = TRUE])
mu <- linkinv(predict(object, nsim = 1L, model = model, offset = object$tmb_data$offset_i)[, 1L, drop = TRUE])
} else if (type == "mle-mcmc") {
if (is.null(mcmc_samples)) {
msg <- c("As of sdmTMB 0.3.0, `mcmc_samples` must be supplied to use `type = 'mle-mcmc'`.",
Expand Down

0 comments on commit 67d0b8e

Please sign in to comment.