plot_compare_growth()
View source ↗On this page
Compare mean length at age and the length distribution at age of two fits on one basis, with optional observed means from age readings.
Usage
plot_compare_growth(
model1,
model2,
age_range = NULL,
model1_name = NULL,
model2_name = NULL,
colors = NULL,
linetypes = NULL,
line_size = NULL,
ref_data = NULL,
ref_name = "Von Bertalanffy curve from age readings",
ref_color = "grey30",
ref_linetype = "dotdash",
show_points = TRUE,
point_size = NULL,
point_alpha = 0.4,
nls_start = NULL,
...,
observed = NULL,
basis = c("population", "survey"),
years = NULL,
observed_name = "Age readings",
title = NULL
)
Arguments
| Argument | Default | Description |
|---|---|---|
model1 | required | The first fit. |
model2 | required | The second fit. |
age_range | NULL | Numeric or NULL. NULL draws all age classes of both fits; an explicit pair of finite increasing ages selects the age classes within it. |
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. |
ref_data | NULL | NULL or a data frame with columns Age and Length of individual age-length observations (for example from otolith readings). When given, |
ref_name | "Von Bertalanffy curve from age readings" | Character. Name of the reference curve; with |
ref_color | "grey30" | Character. Color for the reference curve and its points, and for the points of |
ref_linetype | "dotdash" | Character. Line type of the reference curve. Default "dotdash". |
show_points | TRUE | Logical. Draw the data points of |
point_size | NULL | Numeric or NULL. Point size. NULL uses the global compare_point_size setting, or point_size (default 2.5) when that is NULL. |
point_alpha | 0.4 | Numeric. Transparency of the data points of |
nls_start | NULL | Named list with Linf, k and t0, the starting values of |
... | … | The former argument name linewidth (for line_size), accepted with a warning. |
observed | NULL | NULL or a data frame of observed mean length at age from age readings, drawn as points in the left panel. It needs the columns |
basis | c("population", "survey") | Character. |
years | NULL | NULL (all time steps of each fit) or the time steps over which the values are averaged, which must be time steps of both fits. |
observed_name | "Age readings" | Character. Name of the points of |
title | NULL | NULL (default) draws the default title, FALSE, NA or "" draws no title, and a character string draws that string; see |
Value
A patchwork object with the two panels, which can be displayed or saved with acl_save_plot().
Details
The left panel compares mean length at age of the two fits, calculated on the same basis for both (length_at_age()) and averaged over the time steps. For ACL it comes from the age-length key, for ALSCL from the fitted numbers by length bin and age class. The right panel shows heatmaps of the probability of length given age on the same basis and for the same time steps, with cells at the ages in model$age and at the length-bin midpoints in model$len_mid. For an ACL fit on the population basis the heatmap is report$pla. For an ALSCL fit it is the proportion of each age class in each length bin from the fitted numbers; report$pla of an ALSCL fit is the length distribution of recruits (and, with the original structure, of every age class in the first time step) and is shown by plot_pla().
The left panel draws no curves computed from the growth parameters of the two models, and the subtitle does not list their Linf and k, because these parameters mean different things in the two models. In ACL they are the parameters of a curve of mean length at age; in ALSCL they set the growth increment at length and the mean length of recruits. The subtitle states the basis and the time steps of the mean. Both panels need the ages, the length-bin midpoints and the time steps of each fit, and an ALSCL fit needs its numbers by length and age; a result without them is an error.
observed supplies mean length at age from age readings, drawn as points with an optional standard deviation or interval; use basis = "survey" for readings of fish caught in the survey. ref_data takes individual ages and lengths, to which nls() fits a VB reference curve; the subtitle gives Linf and k of that curve.
The optional reference curve is drawn only at ages at or above its own fitted t0. If its fitted growth parameters are invalid or no positive age span remains, a warning explains why the reference curve is omitted; the lines of the two models and the observed points remain.
Omit age_range to draw all age classes of both fits. An explicit range must contain two finite increasing ages and selects the age classes within it; each fit needs at least one age class in the range.
When supplying ref_data, use a nonempty ref_name that differs from both model names; a repeated name is an error before the reference curve is fitted.
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. A visual comparison does not show that the likelihoods or the biological assumptions of the two fits are comparable.
Points take the global point_size setting (default 2.5) unless the global compare_point_size setting is given; a point_size in the call takes priority. acl_theme_set(compare_point_size = NULL) returns to the global point_size.
External data must use the age and length units of the fits. Simulated reference data, as in the example, only show how the reference curve is drawn.
Additional details from R help
The left panel does not draw curves from the growth parameters. In ACL,
Linf, k and t0 are the parameters of a von Bertalanffy curve of mean length
at age. In ALSCL they set the growth increment at length and the mean
length of recruits, so the parameters of the two models have different
meanings and are not compared (see length_at_age()).
Both panels need the ages, the length-bin midpoints and the time
steps of each fit, and an ALSCL fit needs its numbers by length, age and
time step. Results without them give an error. The heatmap cells sit at
the ages in model$age and at the length-bin midpoints in
model$len_mid. For an ACL fit on the population basis, the
heatmap is its age-length key (report$pla). For an ALSCL fit it is
the proportion of each age class in each length bin from the fitted
numbers, averaged over the time steps; report$pla of an ALSCL fit
is the length distribution of recruits (and, with the original structure,
of every age class in the first time step) and is shown by plot_pla().
The subtitle of the left panel states the basis and the time steps.
title is the title of the whole figure. The titles of the
panels stay when it is removed, because they name the panels.
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)
# Generate reference data here; a and b come from the setup
set.seed(42)
ref <- data.frame(Age = rep(1:15, each = 5))
ref$Length <- VB_func(60, 0.2, 1/60, ref$Age) + stats::rnorm(nrow(ref), sd = 2)
plot_compare_growth(a, b, age_range = c(1, 15), ref_data = ref,
ref_name = "Simulated age readings", nls_start = list(Linf = 60, k = 0.2, t0 = 1/60))

plot_compare_growth(a, b, age_range = c(1, 15), ref_data = ref, ref_name = "Simulated age readings")