Skip to contents

Performs retrospective peels by truncating the input data, optionally applying Francis reweighting and parallelization, and returns estimates of spawning stock biomass (SSB) and recruitment for each peel.

Usage

do_retrospective(
  n_retro,
  data,
  parameters,
  mapping,
  random = NULL,
  do_par,
  n_cores,
  newton_loops = 3,
  do_francis = FALSE,
  n_francis_iter = NULL,
  nlminb_control = list(iter.max = 1e+05, eval.max = 1e+05, rel.tol = 1e-15),
  do_sdrep = FALSE,
  fishidx_datalag = array(0, dim = c(data$n_regions, data$n_fish_fleets)),
  fishage_datalag = array(0, dim = c(data$n_regions, data$n_fish_fleets)),
  fishlen_datalag = array(0, dim = c(data$n_regions, data$n_fish_fleets)),
  srvidx_datalag = array(0, dim = c(data$n_regions, data$n_srv_fleets)),
  srvage_datalag = array(0, dim = c(data$n_regions, data$n_srv_fleets)),
  srvlen_datalag = array(0, dim = c(data$n_regions, data$n_srv_fleets)),
  tag_datalag = 0
)

Arguments

n_retro

Integer. Number of retrospective peels to perform.

data

List. Data input for the RTMB model.

parameters

List. Parameter values for the RTMB model.

mapping

List. Mapping information for the RTMB model.

random

Character vector. Names of random effects in the model. Default is NULL.

do_par

Logical. Whether to run retrospective peels in parallel. Default is FALSE.

n_cores

Integer. Number of cores to use for parallel execution if do_par = TRUE.

newton_loops

Integer. Number of Newton loops to run during model fitting. Default is 3.

do_francis

Logical. Whether to apply Francis reweighting within each retrospective peel. Default is FALSE.

n_francis_iter

Integer. Number of Francis reweighting iterations. Required if do_francis = TRUE.

nlminb_control

List. Control parameters passed to nlminb during model fitting. Default is list(iter.max = 1e5, eval.max = 1e5, rel.tol = 1e-15).

do_sdrep

Logical. Whether to return standard errors from sdreport. Default is FALSE.

fishidx_datalag

Integer array. Lags for fishery index data [regions x fleets]. Default is zeros.

fishage_datalag

Integer array. Lags for fishery age composition data [regions x fleets]. Default is zeros.

fishlen_datalag

Integer array. Lags for fishery length composition data [regions x fleets]. Default is zeros.

srvidx_datalag

Integer array. Lags for survey index data [regions x fleets]. Default is zeros.

srvage_datalag

Integer array. Lags for survey age composition data [regions x fleets]. Default is zeros.

srvlen_datalag

Integer array. Lags for survey length composition data [regions x fleets]. Default is zeros.

tag_datalag

Integer. Lag for tagging data. Default is 0.

Value

A data.frame containing retrospective estimates of SSB and recruitment. Columns include:

  • Region: Region index.

  • Year: Year index.

  • Type: "SSB" or "Recruitment".

  • peel: Peel number (0 = full data, 1 = 1-year peel, etc.).

  • value: Estimated value of SSB or recruitment.

  • pdHess and max_grad (optional): Information from sdreport if do_sdrep = TRUE.

Examples

if (FALSE) { # \dontrun{
# Run a 7-year retrospective
ret <- do_retrospective(
  n_retro = 7,
  data = data,
  parameters = parameters,
  mapping = mapping,
  random = NULL,
  do_par = TRUE,
  n_cores = 7,
  do_francis = TRUE,
  n_francis_iter = 5
)

# Plot retrospective SSB and Recruitment
library(ggplot2)
ggplot(ret, aes(x = Year + 1959, y = value, group = peel, color = 2024 - peel)) +
  geom_line(lwd = 1.3) +
  facet_wrap(~Type) +
  guides(color = guide_colourbar(barwidth = 10, barheight = 1.3)) +
  labs(x = 'Year', y = 'Value', color = 'Retrospective Year') +
  scale_color_viridis_c() +
  theme_bw(base_size = 15) +
  theme(legend.position = 'top')
} # }