R/plot_joint_residuals.R
plot_joint_residuals.RdPlot the residuals of the fits to all indices over time with a loess
smoother and a fit statistic, as in JABBA (jbplot_residuals() and
jbplot_stdresiduals()) and ss3diags (SSplotJABBAres()). A trend in
the smoother shows a pattern in the residuals; a large statistic shows a
poor fit.
plot_joint_residuals(
dat,
fleet = NULL,
module = NULL,
scaled = FALSE,
overlay = TRUE,
show_stat = TRUE,
ncol = NULL,
interactive = TRUE,
make_rda = FALSE,
figures_dir = getwd()
)A tibble from convert_output() with labels "index_observed"
and "index_predicted".
Character vector. Fleet(s) to plot. Default: NULL (all fleets)
Character vector. (Optional) Module name found in dat$module_name.
If selecting >1 module, place them in a vector like c("module1", "module2").
Default: NULL
If the interactive and >1 module_name is found, user will select the
module_name in the console. @seealso filter_data()
Logical. TRUE/FALSE; plot standardized residuals (log residuals divided by their standard error) instead of log residuals.
Default: FALSE
Logical. TRUE/FALSE; plot all indices on one panel, with a boxplot of the residuals in each year. FALSE plots each index on its own panel.
Default: TRUE
Logical. TRUE/FALSE; show the fit statistic in the top
right corner of each panel: the root mean square error (RMSE) of log
residuals, or the standard deviation of normalized residuals (SDNR) of
scaled residuals. When overlay = TRUE, the statistic of each index is
also shown in the legend.
Default: TRUE
Number. Number of columns of panels when overlay = FALSE.
Default: NULL
Logical. TRUE/FALSE; indicate whether the environment is interactive.
Default: FALSE
Logical. TRUE/FALSE; indicate whether to save the object and
make an automated caption and alternative text in the form of an rda object. If TRUE,
the rda will be exported to the folder indicated in the argument "figures_dir".
Default: FALSE.
Path. Path to the "figures" folder.
Default: getwd()
The folder is created within the path if it does not exist.
A ggplot2 object.
Log residuals are \(r = \log(o) - \log(p)\) for observed
\(o\) and predicted \(p\), as in plot_runs_test(); scaled
residuals are \(z = r / s\) for the log-scale standard error \(s\) of
the observation. The RMSE is \(100 \sqrt{\overline{r^2}}\) percent. The
SDNR is \(\sqrt{\sum z^2 / (n - 1)}\), shown with its critical value
\(\sqrt{\chi^2_{0.95, n - 1} / (n - 1)}\); an SDNR above the critical
value suggests the standard errors are too small (Francis 2011).
The smoother is a loess regression (span 0.75) of the mean residual of each year on year, for all indices together or for each index on its own panel. It is not drawn for fewer than five years of residuals, or when the years are too sparse for a stable fit; a message names the indices without one.
Observations are treated as in plot_runs_test(): a fleet observed in
more than one area, season, subseason, month, or sex becomes separate
series, and observations without a positive observed and predicted value
are reported in a message. Scaled residuals also need a standard error;
observations without one are reported in a message.
Francis, R.I.C.C. 2011. Data weighting in statistical fisheries stock assessment models. Canadian Journal of Fisheries and Aquatic Sciences 68: 1124-1138.
plot_joint_residuals(stockplotr::example_data, interactive = FALSE)
plot_joint_residuals(
stockplotr::example_data,
scaled = TRUE,
overlay = FALSE,
interactive = FALSE
)