Learn R Programming

r4ss: R code for Stock Synthesis

Stock Synthesis is a fisheries stock assessment model written in ADMB by Rick Methot. The Stock Synthesis software and many other associated materials are available on the NOAA Virtual Laboratory at https://vlab.noaa.gov/web/stock-synthesis/home. The r4ss package is a collection of R functions for interacting with Stock Synthesis. It is based on the original work of Ian Stewart begun around 2005 and released as an open source R package in 2009. The package has a long list of authors and has benefited from a large community of users making suggestions and reporting issues.

This code comes with no warranty or guarantee of accuracy. It merely represents an ongoing attempt to integrate output plotting, statistics and diagnostics. It is absolutely necessary that prior to use with a new application, the user checks the output manually to verify that there are no plotting or statistical bugs which could incorrectly represent the output files being analyzed.

Installation

The CRAN version of r4ss is out of date. For now, it is necessary to install the main branch directly from GitHub:

install.packages("remotes")
remotes::install_github("r4ss/r4ss")

Ongoing development of r4ss used to take place in the "development" branch, but now is in the "main" branch. Thus, you should no longer need to reference a branch when installing from github unless you are seeking a specific feature that hasn't yet been merged into the main branch.

Once you have installed the r4ss package, it can be loaded using:

library(r4ss)

To get notifications about r4ss, you can watch this GitHub project or follow messages on the forums on Stock Synthesis VLab. Note that to subscribe to the Stock Synthesis VLab forums, an account is required, but those without an account may still view and post forum messages.

A basic vignette can be viewed at https://r4ss.github.io/r4ss/vignettes/r4ss-intro-vignette.html or built locally on your computer using this command to install the package:

remotes::install_github("r4ss/r4ss", build_vignettes = TRUE)

Citing r4ss

Please cite r4ss as:

Ian G. Taylor, Kathryn L. Doering, Kelli F. Johnson, Chantel R. Wetzel, Ian J. Stewart, 2021. Beyond visualizing catch-at-age models: Lessons learned from the r4ss package about software to support stock assessments, Fisheries Research, 239:105924. https://doi.org/10.1016/j.fishres.2021.105924.

Changes

See NEWS.md for a (not very complete) log of changes to r4ss, starting with r4ss v1.24.0 from 2014. The list of commits at https://github.com/r4ss/r4ss/commits/main provides a much more detailed list.

Contributing to r4ss

Interested in contributing to r4ss? We recognize contributions come in many forms, including but not limited to code, reporting issues, creating examples and/or documentation.

We strive to follow the NMFS Fisheries Toolbox Contribution Guide. We also have included r4ss-specific code contribution information in the Git workflow page of the r4ss wiki. Note that these are guidelines, not rules, and we are open to collaborations in other ways that may work better for you. Please feel free to reach out to us by opening an issue in this repository or by emailing the maintainer (call maintainer("r4ss") in R to view the current maintainer's name and email address).

Note that by contributing, you are expect to uphold the code of conduct.

Reporting problems

Please report any issues with this package by posting a new github issue at https://github.com/r4ss/r4ss/issues. You can also write to Ian.Taylor@noaa.gov.

Code of conduct

This project and everyone participating in it is governed by the NMFS Fisheries Toolbox Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to fisheries.toolbox@noaa.gov. Note that the maintainers of r4ss do not have access to this email account, so unacceptable behavior of maintainers can also be reported here.

The NMFS Fisheries Toolbox Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq

Copy Link

Version

Install

install.packages('r4ss')

Monthly Downloads

540

Version

1.44.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

May 26th, 2022

Functions in r4ss (1.44.0)

SS_changepars

Change parameters, bounds, or phases in the control file.
SS_output

A function to create a list object for the output from Stock Synthesis
SS_Sensi_plot

Create relative sensitivity plots as described in Cope and Gertseva (2020)
SS_doRetro

Run retrospective analyses
SS_fitbiasramp

Estimate bias adjustment for recruitment deviates
SS_read_summary

read ss_summary file
SS_read

Read all Stock Synthesis input files for a model
SS_html

Create HTML files to view figures in browser.
SSMethod.Cond.TA1.8

Apply Francis composition weighting method TA1.8 for conditional age-at-length fits
SS_readforecast

read forecast file
SS_makeHTMLdiagnostictable

Make html diagnostic tables
SS_readpar_3.24

read ss.par file from SS version 3.24
SS_parlines

Get parameter lines from Stock Synthesis control file
SS_readdat_2.00

read data file from SS version 2.00
SS_varadjust

Modify variance and sample size adjustments in the control file
SS_readdat_3.00

read data file from SS version 3.00
SS_plots

plot many quantities related to output from Stock Synthesis
SS_readdat_3.24

read data file from SS version 3.24
SS_write

Write all Stock Synthesis input files for a model
SS_writeforecast

write forecast file
SSgetoutput

Get output from multiple Stock Synthesis models.
SS_writepar_3.24

write ss.par file from SS version 3.24
SS_writepar_3.30

write ss.par file from SS version 3.30
SS_readctl_3.30

read control file from SS version 3.30
SS_ForeCatch

Create table of fixed forecast catches
SS_readdat

read Stock Synthesis data file
SSmakeMmatrix

Convert a matrix of natural mortality values into inputs for Stock Synthesis
SS_readdat_3.30

read data file from SS version 3.30
SSplotCohortCatch

Plot cumulative catch by cohort.
SS_readstarter

read starter file
SS_writewtatage

Write weight-at-age file
SS_readpar_3.30

read ss.par file from SS version 3.30
SS_profile

Run a likelihood profile in Stock Synthesis.
SS_readctl

Read control file from SS
SSplotBiology

Plot biology related quantities.
SS_readctl_3.24

read control file from SS version 3.24
SS_splitdat

Split apart bootstrap data to make input file.
SS_tune_comps

Calculate new tunings for length and age compositions and (re)run models
SSbiologytables

A function to create a table of biology for assessment reporting: length, weight, % mature, fecundity, and selectivity
SS_recdevs

Insert a vector of recruitment deviations into the control file.
SS_readwtatage

Read weight-at-age data file
SSplotMnwt

Plot mean weight data and fits.
SSdiagsTime2Year

Convert Time-Steps
SSplotMovementMap

Show movement rates on a map.
SSbootstrap

Fit models to parametric bootstraps
SSplotYield

Plot yield and surplus production.
SSplotRetroRecruits

Make squid plot of retrospectives of recruitment deviations.
SSplotSPR

Plot Spawning Potential Ratio (SPR) quantities.
SS_writedat_3.24

write data file for SS version 3.24
SSplotData

Timeline of presence/absence of data by type, year, and fleet.
SSplotCatch

Plot catch related quantities.
SSplotComps

Plot composition data and fits.
SStableComparisons

make table comparing quantities across models
SS_writedat_3.30

write data file for SS version 3.30
SSplotNumbers

Plot numbers-at-age related data and fits.
SS_writestarter

write starter file
SSplotRecdevs

Plot recruitment deviations
SSplotComparisons

plot model comparisons
SSplotRecdist

Plot of recruitment distribution among areas and seasons
SSplotTimeseries

Plot timeseries data
SSplotTags

Plot tagging data and fits
check_model

Check input argument model
get_tuning_table

Get the tuning table
copy_SS_inputs

Copy a the Stock Synthesis input files from one directory to another
get_tv_parlabs

Get time varying parameter labels
SSmohnsrho

Calculate Mohn's Rho values for select quantities
mountains

Make shaded polygons with a mountain-like appearance
mcmc.out

Summarize, analyze and plot key MCMC output.
selShapes

Launch a shiny app that displays various selectivity curves
SSplotAgeMatrix

Plot matrix of either length or observed age at true age
SSplotDynamicB0

Plot Dynamic B0
SSplotPars

Plot distributions of priors, posteriors, and estimates.
get_SIS_info

Gather information for the NOAA Species Information System (SIS)
SSsummarize

Summarize the output from multiple Stock Synthesis models.
get_comments

Collect comments lines starting from "#C" in datfile, ctlfile, starter.ss, forecast.ss etc
sspar

Allow Multi-Plots Set the par() to options suitable for ss3diags multi plots.
rich.colors.short

Make a vector of colors.
read.admbFit

Read ADMB .par and .cor files.
is.wholenumber

Utility function to test if x is "numerically" integer wrt machine epsilon taken from example section of help of is.integer
make_multifig

Create multi-figure plots.
translate_3.30_to_3.24_var_adjust

Use 3.30 variance adjustments to create the 3.24 formatting
SSplotProfile

Plot likelihood profile results
SSunavailableSpawningOutput

Plot unavailable spawning output
check_inputlist

Check input argument inputlist
bubble3

Create a bubble plot.
SS_writectl

Write Stock Synthesis control file
stackpoly

modified from "stackpoly" by Jim Lemon from "plotrix" package
make_multifig_sexratio

Create multi-figure sex ratio plots.
mcmc.nuisance

Summarize nuisance MCMC output
SSplotDiscard

Plot fit to discard fraction.
write_fwf4

Function to write formatted table similar to table written by gdata::write.fwf from data.frame or matrix This function does not accept columns or logical with factor
translate_3.30_to_3.24_Q_setup

Use 3.30 q options to create the 3.24 q setup
file_increment

Rename Stock Synthesis files by adding integer value
SSplotSexRatio

Plot sex-ratio data and fits for two sex models
SSplotSelex

Plot selectivity
r4ss-package

r4ss: R Code for Stock Synthesis
SSplotSpawnrecruit

Plot spawner-recruit curve.
SSplotSummaryF

Plot the summary F (or harvest rate).
getADMBHessian

Read admodel.hes file
plotCI

Plot points with confidence intervals.
populate_multiple_folders

Populate multiple Stock Synthesis folders with input files
SSplotMCMC_ExtraSelex

Plot uncertainty around chosen selectivity ogive from MCMC.
r4ss_logo

Make a simple logo for r4ss organization on GitHub
SSplotMovementRates

Plot movement rates from model output
SS_writectl_3.24

write control file
SS_writectl_3.30

write control file for SS version 3.30
SSexecutivesummary

A function to create a executive summary tables from an SS Report.sso file
SS_writedat

write Stock Synthesis data file
SSgetMCMC

Read MCMC output.
SSplotIndices

Plot indices of abundance and associated quantities.
run_SS_models

Run multiple Stock Synthesis models
get_last_phase

Get the highest phase used in the control file
save_png

Open png device and return info on the file being created
TSCplot

Create a plot for the TSC report
add_legend

Add legend to plots
get_dat_new_name

Get the name of the data .ss_new file in a directory
SS_decision_table_stuff

Extract total catch, spawning output, and fraction unfished from forecast years
NegLogInt_Fn

Perform SS implementation of Laplace Approximation
SSMethod.TA1.8

Apply Francis composition weighting method TA1.8
PinerPlot

Make plot of likelihood contributions by fleet
DoProjectPlots

Make plots from Rebuilder program
SS_RunJitter

Iteratively apply the jitter option in SS