plot_compare_ts()
View source ↗On this page
Compare the time series of SSB, recruitment, biomass, abundance and catch of two fits on the same axes, with optional 95% intervals.
Usage
plot_compare_ts(
model1,
model2,
quantities = c("SSB", "R", "B", "N", "CN"),
se = FALSE,
model1_name = NULL,
model2_name = NULL,
colors = NULL,
linetypes = NULL,
line_size = NULL,
facet_ncol = NULL,
facet_scales = NULL,
return_data = FALSE,
...,
interval = NULL,
title = NULL
)
Arguments
| Argument | Default | Description |
|---|---|---|
model1 | required | The first fit. |
model2 | required | The second fit. |
quantities | c("SSB", "R", "B", "N", "CN") | Character vector. Quantities to compare, from "SSB", "R" (or "Rec"), "B", "N", "CN" and "CB". For F use |
se | FALSE | Logical. Draw approximate 95% intervals of both fits from their standard errors. Default FALSE. |
model1_name | NULL | Character or NULL. Name of the first fit in the plot and in the default title. NULL takes the model type ("ACL" or "ALSCL"); when both fits have the same type, the F structure, or 1 and 2, is added in parentheses. |
model2_name | NULL | Character or NULL. Name of the second fit in the plot and in the default title. NULL takes the model type ("ACL" or "ALSCL"); when both fits have the same type, the F structure, or 1 and 2, is added in parentheses. |
colors | NULL | Character vector of two colors, named by model or in model order. NULL uses the global compare_colors setting; fewer than two colors give a warning, and the global setting is used. |
linetypes | NULL | Character vector of two line types, with the same rules as |
line_size | NULL | Numeric or NULL. Line width. NULL uses the global compare_line_size setting. |
facet_ncol | NULL | Integer or NULL. Number of columns of panels. NULL uses the global compare_facet_ncol setting, which by default chooses it from the number of panels. With five quantities the legend fills the empty cell. |
facet_scales | NULL | Character or NULL. Axis scales of the panels, "fixed", "free", "free_x" or "free_y". NULL uses the global compare_facet_scales setting ("free_y" unless changed). Letter case does not matter. |
return_data | FALSE | Logical. TRUE returns a list with the plot and the plotted data (see Value). Default FALSE. |
... | … | The former argument names linewidth (for line_size), ncol (for facet_ncol) and scales (for facet_scales), accepted with a warning. |
interval | NULL | Character or NULL. The 95% interval drawn when |
title | NULL | NULL (default) draws the default title, FALSE, NA or "" draws no title, and a character string draws that string; see |
Value
A ggplot object, or with return_data = TRUE a list with plot and data, the plotted values of both fits (columns Year, Value, Model and Quantity).
Details
Compare fits to compatible observations, units and time steps. The intervals of each fit depend on the fixed assumptions of that model.
The default quantities are SSB, recruitment, B, N and CN, which both models report with standard errors. CB must be requested explicitly and be present in both fits; ACL does not report CB, and neither model reports its standard errors. For fishing mortality use plot_compare_F_ts(a, b, method = "apical") or method = "mean", which take the maximum or the unweighted mean over groups in each time step, do not combine time steps and draw no interval for the summary.
Every requested quantity must be a finite series that matches the time metadata of its fit; unknown or unavailable quantities are errors. With se = TRUE, both fits need complete, finite estimates and finite, nonnegative standard errors for every requested quantity; use se = FALSE when they are not available.
A fit with only one estimate in a panel is drawn as a point, with an error bar when se = TRUE, because a band through one point has no width; fits with several estimates keep their lines and bands. The point size follows the global compare_point_size setting, or point_size when that is NULL. With the global y_zero setting (TRUE under the default style) the y axis of every panel starts at zero. Grid lines follow the grid setting of acl_theme_set().
Two fits of the same model get distinct default names, such as ACL (group_year) and ACL (year); model1_name and model2_name set other names, which must differ. Each fit keeps its own time steps, so the two fits can cover different years. A visual comparison does not show that the likelihoods or the biological assumptions of the two fits are comparable.
With se = TRUE the default interval is lognormal. The log of a positive estimate is treated as normal with standard error SE / estimate (delta method), so the bounds are exp(log(estimate) +/- 1.96 * SE / estimate) and cannot fall below zero. The estimate and its standard error (SE) are those stored in est_std of each fit. interval = "wald", or acl_theme_set(interval = "wald"), gives the symmetric interval estimate +/- 1.96 * SE. With the lognormal interval, an estimate of exactly zero gets the Wald upper bound and a lower bound of zero. Neither interval corrects for a poorly determined fit; inspect the fit diagnostics before using the intervals.
Additional details from R help
Every requested quantity must be a finite series matching its model's time steps. An unknown or unavailable quantity is an error. With se = TRUE, both models must have complete, finite estimates and finite nonnegative standard errors for every requested quantity. Use se = FALSE when uncertainty is unavailable. A model with one estimate in a panel is drawn as a point, with an error bar when se = TRUE. Models with multiple estimates retain lines and ribbons. With the global y_zero setting (TRUE under the default style) the y axis of every panel starts at zero.
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
plot_compare_ts(a, b, se = TRUE)

plot_compare_ts(a, b, se = TRUE)