On this page

Compare two fits of the same survey data by their numerical checks, AIC, fit statistics, mean length at age and population series, and print the comparison.

Usage

compare_models(
  model1,
  model2,
  data.CatL,
  model1_name = NULL,
  model2_name = NULL
)

Arguments

ArgumentDefaultDescription
model1required

A fit from run_acl() or run_alscl(), the reference model.

model2required

A fit from run_acl() or run_alscl(), the alternative model.

data.CatLrequired

The survey index table that both fits used; the in-sample fit statistics are calculated from it.

model1_nameNULL

Character or NULL. Label of model1 in the printed report and in the returned tables. NULL takes the model type of the fit; when both labels are the same, the F structure or a number is added to tell them apart.

model2_nameNULL

Character or NULL. Label of model2 in the printed report and in the returned tables. NULL takes the model type of the fit; when both labels are the same, the F structure or a number is added to tell them apart.

Value

Prints a comparison report and returns, invisibly, a list. summary compares the convergence, boundary status, objective, number of parameters, number of observations, AIC, BIC, maximum absolute gradient and the ratio of run times. growth has one block of rows per model with the columns Model, Parameter (Linf, k, t0, cv_len, cv_grow for ALSCL, and sigma_index, the standard deviation of the observation error of the log survey index), Estimate and Meaning; select one model with subset(cmp$growth, Model == "ALSCL"). The growth parameters of ACL and ALSCL are not placed side by side, because they are different quantities. length_at_age has the columns Age, Basis and one column per model with mean length at age, averaged over the time steps; it is the comparison of growth between the two fits. Basis is "survey" (numbers at length multiplied by survey catchability at length) when the survey catchability of both fits is available and "population" otherwise, and the element is NULL when neither fit holds the quantities needed (see length_at_age()). fit_metrics holds the in-sample errors of the survey-index fit. correlation holds the Pearson correlation and Ratio_Mean (the mean of model2 divided by the mean of model1) of the population series that both fits report; catch in numbers and catch in weight are compared as relative catch (rows "CN (relative)" and "CB (relative)"), with the correlation only and Ratio_Mean NA. fit_diagnostics holds the numerical checks of the two fits. comparison holds data_verified, eligible, preferred, issues, delta_aic (the Akaike information criterion, AIC, of model2 minus that of model1), aic_threshold (2, the smallest absolute AIC difference for which a preference is given) and reason (why no preference was given; NA when one is given). preferred names the model with the lower AIC only when both fits are eligible and their AIC values differ by at least 2; otherwise it is NULL. model1_name and model2_name hold the labels used.

Details

compare_models() checks both fits against data.CatL. Their time labels, length-bin labels and order, positive observations and missing values must agree with the table, and a known mismatch is an error. Each positive index is checked at its own scale, with a relative tolerance of 10⁻¹². For example, replacing 10⁻¹³ with 10⁻²⁰ changes the log observation by about 16 units, and the comparison stops before any preference is calculated. Give the survey table that both fits used. data.CatL can be a data frame, a matrix or a tibble; factor columns that hold numbers as text are read by their labels, not by their internal level codes.

Ratio_Mean divides the mean of model2 by the mean of model1 and is not a mean of ratios by time step; delta_aic subtracts the AIC of model1 from that of model2. When a fit fails its numerical checks, or a saved fit lacks the records needed to check its data, the function warns and reports the AIC, BIC and fit statistics but gives no preference. Read cmp$fit_diagnostics and cmp$comparison (data_verified, eligible, preferred, issues). Passing the numerical checks allows a comparison; whether the likelihoods are comparable and the biological assumptions reasonable remains to be judged, and AIC expresses only the relative support for the two fits. With an AIC difference below 2, preferred is NULL, issues is empty and cmp$comparison$reason gives this reason; such a difference does not show that the models are equivalent. A failure record from a batch function, such as an element of fit_scenarios()$fits that holds an error, is rejected with its fit error. AIC(), BIC(), logLik() and nobs() work on a fit and give the values reported here.

Growth is compared through mean length at age, not through Linf, k and t0. In ACL these are the parameters of a von Bertalanffy curve of mean length at age. In ALSCL, Linf and k set the mean growth increment in one time step as a function of length, and Linf, k and t0 set the mean length of recruits; the lengths of older fish follow from the growth increments and from mortality at length. The parameters are therefore listed in a separate block for each model, with their meaning, and length_at_age holds mean length at age of both fits as an unweighted mean over the time steps of the values that length_at_age() returns.

A fit to survey data alone has no information on the absolute level of catch, which depends on the assumed natural mortality rate and the assumed survey catchability (see relative_catch()). The catch series of the two fits are therefore compared by their correlation only. ACL does not report catch in weight; it is calculated from catch in numbers at age and mean weight at age when the weights used in the fit are available.

Additional details from R help

Both fits must use the same positive observations, missing-data mask, length labels and time steps as data.CatL, and a known mismatch is an error. Results without these records give the statistics but no preference, as do fits that fail the numerical checks. Passing the checks does not show that a model is adequate, and AIC measures the relative support of the two fits, not their biological validity. When both fits are eligible, preferred names the model with the lower AIC only if the two AIC values differ by at least 2. With a smaller difference preferred is NULL, issues is empty and comparison$reason records that the AIC difference is below 2; such a difference does not establish that the models are equivalent. A failure record from a batch function, such as an element of fit_scenarios()$fits that holds an error, is rejected with its fit error. Growth is compared through mean length at age, not through Linf, k and t0. In ACL these are the parameters of a von Bertalanffy curve of mean length at age. In ALSCL, Linf and k set the mean growth increment in one time step as a function of length, and Linf, k and t0 set the mean length of recruits; the lengths of older fish follow from the growth increments and from mortality at length. The parameters are therefore listed in a separate block for each model, with their meaning, and length_at_age holds mean length at age of both fits as an unweighted mean over the time steps of the values that length_at_age() returns. A fit to survey data alone has no information on the absolute level of catch, which depends on the assumed natural mortality rate and the assumed survey catchability (see relative_catch()). The catch series of the two fits are therefore compared by their correlation only. ACL does not report catch in weight; it is calculated from catch in numbers at age and mean weight at age when the weights used in the fit are available. Goodness-of-fit measures use the same calculation as diagnostic_metrics(). Undefined R-squared for constant observations is NA; nonfinite response-scale predictions at observed cells are errors. Data frames, tibbles and matrices are converted as in fitting, so numbers stored as text or factors are read as their values, not as factor codes.

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
comparison <- compare_models(a, b, dat)
comparison$length_at_age
comparison$growth
comparison$correlation

See also

Search documentation