pbs-assess / sdmTMB

:earth_americas: An R package for spatial and spatiotemporal GLMMs with TMB
https://pbs-assess.github.io/sdmTMB/
186 stars 26 forks source link

get_index doesn't work without spatiotemporal random fields? #78

Closed seanhardison1 closed 2 years ago

seanhardison1 commented 2 years ago

From the get_index vignette:

# Use a small number of knots for this example to make it fast:
pcod_spde <- make_mesh(pcod, c("X", "Y"), n_knots = 60, type = "kmeans")
m <- sdmTMB(
  data = pcod,
  formula = density ~ 0 + as.factor(year),
  time = "year",
  mesh = pcod_spde, family = tweedie(link = "log")
)
# Note `return_tmb_object = TRUE` and the prediction grid:
predictions <- predict(m, newdata = qcs_grid, return_tmb_object = TRUE)
ind <- get_index(predictions)
ind

That checks out. But when the spatiotemporal random fields are excluded:

m <- sdmTMB(
  data = pcod,
  formula = density ~ 0 + as.factor(year),
  spatiotemporal = "off",
  mesh = pcod_spde, family = tweedie(link = "log")
)
predictions <- predict(m, newdata = qcs_grid, return_tmb_object = TRUE)
ind <- get_index(predictions)
ind

image

seananderson commented 2 years ago

You need to specify the time argument in sdmTMB(). Right now time isn’t defined so it’s giving you the index for all years combined. Perhaps we should have a check for that.

seanhardison1 commented 2 years ago

Fixed! Thank you.