# 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
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.
From the get_index vignette:
That checks out. But when the spatiotemporal random fields are excluded: