Summarize model estimates and plot diagnostics
diagnose(dir, fit, prediction_grid = NULL)Directory path where results will be saved. If NULL,
results are only returned as a list (not saved to disk).
An object of class sdmTMB returned by sdmTMB::sdmTMB().
The prediction grid for the survey that sdmTMB will use to make model predictions to. Should not be NULL
A list containing
sanity - Sanity check results as list
model - The model family name
formula - The model formula
loglike - The log-likelihood value
aic - The AIC value
effects - A data frame of fixed and random effects, with confidence intervals
qq_plot - QQ plot ggplot object
residual_maps - List of residual map ggplot objects (one per model component for delta models)
anisotropy_plot - Anisotropy plot ggplot object
fixed_effects_plot - Fixed effects plot ggplot object
density_plot - Density plots ggplot object
predictions - Prediction data from the grid (as data frame)
data_with_residuals - Original data with residuals added (data frame)
date - Date diagnostics were run (Date)
session_info - R session information for reproducibility
run_sdmtmb(), fit the model first
calc_index_areas(), calculate indices after diagnosing
if (FALSE) { # \dontrun{
# Fit a model
fit <- run_sdmtmb(
data = data_formatted,
family = sdmTMB::delta_gamma(),
formula = catch_weight ~ 0 + fyear + depth_scaled + depth_scaled_squared
)
# Run diagnostics without saving
diag <- diagnose_model(
fit = fit,
prediction_grid = my_grid,
dir = NULL
)
# Access diagnostic values
diag$aic # AIC value
diag$loglike # Log-likelihood
diag$sanity # Sanity check data frame
head(diag$effects) # Effects table
# View plots
print(diag$qq_plot) # QQ plot
print(diag$anisotropy_plot) # Anisotropy
print(diag$residual_maps[[1]]) # Residuals model 1
if (length(diag$residual_maps) > 1) {
print(diag$residual_maps[[2]]) # Residuals model 2 (delta)
}
print(diag$fixed_effects_plot) # Fixed effects over time
print(diag$density_plot) # Density maps
# Access data
head(diag$predictions) # Predictions on grid
head(diag$data_with_residuals) # Data with residuals
# Session information
diag$date # When diagnostics were run
diag$session_info # Full session info
} # }