On this page

On this page you plot the growth, the fishing mortality, the fixed natural mortality and survey catchability, the residuals, the process deviations and the length compositions of a fit. You need the fits a and b of Understand your first fit. The block below loads ggplot2 and patchwork, which some sections use.

library(ggplot2)
library(patchwork)

Mean length at age

# Simulated age readings, not observations from the paper
set.seed(42)
ref <- data.frame(Age = rep(1:15, each = 5))
ref$Length <- VB_func(60, .2, 1/60, ref$Age) + rnorm(nrow(ref), 0, 2)
# Assign each length to its model length bin before averaging
ref$Mid <- b$len_mid[findInterval(ref$Length, b$len_border) + 1]
readings <- data.frame(age = 1:15,
  mean_length = as.numeric(tapply(ref$Mid, ref$Age, mean)),
  sd_length = as.numeric(tapply(ref$Mid, ref$Age, sd)))
# Draw this figure
plot_VB(b, observed = readings, parameter_curve = TRUE, text_size = 3.5)

Mean length at age

For an ALSCL fit, plot_VB() shows mean length at age calculated from the fitted numbers by length bin and age class and averaged over the time steps (solid line; the values of length_at_age()). In ALSCL, Linf and k set the growth increment at length, and Linf, k and t0 set the mean length of recruits, so they are not the parameters of a von Bertalanffy curve of mean length at age (Model principles). The default figure, plot_VB(b), shows the solid line only and has no annotation of Linf and k. parameter_curve = TRUE adds the curve computed from Linf, k and t0 as a dashed grey line, named "Curve from the growth parameters" in the legend and in the annotation that gives Linf and k; with the original structure this curve gives the mean length at age in the first time step and the mean length of recruits in every time step. observed adds mean length at age from age readings as points ("Age readings"), here with error bars of one standard deviation on each side. For an ACL fit, plot_VB(a) shows the von Bertalanffy curve, which is the mean length at age of that model, with the annotation of Linf and k.

Each length bin is represented by its midpoint. The last length bin of this example holds all fish above 49 cm and has the midpoint 50 cm, so the mean length of the older age classes levels off at 50 cm, below the dashed curve. For a comparison with age readings, assign the lengths of the aged fish to the length bins of the model, as the code above does, so that both means are calculated in the same way. Use basis = "survey" to compare with age readings of fish caught in the survey; the numbers at length are then multiplied by the survey catchability at length. years selects the time steps of the mean.

se = TRUE draws the 95% interval of the curve computed from Linf, k and t0, which is the curve of the figure for an ACL fit and the dashed curve for an ALSCL fit. All three parameters are fixed in this example, so the interval has zero width. The model reports no standard error for mean length at age from the fitted numbers, and se = TRUE without the dashed curve gives a warning and the estimate only. If the parameter covariance is unavailable, the function warns and draws the estimate alone, keeping the labels, text sizes, breaks and theme you passed.

Arguments and defaults

Mean length at age by time step

# Draw this figure
plot_length_at_age(b, ages = c(2, 5, 8, 11), line_size = 0.6)

Mean length at age by time step

Each panel shows the mean length of one age class in each time step, from length_at_age(). In the first time step of an ALSCL fit with the original structure, every age class has the length distribution given by Linf, k and t0. In later time steps the lengths follow from the growth increments and from mortality at length, so the mean length changes during the first years and then varies with recruitment and fishing. An ACL fit uses one age-length key and gives horizontal lines. observed takes mean length at age by time step from age readings (columns year, age and mean_length, optionally sd_length) and draws it as points in the panel of its age class; use basis = "survey" for readings of fish caught in the survey. ages and years select age classes and time steps, and facet_by = "none" draws all age classes in one panel.

Arguments and defaults

Distribution of length at age

# Draw this figure
plot_pla(b)

Distribution of length at age

Each column of the static pla matrix gives length-bin probabilities for one age class and sums to one. ACL uses this matrix to convert numbers at age to numbers at length in every time step. ALSCL uses it to initialize the population and assign lengths to recruits; subsequent length distributions follow growth and survival. To obtain the realized distribution at a given age and time in ALSCL, normalize the corresponding length vector in NLA. The color shows the probability in each bin, and the last bin includes the upper tail. The horizontal axis shows the fitted ages, and the oldest age, a plus group, is marked "15+". A result saved without age metadata is plotted against the position of the age class, and its axis label reads Age bin.

Arguments and defaults

A panel or model group containing only one estimate is shown as a point. With se = TRUE, an error bar shows the 95% interval (lognormal by default; see the interval argument) because a one-point ribbon has no visible width. This applies to population and fishing-mortality plots and to each model separately in plot_compare_ts(). Point size follows point_size; a single-model point takes the color of the line of its plot and its error bar the color of the interval. Grid lines follow the grid setting of acl_theme_set().

ACL fishing mortality over time by age class

plot_fishing_mortality() takes its title, axis labels, x_breaks and x_expand from acl_theme_set(), with the title keys F_year, F_age and F_length (_se added for interval plots) and the labels xlab$year, xlab$age or xlab$length and ylab$F. In age mode the horizontal axis shows the fitted ages, and the plus group is marked as in "15+"; an ALSCL plot with intervals (se = TRUE) shows the ages before the plus group. A result saved without age metadata is plotted against the position of the age class, and its default label reads Age bin unless you set xlab$age. The default ylab$F label states the time basis of the rate, for example "Fishing mortality rate (per year)"; labels and breaks given in the call take precedence. base_theme accepts a theme name such as "theme_bw" or "bw", a ggplot2 theme object, or NULL for the global setting, and the grid lines follow the grid setting in every case.

# Draw this figure
plot_fishing_mortality(a, type = "year",
  se = TRUE, line_size = 0.6)

ACL fishing mortality over time by age class

Each panel shows the estimated instantaneous fishing mortality rate (F) for one ACL age class, with its approximate 95% interval. F is expressed per model time step. The time step is one year here and one quarter in a quarterly fit.

Arguments and defaults

ACL fishing mortality at age by time step

# Draw this figure
plot_fishing_mortality(a, type = "age",
  se = TRUE, line_size = 0.6)

ACL fishing mortality at age by time step

Each panel shows the same ACL estimates for one time step, with the fitted ages on the horizontal axis (the plus group is marked "15+") and approximate 95% intervals. In most years of this example the profiles are nearly flat, which indicates similar estimated fishing mortality across ages; from 2007 to 2010 the estimates are higher at the younger ages.

Arguments and defaults

ALSCL fishing mortality over time by length bin

# Draw this figure
plot_fishing_mortality(b, type = "year",
  se = TRUE, line_size = 0.6)

ALSCL fishing mortality over time by length bin

Each panel shows how fishing mortality at length (FL) changes over time for one length bin, with an approximate 95% interval. The estimated peak around 2008 is most pronounced at intermediate lengths.

Arguments and defaults

ALSCL fishing mortality at age by time step

# Draw this figure
plot_fishing_mortality(b, type = "age",
  se = TRUE, line_size = 0.6)

ALSCL fishing mortality at age by time step

For each age class, ALSCL sums the numbers surviving across length bins and divides by the number present at the start of the step. Fishing mortality at age is FA = -log(survival proportion) - M. Each panel shows the estimates and approximate 95% intervals for one time step. The figure is drawn with se = TRUE, so it shows the cells that have standard errors, namely the ages before the plus group (ages 1 to 14) and the time steps before the last (2000 to 2018). These are the cells of report$FA, and report$ZA holds the matching total mortality at age. Without intervals (se = FALSE) the function also draws the plus group ("15+") and the last time step, which it computes from the reported numbers at length and age (report$NLA) and total mortality at length (report$ZL) with the same formula. F in the last time step is predicted by the F process; no observation informs it. extract_estimates(b, "FA") returns F at age for every age and time step; its standard errors are NA for the plus group and the last time step.

Arguments and defaults

ALSCL fishing mortality at length by time step

# Draw this figure
plot_fishing_mortality(b, type = "length",
  se = TRUE, line_size = 0.6)

ALSCL fishing mortality at length by time step

Each panel shows fishing mortality at length for one time step, with an approximate 95% interval. Length-bin midpoints (len_mid) are plotted at their actual spacing. In this example, estimated fishing mortality is higher at intermediate lengths, around 20 to 35 cm.

Arguments and defaults

Natural mortality rate and survey catchability used in the fit

# Draw this figure
(plot_natural_mortality(b, line_size = 0.8, title = "Natural mortality rate") +
   expand_limits(y = 0)) |
  plot_survey_catchability(b, line_size = 0.8, point_size = 1.5,
    title = "Survey catchability at length")

Natural mortality rate and survey catchability used in the fit

Both panels show inputs that you supplied, not estimates. plot_natural_mortality() follows the form of M. A single value is a horizontal line (as here, with the subtitle "One value for all age classes and time steps"), a rate by age class is drawn against age or, when it changes over time, against the time step with one panel per age class, and a rate by length (ALSCL) is drawn against length. plot_survey_catchability() shows the catchability at length from sel_L50 and sel_L95 or from survey_q. When survey_q differs among time steps, it draws one line for each distinct curve and names the time steps of each, and type = "age" shows the multiplier by age (survey_q_age). The survey index does not inform the split of total mortality into fishing and natural mortality or the level of catchability, so the level of F, catch and abundance depends on these inputs (Choose the fitting settings). Show them next to the estimates in a report.

Arguments and defaults

Log residuals by length bin

# Draw this figure
plot_residuals(b, facet_by = "length", line_size = 0.6)

Log residuals by length bin

Log residuals, the observed minus the fitted log survey index, one panel per length bin with time on the horizontal axis. The dark blue line joins the residuals, the grey line is zero and the dashed teal curve is a smoother. Use it to find bins the model misfits (zero and missing observations have no residual); residuals of one sign over many years, as in bins 16 (positive) and 20 (negative) here, mean a systematic misfit, and a trend at the end of the series, as in bin 50, points to a change the model misses.

Within each facet, a missing or excluded observation breaks the residual line and its trend. A single observed value is drawn as a point. Each consecutive run of 2-5 observations has a linear trend, and a run of 6 or more uses loess.

Arguments and defaults

Log residuals by time step

# Draw this figure
plot_residuals(b, facet_by = "year", line_size = 0.6)

Log residuals by time step

The same residuals arranged by length, with one panel per time step, length on the horizontal axis, a zero line and a smoother. Look for length ranges with residuals persistently above or below zero. The positive spikes in the largest bin from 2015 onward indicate observed indices above the fitted values in those years. Repeated changes in sign can suggest length-dependent misfit; the smoother crossing zero at a particular length is not itself evidence of bias at that length.

Arguments and defaults

Log recruitment deviations

# Draw this figure
plot_deviance(b, type = "R", log = TRUE, se = TRUE,
  point_size = 1.2, line_size = 0.5)

Log recruitment deviations

The points are estimated log recruitment deviations and the bars are approximate 95% intervals. Zero corresponds to the median recruitment of the fitted process, exp(mean_log_R). A negative estimate indicates recruitment below that median.

Arguments and defaults

Recruitment relative to the process median

# Draw this figure
plot_deviance(b, type = "R", log = FALSE, se = TRUE,
  point_size = 1.2, line_size = 0.5)

Recruitment relative to the process median

With log = FALSE, each point is recruitment divided by the process median. A ratio of 1.77, as in 2012, means that estimated recruitment was 77% above that median. The interval endpoints are exponentiated from the log scale.

Arguments and defaults

Log fishing mortality deviations

# Draw this figure
plot_deviance(b, type = "F", log = TRUE, se = TRUE,
  point_size = 1.2, line_size = 0.5)

Log fishing mortality deviations

Points and approximate 95% intervals show log fishing mortality deviations over time. Zero corresponds to the process median, exp(mean_log_F), on the original scale. ALSCL shows one panel per length bin, ACL one per age class. A fit with shared F has one panel, labelled "All length bins" (ALSCL) or "All age classes" (ACL).

Arguments and defaults

Fishing mortality relative to the process median

# Draw this figure
plot_deviance(b, type = "F", log = FALSE, se = TRUE,
  point_size = 1.2, line_size = 0.5)

Fishing mortality relative to the process median

Each point is the fitted fishing mortality rate divided by the process median. A ratio of 0.5 means fishing mortality was half that median. The error bars show the approximate 95% intervals after exponentiation.

Arguments and defaults

Length composition ridges

# Draw this figure
plot_ridges(b) # Default blue gradient

Length composition ridges

Each ridge shows the relative survey index across lengths in one time step, with observations on the left and the fit on the right. plot_ridges() returns a patchwork object with one figure title and a title on each panel; p[[1]] and p[[2]] extract the observed and the fitted panel. The time axis shows years for annual fits and quarters, as in "2000 Q2", for quarterly fits. After 2013 the compositions hold more fish at larger lengths than in 2010-2012, although the peak stays near 20 to 22 cm in most years. Compare the position and spread of the distributions. A step with no observations has no observed ridge, and a partially observed step is normalized over the observed bins only.

Missing or excluded length bins break the observed outline and fill. An isolated observed bin is drawn as a point at its scaled composition height; normalization still uses all positive observations in that time step. Both panels keep the same time positions, vertical range and time colors, including time steps without observations. Brewer palettes such as spectral also support results with two time steps.

Arguments and defaults

Both ridge panels retain the full model length range, even when the shortest or longest bins are unobserved or all observations are missing. Custom x_breaks and global x_expand apply to both panels. ridges_scale must be NULL (automatic height) or one finite positive number; zero, negative values, missing values, infinity and vectors are rejected.

Missing boundary length bins

This synthetic illustration has no observations in the two smallest or two largest length bins, and no observations in the first time step. Both panels still span 10-90 length units and keep all four time positions. The observed composition uses the remaining bins; the fitted composition uses all bins, so their normalizing totals differ. Blank areas are not zero observations.

# Synthetic display example with missing boundary length bins.
lengths <- seq(10, 90, 10)
years <- 2000:2003
log_index <- outer(lengths, seq(35, 50, 5),
  function(length, center) -((length - center) / 18)^2)
ridge_example <- list(year = years, len_mid = lengths,
  observations = exp(log_index), report = list(Elog_index = log_index))
ridge_example$observations[c(1, 2, 8, 9), ] <- NA_real_
ridge_example$observations[, 1L] <- NA_real_
plot_ridges(ridge_example, ridges_scale = 1,
  x_breaks = seq(10, 90, 20))

Missing boundary length bins

Search documentation