plot_deviance()
View source ↗On this page
Plot the process deviations of log recruitment or log fishing mortality of a fit by time step, on the log scale or as ratios to the median.
Usage
plot_deviance(
model_result,
se = FALSE,
point_size = NULL,
point_color = "white",
point_shape = 21,
line_size = NULL,
line_color = NULL,
line_type = "solid",
se_color = NULL,
se_width = NULL,
facet_ncol = NULL,
facet_scales = "free",
log = TRUE,
type = c("R", "F"),
title = NULL,
xlab = NULL,
ylab = NULL,
font_family = NULL,
title_size = NULL,
axis_title_size = NULL,
axis_text_size = NULL,
strip_text_size = NULL,
legend_text_size = NULL,
x_breaks = NULL,
base_theme = NULL,
title_hjust = NULL
)
Arguments
| Argument | Default | Description |
|---|---|---|
model_result | required | A fit from |
se | FALSE | Logical. Draw approximate 95% intervals from the standard errors. Default FALSE. |
point_size | NULL | Numeric or NULL. Size of the points. NULL inherits the global point_size setting (default 2.5). |
point_color | "white" | Character. Fill color of the points, used by shapes 21-25. Default "white". |
point_shape | 21 | Numeric. Shape code of the points, such as 16 or 21. Default 21. |
line_size | NULL | Numeric or NULL. Line width. NULL inherits the global line_size setting (1 under the default style, 1.5 under "classic"). While that setting keeps the value of the style, facets of more than four panels draw thinner lines. |
line_color | NULL | Character or NULL. NULL inherits the global recruitment_color (type "R") or F_color (type "F") setting, or line_color when that is NULL. |
line_type | "solid" | Character. Line type, such as "solid" or "dashed". Default "solid". |
se_color | NULL | Character or NULL. Error bar color. NULL takes the color of the line, or the global se_color when it was set to a color other than the band color of the palette. |
se_width | NULL | Numeric or NULL. Width of the error-bar caps in years; does not change the standard errors or interval lengths. NULL (default) uses a quarter of the time step. |
facet_ncol | NULL | Integer or NULL. Number of columns of panels. NULL chooses it from the number of panels, for example 5 × 3 for 15 panels and 6 × 4 for 23. |
facet_scales | "free" | Character. Axis scales of the panels, "fixed", "free", "free_x" or "free_y". Letter case does not matter. |
log | TRUE | Logical. TRUE plots the log process deviations; FALSE plots their exponentials, the ratios to the median, with a reference value of 1. |
type | c("R", "F") | Character. "R" for the process deviations of recruitment, "F" for those of fishing mortality. Letter case does not matter. |
title | NULL | NULL (default) draws the default title, FALSE, NA or "" draws no title, and a character string draws that string; see |
xlab | NULL | Character or NULL. Label of the x axis. NULL uses the global theme setting. |
ylab | NULL | Character or NULL. Label of the y axis. NULL uses the global theme setting. |
font_family | NULL | Character or NULL. Font family of the text, which must be installed on the computer. NULL uses the global theme setting (default "sans"). |
title_size | NULL | Numeric or NULL. Size of the plot title in pt. NULL uses the global theme setting (default 14). |
axis_title_size | NULL | Numeric or NULL. Size of the axis titles in pt. NULL uses the global theme setting (default 12). |
axis_text_size | NULL | Numeric or NULL. Size of the axis tick labels in pt. NULL uses the global theme setting (default 10). |
strip_text_size | NULL | Numeric or NULL. Size of the panel labels in pt. NULL uses the global theme setting (default 10). |
legend_text_size | NULL | Numeric or NULL. Size of the legend text in pt. NULL uses the global theme setting (default 10). |
x_breaks | NULL | Numeric vector or NULL. Positions of the x-axis breaks. NULL inherits the global x_breaks setting when at least one of its values lies on this axis; otherwise the breaks are chosen automatically. |
base_theme | NULL | Character or NULL. Name of the base ggplot2 theme, such as "bw", "minimal" or "theme_bw". NULL uses the global theme setting. Letter case does not matter. |
title_hjust | NULL | Numeric or NULL. Horizontal position of the title, 0 for left, 0.5 for centered and 1 for right. NULL uses the global theme setting. |
Value
A ggplot object, which can be styled further or saved with acl_save_plot().
Details
The function plots report$dev_log_R (type = "R") or report$dev_log_F (type = "F") over time. log = TRUE shows the log process deviations, which are zero where recruitment or F equals its median, exp(mean_log_R) or exp(mean_log_F). log = FALSE shows their exponentials, the ratios to that median, with a reference value of 1. These are process deviations, not likelihood deviances.
With type = "F", ACL draws one panel per age class and ALSCL one per length bin; a fit with F_structure = "year" has a single panel for the shared F. ACL panels are in age order and labelled with the fitted ages in model_result$age; the oldest age class is the plus group, labelled for example "Age 15+". Titles and y-axis labels come from the theme keys dev_R and dev_F, or dev_R_multiplier and dev_F_multiplier with log = FALSE. A title, xlab, ylab or typography argument given in the call replaces the corresponding theme setting.
se = FALSE uses the reported deviations and needs no standard errors. se = TRUE draws error bars at the deviation plus and minus 1.96 standard errors on the log scale (exponentiated with log = FALSE) and needs complete, finite, nonnegative standard errors.
Additional details from R help
With se = FALSE, estimates come from report$dev_log_R or
report$dev_log_F without a table of standard errors; a saved result
without these reported quantities uses the finite Estimate column of
est_std. With se = TRUE, a complete table of finite estimates and finite
nonnegative standard errors is required. Groups and time steps
must match the model metadata, including the single group for shared F.
ACL age panels are labelled with the fitted ages in model_result$age;
the oldest age class is a plus group and is marked with a plus sign, for
example "Age 15+". Results saved without age metadata keep the position
labels "Age bin 1", "Age bin 2" and so on.
Titles and y-axis labels use the global dev_R/dev_F keys on the log
scale, and dev_R_multiplier/dev_F_multiplier keys after exponentiation.
A title, xlab or ylab given in the call replaces the
theme label, and the typography arguments replace the corresponding theme settings.
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_deviance(b, type = "R", log = TRUE, se = TRUE,
point_size = 1.2, line_size = 0.5)

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