Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prediction fails when both offset and nsim are provided and model includes extra_time (v0.4.1) #273

Closed
sebpardo opened this issue Nov 3, 2023 · 1 comment

Comments

@sebpardo
Copy link
Contributor

sebpardo commented Nov 3, 2023

Just came across this issue that's very much related to #270 and which is occurring in both sdmTMB 0.4.0 and 0.4.1. The problem with matching the length of the offset and the number of rows of newdata (in this case obtained internally) resurfaces when a value of nsim is being provided:

library(sdmTMB)

mesh <- make_mesh(pcod, c("X", "Y"), cutoff = 10)

pcod$os <- rep(log(0.01), nrow(pcod)) # offset

m <- sdmTMB(
  data = pcod,
  formula = density ~ poly(log(depth), 2),
  mesh = mesh,
  offset = pcod$os,
  family = tweedie(link = "log"),
  spatial = "on",
  time = "year",
  extra_time = c(2006, 2008, 2010, 2012, 2014, 2016), 
  spatiotemporal = "AR1"
)

p1 <- predict(m, offset = pcod$os) # This works
p2 <- predict(m, newdata = pcod, offset = pcod$os) # This used to fail but now works 
p3 <- predict(m, newdata = pcod) # This works
p4 <- predict(m, offset = pcod$os, nsim = 30) # This fails
# Error in `predict()`:
# ! Prediction offset vector does not equal number of rows in prediction dataset.
# Run `rlang::last_trace()` to see where the error occurred.
@seananderson
Copy link
Member

Thanks. Should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants