class: center, middle, inverse, title-slide .title[ # Forecasting with sdmTMB ] .subtitle[ ## DFO TESA sdmTMB workshop ] .author[ ### ] .date[ ### January 16–19 2023 ] --- <!-- Build with: xaringan::inf_mr() --> # Types of prediction we might be interested in * Time * e.g., interpolating over missed survey year * e.g., forecasting future year * Extrapolating in space * e.g., unsampled area (MPA, area beyond existing domain) --- class: center, middle, inverse # Forecasting in time --- # Predicting to missing/future years * Need a model for time: e.g., can't predict with years as factors * Options: * AR(1) or random walk random fields * Time-varying intercept * Smoother on year (`s(year)`) * Ignore time (fixed) * Some combination of these --- # AR(1) spatiotemporal field .small[ ```r # missing and forecasted years: extra_years <- c( 2006, 2008, 2010, 2012, 2014, 2016, 2018:2025 ) fit_ar1 <- sdmTMB( density ~ depth_scaled + depth_scaled2, time = "year", * extra_time = extra_years, * spatiotemporal = "AR1", data = pcod, mesh = mesh, family = tweedie(link = "log"), spatial = "off", silent = FALSE ) ``` ] --- # Random walk spatiotemporal field .small[ ```r fit_rw <- sdmTMB( density ~ depth_scaled + depth_scaled2, time = "year", * extra_time = extra_years, * spatiotemporal = "RW", data = pcod, mesh = mesh, family = tweedie(link = "log"), spatial = "off", silent = FALSE ) ``` ] --- # Random walk intercept + AR(1) fields .small[ ```r fit_rw_ar1 <- sdmTMB( density ~ 0 + depth_scaled + depth_scaled2, time = "year", * time_varying = ~1, * extra_time = extra_years, * spatiotemporal = "AR1", data = pcod, mesh = mesh, family = tweedie(link = "log"), spatial = "off", silent = FALSE ) ``` ] --- # Smoother on year + AR(1) fields .small[ ```r fit_sm <- sdmTMB( * density ~ s(year) + depth_scaled + depth_scaled2, time = "year", * extra_time = extra_years, * spatiotemporal = "AR1", data = pcod, mesh = mesh, family = tweedie(link = "log"), spatial = "off", silent = FALSE ) ``` ] --- # Comparing predicted density at a point in space .xsmall[Vertical dashed lines indicate observations] <img src="10-forecasting_files/figure-html/plot-time-comparison-1.png" width="700px" style="display: block; margin: auto;" /> --- # AR(1) spatiotemporal fields evolve towards mean zero <img src="10-forecasting_files/figure-html/pred-ar1-plot-eps-1.png" width="700px" style="display: block; margin: auto;" /> --- # Random walk fields do not evolve towards mean <img src="10-forecasting_files/figure-html/pred-rw-plot-eps-1.png" width="700px" style="display: block; margin: auto;" /> --- # Spatiotemporal field uncertainty grows without data (Here AR(1) fields; random walk similar.) <img src="10-forecasting_files/figure-html/eps-se-1.png" width="700px" style="display: block; margin: auto;" /> --- # Forecasting and interpolating in time summary * Use `extra_time` argument to fill in or forecast .xsmall[(a more flexible interface for forecasting may be forthcoming)] * Need a model for time * AR(1) field processes revert towards mean * Random walk field processes do not revert towards mean * Smoothers should be used with caution when forecasting .xsmall[(they continue whatever the basis functions were doing)]