Plot the residuals of the fit to each index over time with three-sigma control limits and a runs test for non-random residuals (Carvalho et al. 2017), as in JABBA and ss3diags (SSplotRunstest()).

plot_runs_test(
  dat,
  fleet = NULL,
  module = NULL,
  interactive = TRUE,
  ncol = NULL,
  make_rda = FALSE,
  figures_dir = getwd()
)

Arguments

dat

A tibble from convert_output() with labels "index_observed" and "index_predicted".

fleet

Character vector. Fleet(s) to plot. Default: NULL (all fleets)

module

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()

interactive

Logical. TRUE/FALSE; indicate whether the environment is interactive.

Default: FALSE

ncol

Number. Number of columns of panels. Default: NULL

make_rda

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.

figures_dir

Path. Path to the "figures" folder.

Default: getwd()

The folder is created within the path if it does not exist.

Value

A ggplot2 object.

Details

Residuals are \(\log(o) - \log(p)\) for observed \(o\) and predicted \(p\), assuming lognormal errors. The one-sided runs test checks whether residual signs are random over time (normal approximation, as in ss3diags). The shaded band spans the three-sigma limits, with sigma from the average moving range; it is green when the test passes (p >= 0.05) and red when it fails. Residuals outside the limits are filled red.

No observations are dropped silently: a fleet observed in more than one area, season, subseason, month, or sex becomes separate series (e.g., "Survey (season 2)"), observations without a positive observed and predicted value are reported in a message, and output from more than one model or with values that cannot be told apart is an error. Years with no observed index (BAM reports every year) are not observations.

References

Carvalho, F., et al. 2017. Can diagnostic tests help identify model misspecification in integrated stock assessments? Fisheries Research 192: 28-40.

Examples

plot_runs_test(stockplotr::example_data, interactive = FALSE)