R code from: Diagnosing common sources of lack of fit to composition data in fisheries stock assessment models using One-Step-Ahead (OSA) residuals
Data files
Oct 10, 2025 version files 30.12 KB
-
OSA_code_final.R
28.63 KB
-
README.md
1.50 KB
Abstract
Fisheries stock assessments often include age- and size-composition data to estimate recruitment strengths, mortality rates and management quantities. Compositions inherently have correlation among the categories, and therefore residuals are not independent. One-Step-Ahead (OSA) residuals have been proposed as a replacement for the commonly used (but incorrectly interpreted) Pearson residuals; however, there is no clear best practice for diagnosing model fit when using OSA residuals. We use a simple example to illustrate common sources of model-misspecification and impacts on statistical and visual diagnostics. We find that visual inspection of model fit aggregated across all observations reliably identifies many types of misspecification, visual inspection of Pearson residuals can reveal further lack of fit, and statistical analysis of OSA residuals provides for objective evaluation of both lack-of-fit and overall data weighting. The power to detect model misspecification depends on the sample size, the number of age bins, and the number of years of data. By illustrating common problems when the correct answer is known, this work provides a guideline for model diagnostics using OSA residuals in more complex settings. This R code will reproduce the simulated data and analysis; each of the figures in the paper are also created.
Dataset DOI: 10.5061/dryad.dncjsxmc8
Description of the data and file structure
This R code creates the simulated data and analysis in "Diagnosing common sources of lack of fit to composition data in fisheries stock assessment models using One-Step-Ahead (OSA) residuals"
Files and variables
File: OSA_code_final.R
Description: This script defines the R packages needed to recreate the entire analysis. It creates several functions and the produces the simulated data, analyzes each case described in the paper and produces the figures in the publication and the supplementary material.
Code/software
This code runs in R version 4.5.1. R Core Team. 2025. R: A language and environment for statistical computing. R Foundation for Statistical Computing. Vienna, Austria. https://www.R-project.org.
It requires the following packages:
compResidual: Trijoulet, V., and Nielsen, A. 2022. compResidual: Residual calculation for compositional observations. R package version 0.0.1. https://github.com/fishfollower/compResidual.
TMB: Template Model Builder: A General Random Effect Tool Inspired by 'ADMB'. https://cran.r-project.org/web/packages/available_packages_by_name.html#available-packages-T
