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

Implement cross validation for delta families #239

Closed seananderson closed 1 year ago

seananderson commented 1 year ago

I think this should be relatively straightforward to implement. https://github.com/pbs-assess/sdmTMB/discussions/111#discussioncomment-6439110

library(sdmTMB)
x <- sdmTMB_cv(
  density ~ 1, 
  data = pcod_2011, 
  mesh = pcod_mesh_2011, 
  family = delta_gamma()
)
#> Error in switch(object$family$family, gaussian = ll_gaussian, tweedie = ll_tweedie, : 
#> EXPR must be a length 1 vector

Created on 2023-07-13 with reprex v2.0.2

seananderson commented 1 year ago

Cross validation is now working with delta models:

library(sdmTMB)
future::plan(future::multisession)
out_dg <- sdmTMB_cv(
  density ~ depth_scaled,
  data = pcod_2011, 
  mesh = make_mesh(pcod_2011, c("X", "Y"), cutoff = 10),
  family = delta_gamma(), 
  k_folds = 5
)
#> Running fits with `future.apply()`.
#> Set a parallel `future::plan()` to use parallel processing.
out_dg$fold_loglik
#> [1] -531.3995 -702.3048 -591.7539 -608.1418 -611.2388
out_dg$sum_loglik
#> [1] -3044.839