Overview
Rceattle fits CEATTLE, a climate-linked, single- and
multi-species age-structured stock assessment model (Holsman et
al. 2016; Adams et al. 2022), using Template Model Builder (TMB). This
vignette is the starting point for new users: it fits five single- and
multi-species models to walleye pollock, arrowtooth flounder, and
Pacific cod in the Gulf of Alaska and eastern Bering Sea. The workflow
is:
Install
RceattleLoad
Rceattleand associated excel dataFit assessment models:
model 1: single species, recruitment deviations as penalized fixed effects;
model 2: three single-species models fit jointly, recruitment deviations as penalized fixed effects;
model 3: model 2 with natural mortality estimated for each species;
model 4: model 3 with recruitment deviations as random effects;
model 5: multispecies, with time- and age-varying natural mortality due to predation.
Compare models by AIC and Mohn’s rho (retrospective analysis)
Review plots of input data, diagnostics, and results.
1. Installation
Install Rceattle and its dependencies with:
# Not run when the vignette is built: it would reinstall the package mid-render.
# Rceattle (pulls CRAN dependencies automatically; e.g. TMB, Matrix, dplyr)
install.packages("remotes")
remotes::install_github("afsc-assessments/Rceattle")
# Optional: TMBhelper provides richer optimization diagnostics.
# Rceattle falls back to plain nlminb + sdreport if it's not installed.
# devtools::install_github("kaskr/TMB_contrib_R/TMBhelper")2. Data
Data from the 2018 Gulf of Alaska and 2017 eastern Bering Sea single- and multi-species assessments are bundled with the package:
library(Rceattle)
data("GOApollock") # Data for GOA-pollock (1-species) ?GOApollock for more information on the data
data("BS2017SS") # Combined data for 3 species. ?BS2017SS for more information on the data
data("BS2017MS") # Multi-species data: lower residual mortality (M1_base) for pollock ages 1-2Plot the data with plot_data():
plot_data(GOApollock)A data list can be written to Excel, edited there, and read back into
R:
Rceattle::write_data(data_list = BS2017SS, file = "BS2017SS.xlsx")
mydata <- Rceattle::read_data( file = "BS2017SS.xlsx")The first sheet (meta_data) and ?BS2017SS
describe the inputs and file structure.
3. Fit models
Models are fit with fit_mod(). Model 1 is a
single-species fit to Gulf of Alaska pollock with no stock–recruit
relationship. It has 8 fleets: 1 fishery, 6 surveys, and 1 fleet turned
off (its data excluded from the likelihood; see
model_1$data_list$fleet_control).
model_1 <- Rceattle::fit_mod(data_list = GOApollock,
inits = NULL, # Initial parameters = 0
estimateMode = 0, # Estimate
random_rec = FALSE, # No random recruitment
fit_control = fit_control(
phase = TRUE,
verbose = 1))
summary(model_1)Model 2 fits three single-species models jointly
(msmMode = 0, the default), with no stock–recruit curve and
natural mortality fixed at the input values
(mydata$M1_base). It has 7 fleets: 3 fisheries (one per
species) and 4 surveys (see mydata$fleet_control).
model_2 <- Rceattle::fit_mod(data_list = mydata,
inits = NULL, # Initial parameters = 0
estimateMode = 0, # Estimate
random_rec = FALSE, # No random recruitment
msmMode = 0, # Single-species
fit_control = fit_control(
phase = TRUE,
verbose = 1))
summary(model_2)Model 3 estimates natural mortality with build_M1();
M1_model = "sex_age_invariant" estimates a single M per
species, constant across sex and age:
model_3 <- Rceattle::fit_mod(data_list = mydata,
estimateMode = 0, # Estimate
M1Fun = build_M1(M1_model = "sex_age_invariant"), # Estimate sex-invariant M)
random_rec = FALSE, # Penalized likelihood
msmMode = 0, # Single species mode
fit_control = fit_control(
phase = TRUE,
verbose = 1))
summary(model_3)Model 4 treats recruitment deviations as random effects
(random_rec = TRUE), starting from model 3’s MLEs and
skipping phasing to reduce run time:
model_4 <- Rceattle::fit_mod(data_list = mydata,
inits = model_3$estimated_params, # Start estimation at model 3's MLEs
estimateMode = 0, # Estimate
M1Fun = build_M1(M1_model = "sex_age_invariant"),
random_rec = TRUE, # Random recruitment
msmMode = 0, # Single species mode
fit_control = fit_control(
phase = FALSE,
verbose = 1))
summary(model_4)Model 5 sets msmMode = 1, running in multi-species mode:
it estimates time- and age-varying natural mortality from predation,
following the MSVPA parameterization of Magnússon
(1995).
model_5 <- Rceattle::fit_mod(data_list = BS2017MS,
inits = model_3$estimated_params, # Initial parameters from single species estimates
M1Fun = build_M1(M1_model = "sex_age_invariant"),
estimateMode = 0, # Estimate
niter = 3, # 3 iterations around population and predation dynamics
random_rec = FALSE, # No random recruitment
msmMode = 1, # MSVPA based
suitMode = 0, # Empirical suitability
fit_control = fit_control(
verbose = 1))
summary(model_5)4. Reading the fitted object
fit_mod() returns an object of class
Rceattle, with the standard S3 methods:
summary(model_1) # reference points, likelihood, convergence
coef(model_1) # estimated parameters
head(vcov(model_1)) # covariance matrix (NULL when getsd = FALSE)
logLik(model_1) # log-likelihood, holding its degrees of freedom
AIC(model_1) # so stats::AIC() works
head(residuals(model_1))
head(as.data.frame(model_1))plot(), simulate() and
profile() dispatch on the fit too. The diagnostics
(retrospective(), jitter(),
self_test(), profile(),
osa_residuals()) return their own classes, whose
print() methods summarize the result. A data list read by
read_data() also prints and summarizes.
Derived quantities on their natural scale (biomass, ssb,
N_at_age, M_at_age, sel_at_age,
reference points and the likelihood components) are in
fit$quantities. The estimated parameters are in
fit$estimated_params, mostly on a log scale, under
abbreviated names that parameter_dictionary() explains:
parameter_dictionary("R_log_sd") # log_sd of recruitment -> sigma_R
parameter_dictionary(process = "selectivity")Anything beginning log_, or ending _log_sd,
needs exp() to reach the quantity named in the dictionary’s
natural column.
quantity_dictionary() does the same for the reported
quantities: what each means, its units and dimensions, and whether
sdreport() gives it a standard error:
quantity_dictionary("ssb_depletion")
quantity_dictionary(process = "reference_points")
# Everything that holds a standard error
dict <- quantity_dictionary()
dict[dict$se, c("quantity", "units")]Units follow the model throughout: numbers-at-age are
thousands of fish and weight-at-age is
kg, so their product is mt.
ssb is female spawning-stock biomass. Every
per-recruit reference point (SPR0, SPRlimit,
SPRtarget) is defined only in single-species mode; on a
multispecies fit the model leaves them at zero, which is not an estimate
of zero.
5. Compare models
Models can be compared by marginal or joint negative log-likelihood, AIC, and retrospective analysis. AIC cannot compare a penalized-likelihood fit against a marginal-likelihood fit.
# Evaluate 1 model
AIC(model_1) # AIC, via the logLik() method
model_1$opt$objective # Negative log-likelihood
model_1$quantities$jnll_comp # Negative log-likelihood components
# Compare AIC across 3-species penalized likelihood models
sapply(list(model_2, model_3, model_5), AIC)report_tables() collects what an assessment reports (the
fit and its likelihood decomposition, time series with uncertainty,
reference points, and fits to index and catch) into tidy tables, each
with a model column so several fits stack for
comparison:
tabs <- report_tables(list(pollock = model_1, three_species = model_2))
tabs
tabs$reference_pointsRead the basis column of reference_points
before quoting from it. A CEATTLE fit leaves a plausible-looking
number for reference points it never estimated:
Ftarget and Flimit sit at 1.0/yr unless the
harvest control rule estimates them, and in multispecies mode
SB0 is a placeholder until a no-fishing projection derives
it. report_tables() returns those cells as NA,
with the reason in basis.
report_tables() never runs a retrospective or a jitter;
pass in the ones you have and the matching sections appear:
report_tables(model_1, retro = model_1_retro, osa = osa_residuals(model_1))standard_output() relabels the result into the NOAA
standardized assessment output read by the stockplotr and
asar packages. That standard describes one stock, so a fit
with more than one species needs species to pick the
stock:
head(standard_output(tabs, model = "pollock"))
head(standard_output(tabs, model = "three_species", species = 1))retrospective() measures retrospective bias, returning a
list of refit models and a data.frame of Mohn’s rho values.
model_1_retro <- retrospective(model_1, peels = 7)
# `mohns` has columns Object, `Forecast year` (0 = each peel's terminal year), N, then
# one column per species. Read the rho by name -- column 2 is `Forecast year`, not a rho.
rho <- subset(model_1_retro$mohns, Object == "biomass" & `Forecast year` == 0)
plot_biomass(model_1_retro$Rceattle_list,
model_names = paste("Pollock; mohns =", round(rho[["Pollock"]], 3)))6. Model plots and diagnostics
Rceattle plots hindcast and projection time series of
biomass, SSB, recruitment, biomass consumed as prey, mortality-at-age,
and depletion, with uncertainty. Time-series plots accept a list of
models.
model_list <- list(model_2, model_3, model_4, model_5)
model_names <- list("single-spp", "Single-spp M", "Single-spp M - RE", "Multi-spp")
# Biomass
plot_biomass(model_list, model_names = model_names, incl_proj = TRUE, add_ci = TRUE)
# Recruitment
plot_recruitment(model_list, model_names = model_names, incl_proj = TRUE, add_ci = TRUE)
# SSB
plot_ssb(model_list, model_names = model_names, incl_proj = TRUE, add_ci = TRUE)
# Biomass depletion (total biomass / B0)
plot_depletion(model_list, model_names = model_names, incl_proj = FALSE, add_ci = FALSE)
# SSB depletion (female spawning biomass / SB0), the quantity a Tier 3 HCR
# compares against B40%
plot_ssb_depletion(model_list, model_names = model_names, incl_proj = FALSE, add_ci = FALSE)Diagnostic plots cover selectivity and the fits to composition, index and catch data. Composition plots take a single model; selectivity, index and catch plots take one or more.
plot_selectivity() draws each fleet on age, or on length
bin for a fleet whose Selectivity_dimension is
"Length". With one model, colour is the year, so
time-varying selectivity reads as a fan; with several, colour separates
the models and the fan moves to transparency.
# Selectivity
plot_selectivity(model_2)
# Overlay models; `line_col` and `lwd` apply as in the other plotters
plot_selectivity(model_list, model_names = model_names, lwd = 2)
# Plot composition fit
plot_comp(model_2)
# Plot index
plot_index(model_list) # - All models
# Plot catch data
plot_catch(model_list)Components of the fitted object, accessed with $:
model_1$initial_params- initial parameter valuesmodel_1$bounds- parameter boundsmodel_1$map- parameter map in factor form (model_1$map$mapFactor) or list form (model_1$map$mapList)model_1$estimated_params- estimated parametersmodel_1$quantities- derived quantities (SSB, biomass, selectivity, etc)model_1$data_list- the input datamodel_1$run_time- model run timemodel_1$obj- the TMB makeadfun object.model_1$opt- the fit_tmb optimization object.model_1$sdrep- the TMB sdreport object.
References
- Adams, G.D., Holsman, K.K., Barbeaux, S.J., Dorn, M.W., Ianelli, J.N., Spies, I., Stewart, I.J., Punt, A.E. (2022). An ensemble approach to understand predation mortality for groundfish in the Gulf of Alaska. Fisheries Research, 251, 106303.
- Holsman, K.K., Ianelli, J., Aydin, K., Punt, A.E., Moffitt, E.A. (2016). A comparison of fisheries biological reference points estimated from temperature-specific multi-species and single-species climate-enhanced stock assessment models. Deep Sea Research Part II, 134, 360-378.
- Magnússon, K.G. (1995). An overview of the multispecies VPA — theory and applications. Reviews in Fish Biology and Fisheries, 5, 195-212.