plot_self_test()
View source ↗On this page
Plot the median relative error of a self-test with a percentile band by time step for each time series, and with percentiles for each estimated parameter.
Usage
plot_self_test(
x,
what = c("both", "series", "parameters"),
probs = c(0.1, 0.9),
line_size = NULL,
line_color = NULL,
se_color = NULL,
se_alpha = NULL,
point_size = NULL,
facet_ncol = NULL,
facet_scales = "free_y",
return_data = FALSE,
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 |
|---|---|---|
x | required | An |
what | c("both", "series", "parameters") | "both" (default) draws the time series above the parameters; "series" or "parameters" draws one part. Letter case does not matter. |
probs | c(0.1, 0.9) | Two probabilities, the lower and upper percentiles of the band; default the 10th and 90th percentiles. |
line_size | NULL | Numeric or NULL. Line width. NULL inherits the global line_size setting. |
line_color | NULL | Color of the median line and points; NULL inherits the global line_color setting. |
se_color | NULL | Color of the band; NULL inherits the global se_color setting. |
se_alpha | NULL | Opacity of the band; NULL inherits the global se_alpha setting. |
point_size | NULL | Size of the median point of each parameter; NULL inherits the global point_size setting. |
facet_ncol | NULL | Numeric or NULL. Columns of the time-series panels; NULL chooses them from the number of panels. |
facet_scales | "free_y" | Character. Axis scales of the time-series panels, "fixed", "free", "free_x" or "free_y". Default "free_y". Letter case does not matter. |
return_data | FALSE | Logical. TRUE also returns the plotted data; see the value. Default FALSE. |
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 relative-error 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 (a patchwork for what = "both"), or a list with plot, series and parameters (the plotted medians and percentiles, in percent) when return_data = TRUE.
Details
The upper panels show, for each time series, the median relative error by time step (line) and a band between two percentiles; the lower panel shows the median and the same percentiles for each estimated parameter. A dashed line marks no error. Only refits that pass the numerical checks are drawn, and the subtitle gives their number. Parameters are on the natural scale of extract_parameters() and are named in words, for example "Asymptotic length (Linf)" for log_Linf; a parameter whose truth is zero has no relative error and is not drawn. In the data returned with return_data = TRUE, the column parameter holds the code name and Parameter the name in words. The title uses the theme key self_test; the axis labels use xlab$year and ylab$relative_error.
Additional details from R help
The relative error is (estimate - truth) / truth, shown in
percent; the truth of each replicate is described in self_test().
Refits that fail the numerical checks are not drawn; the subtitle gives
the number of refits drawn. Parameters are on the natural scale of
extract_parameters(). The plot labels them in words, for example
"Median recruitment". With return_data = TRUE the column parameter
of parameters holds the name used in code, for example "mean_log_R",
and the column Parameter the label of the plot. A parameter whose
truth is zero has no relative error and is not drawn.
The title uses the theme key self_test; the axis labels use
xlab$year and ylab$relative_error.
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)
# Use objects defined above
st <- self_test(a, nsim = 5, seed = 20261101)
plot_self_test(st)
plot_self_test(st, what = "series", probs = c(0.05, 0.95))

plot_self_test(st)