pbs-assess / sdmTMB

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

Add option to turn off spatial/spatiotemporal fields if they 'collapse' #263

Open seananderson opened 10 months ago

seananderson commented 10 months ago

Might need options:

Warn user if it happens.

ericward-noaa commented 10 months ago

Similarly, I was wondering if it'd be worth throwing a warning for spatiotemporal delta models in cases where there's no variation in the data. Especially for rare species, some time slices might not have any variation. Example:

mesh <- make_mesh(pcod, c("X", "Y"), cutoff = 20)
pcod$density[which(pcod$year==2005)] = 0
# model fits fine
fit <- sdmTMB(
  density ~ s(depth),
  data = pcod, mesh = mesh,
  family = delta_gamma(),
  time="year",
  spatiotemporal = "iid"
)
pred <- predict(fit, pcod) # predict all

The presence-absence field is shifted down (and unclear why there's any variation)

# plot spatial fields of presence-absence -- 
dplyr::filter(pred, year < 2009) %>%
  ggplot(aes(X,Y,col=est_rf1)) + 
  geom_point() + 
  facet_wrap(~year) + 
  scale_color_gradient2()

png_1

And as expected the positive model is ~ 0 with little variation compared to other years

dplyr::filter(pred, year < 2009) %>%
  ggplot(aes(X,Y,col=est_rf2)) + 
  geom_point() + 
  facet_wrap(~year) + 
  scale_color_gradient2()

png2