Skip to contents

Southern bluefin roam,
Data rich as ocean tides—
Code unlocks their truth.

Introduction

The R package sbt was developed for doing stock assessments of southern bluefin tuna (SBT) for the Commission for the Conservation of Southern Bluefin Tuna (CCSBT).

The sbt model was coded using the RTMB package, which provides an R interface (R Core Team 2026) for Template Model Builder (TMB) and avoids the need to code the model in C++ (Kristensen et al. 2016). The sbt model is bespoke to SBT: it is age-structured, with two seasons per year and one region. Six fisheries are defined to account for removals through catch using an areas-as-fleets approach, and time-varying selectivity is defined for some of these fisheries.

Frequentist inference can be done using the nlminb() optimizer in R’s stats package, and Bayesian inference can be done using the SparseNUTS package (Monnahan et al. 2026). The help pages for sbt are available on the sbt website. The Get started and Articles pages are the best place to see what sbt can do.

The southern bluefin tuna in the sbt logo was painted by Joanne Webber (https://www.joannewebber.co.nz).

Fitted-model workflow

The standard interface keeps configuration, optimisation, diagnostics, and posterior samples in one portable object:

fit <- sbt_fit(data)
fit <- sbt_optimise(fit)
fit <- sbt_mcmc(fit)
sbt_fit_save(fit, "assessment.sbt.rds")

Parameters, priors, maps, and bounds are resolved automatically. Use the sbt_add_*() setters for explicit overrides and sbt_obj() only when an external API requires the transient RTMB objective.

Installation

There are several options for installing the sbt R package. The GitHub repository is private, so you need GitHub access to quantifish/sbt and a personal access token (PAT) stored in your Git credentials before installing directly from GitHub.

Option 1: install from GitHub

Set up GitHub credentials once:

install.packages(c("remotes", "usethis", "gitcreds"))
usethis::create_github_token()
gitcreds::gitcreds_set()

Then install sbt from within R:

remotes::install_github(repo = "quantifish/sbt", dependencies = NA)

dependencies = NA installs the packages needed for normal model fitting and reporting without attempting to install every optional article and diagnostic dependency.

Optional composition residuals

plot_tags_residuals() requires the suggested compResidual package. Some other composition-residual functions use it only as a fallback when RTMB cannot produce finite one-step-ahead residuals. Normal fitting, MLE and MCMC checks, and the other plots do not require it.

The upstream package expects an external OSA distribution header that it does not bundle. From an sbt source clone, install the pinned, tested version with:

comp_residual_include="$(./tools/prepare-comp-residual.sh)"
PKG_CPPFLAGS="-I${comp_residual_include}" Rscript -e \
  'remotes::install_github("fishfollower/compResidual/compResidual@d4c74845089074d8016454f235044c5d13ded3a5")'

This step is optional unless those residual diagnostics are required.

Do not paste a PAT directly into analysis scripts. Storing it once with gitcreds::gitcreds_set() lets remotes, git, and RStudio use the same credential without exposing it in code.

Option 2: clone then install

The sbt package is available in a private GitHub repository. The repository can be cloned to your computer from the command line or using a user interface. From the command line using Linux, the repository can be cloned using:

git clone https://github.com/quantifish/sbt.git

After cloning the repository, the sbt package can be installed from within R using:

devtools::install("sbt")

or from the command line using:

R CMD INSTALL sbt

Option 3: install from a local source file

If you have the sbt package downloaded on your local machine as a zip or tar.gz file, you can install it using the install.packages() function passing in the path where the zip file is saved, setting repos = NULL and type = source. For example:

install.packages("sbt_3.0.0.tar.gz", repos = NULL,
                 type = "source")

Help

Help for all sbt functions and data sets can be found on the R help pages associated with each function and data set. Help for a specific function can be viewed using ?function_name, for example:

?get_weight_at_age
?plot_cpue

Alternatively, to see a list of all available functions and data sets use:

help(package = "sbt")

References

Kristensen, Kasper, Anders Nielsen, Casper W. Berg, Hans Skaug, and Bradley M. Bell. 2016. “TMB: Automatic Differentiation and Laplace Approximation.” Journal of Statistical Software 70 (5): 1–21. https://doi.org/10.18637/jss.v070.i05.
Monnahan, Cole C., Kasper Kristensen, James T. Thorson, and Bob Carpenter. 2026. Leveraging Sparsity to Improve No-u-Turn Sampling Efficiency for Hierarchical Bayesian Models. https://arxiv.org/abs/2603.02437.
R Core Team. 2026. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. https://www.R-project.org/.