diagnose_model()
View source ↗On this page
Print the numerical checks of a fit and return them in one table with the in-sample statistics of the survey-index fit.
Usage
diagnose_model(data.CatL, model_result)
Arguments
| Argument | Default | Description |
|---|---|---|
data.CatL | required | Survey index table, with the length labels in the first column and one column per time step. |
model_result | required | An ACL or ALSCL fit. |
Value
Prints the optimizer convergence code, the maximum absolute gradient and the Hessian and boundary checks and, when the fit stores diagnostics, the verdict of the numerical checks, the natural-scale boundary, the refinement status and the numbers of parameters at their limit in practice and of plausibility notes. Then returns a data frame with the columns Metric and Value, in which the in-sample fit statistics of diagnostic_metrics() are followed by the numerical checks (Parameter boundary hit, Optimizer converged, Maximum absolute gradient and Positive-definite Hessian; with stored diagnostics also Numerical checks passed, Natural-scale boundary, Covariance condition number and Highly correlated parameter pairs; for fits that store them, Parameters at their limit in practice and Plausibility notes, see the notes of run_acl() and model_result$diagnostics). Value is numeric, with 1 or 0 for a check that is TRUE or FALSE; the table prints these as TRUE or FALSE, with values to 4 significant digits and a legend of the fit statistics. Undefined or unavailable metrics are NA.
Details
The fit statistics compare the observed and the fitted survey index at length over the positive observations. MSE and RMSE are the mean squared error and its square root, MAE the mean absolute error, MAD the mean absolute deviation of the observations from their mean, MASE the MAE divided by the mean absolute change of the observations between adjacent time steps, Rsquared the coefficient of determination, MAPE and SMAPE the mean absolute percentage error and its symmetric form, Explained Variance Score one minus the variance of the errors divided by the variance of the observations, Max Error the largest absolute error, AIC and BIC the Akaike and Bayesian information criteria, and SD_log_resid the standard deviation of the log residuals.
These in-sample metrics use the finite positive survey observations only. The fitted values are the medians of the survey index on the original scale, exp(Elog_index) (where Elog_index is the fitted log index), without a lognormal mean correction. MASE divides MAE by the mean absolute change between adjacent time steps within each length bin, over the pairs in which both observations are positive. AIC and BIC count the estimated scalar parameters; compare them only between fits of the same observations with comparable likelihoods. Use hindcast_model() to score predictions of observations left out of the fit.
The optimizer convergence code (Optimizer converged is TRUE for code 0), the gradient, the Hessian and the boundaries are reported separately; a successful convergence code alone does not show that the standard errors can be used. The verdict of the numerical checks (Numerical checks passed, numerical_ok) follows from the gradient, Hessian, covariance and boundary criteria. Strongly correlated parameter pairs are reported separately; a pair with an absolute correlation of 0.95 or more is counted in high_correlations.
Additional details from R help
The fit statistics compare the observed and the fitted survey index at length over the positive observations: MSE and RMSE, the mean squared error and its square root; MAE, the mean absolute error; MAD, the mean absolute deviation of the observations from their mean; MASE, the MAE divided by the mean absolute change of the observations between adjacent time steps; Rsquared, the coefficient of determination; MAPE and SMAPE, the mean absolute percentage error and its symmetric form; Explained Variance Score, one minus the variance of the errors divided by the variance of the observations; Max Error, the largest absolute error; AIC and BIC, the Akaike and Bayesian information criteria.
The numerical checks are the optimizer convergence code ("Optimizer
converged" is TRUE for code 0), the maximum absolute gradient, whether a
parameter is at a bound of the optimizer and whether the Hessian is
positive definite, reported separately. An optimizer code of 0 alone
does not show that the estimates and their standard errors can be used.
For fits that store them, the numbers of parameters at their limit in
practice and of plausibility notes are added; see the Details of
run_acl() and model_result$diagnostics.
Input observations are checked against available fitted time, length and
observation metadata by diagnostic_metrics(); known mismatches are errors.
Examples
Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.
Example setup
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
a <- run_acl(x, silent = TRUE)
b <- run_alscl(x, silent = TRUE)
# Use objects defined above
diagnose_model(dat, b)