A convenience wrapper that takes the outputs from run_sdmtmb(), diagnose(), and calc_index_areas() when run with dir = NULL and writes them all to disk in the same directory structure as the original indexwc code.

save_index_outputs(fit, diagnostics, indices, dir_main, overwrite = FALSE)

Arguments

fit

An sdmTMB model object returned by run_sdmtmb() with dir_main = NULL

diagnostics

A list returned by diagnose() with dir = NULL

indices

A list returned by calc_index_areas() with dir = NULL

dir_main

A string specifying the base directory where results will be saved. The function will create a subdirectory structure based on species, survey, and model family (same as run_sdmtmb() creates when dir_main is specified)

overwrite

Logical. If TRUE, existing files will be overwritten. Default is FALSE

Details

This function recreates the file structure that would have been created if you had run run_sdmtmb(), diagnose(), and calc_index_areas() with directory arguments specified from the start.

The directory structure created is:

dir_main/
└── species_name/
    └── survey_name/
        └── family_name/
            ├── data/
            │   ├── data.rdata
            │   └── fit.rds
            ├── diagnostics/
            │   ├── mesh.png
            │   ├── sanity_data_frame.csv
            │   ├── aic_nll.txt
            │   ├── run_diagnostics_and_estimates.rdata
            │   ├── qq.png
            │   ├── residuals_1_*.png
            │   ├── residuals_2_*.png (if delta model)
            │   ├── anisotropy.png
            │   ├── fixed_effects.png
            │   ├── density_*.png
            │   ├── data_with_residuals.rdata
            │   └── predictions.rdata
            └── index/
                ├── est_by_area.csv
                ├── index_coastwide.png (if Coastwide calculated)
                └── index_all_areas.png

See also

Author

Chantel R. Wetzel

Examples

if (FALSE) { # \dontrun{
# Fit model without saving
fit <- run_sdmtmb(
  dir_main = NULL,
  data = my_data,
  family = sdmTMB::delta_gamma(),
  formula = catch_weight ~ 0 + fyear
)

# Run diagnostics without saving
diag <- diagnose(
  dir = NULL,
  fit = fit,
  prediction_grid = my_grid
)

# Calculate indices without saving
idx <- calc_index_areas(
  data = fit$data,
  fit = fit,
  prediction_grid = my_grid,
  dir = NULL,
  boundaries = c("Coastwide", "CA", "OR", "WA")
)

# Now save everything to disk
paths <- save_index_outputs(
  fit = fit,
  diagnostics = diag,
  indices = idx,
  dir_main = "~/my_indices"
)
} # }