Skip to content
No description, website, or topics provided.
Stan R Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Code used in Parameterizations for Bayesian state-space models

Status: Accepted at Fisheries Research



  • make: Optional, allows for automating fitting and postprocessing
  • Rtools: Windows, required for rstan

R packages

  • rstan: Interface to Stan
  • later: Required for among-chain parallelization (rstan issue 556)
  • tidyverse: Fit management, postprocessing management, and plotting
  • gsl: Provides Lambert $W$ function used in prior on Pella-Tomlinson shape parameter
  • sn: Provides skew normal functions
  • ggridges: Additional plot types for ggplot2
  • gridExtra: Combining and manipulating plots from ggplot2
  • flextable : Output pretty tables to MS Word

Reproducing the model fits

This is easy if you have make installed. Just use

make fits

in the top-level directory of this repository (typically tunabayes, otherwise the directory with Makefile.

If you don't have make, you can manually source each of the relevant R scripts. Be sure that the working directory is the top directory of this repository. From the R prompt, this would be


Either way, the result will be three (large) files in the results directory

  • fullPT_fits.Rds
  • fixedPT_fits.Rds
  • Schaefer_fits.Rds

Postprocessing the fits

The make approach

make results

Note that if the three *_fits.Rds results are not available, this will also run the fits.

Otherwise, from the same working directory in R


Note that each of these scripts require loading the *_fits.Rds files into memory. Without a large amount of memory, it will probably be easiest to restart R between running these. The make version already does this.

Either of these will add six new files to the results directory

  • fullPT_summaries.Rds
  • fullPT_diagnostics.Rds
  • fixedPT_summaries.Rds
  • fixedPT_diagnostics.Rds
  • Schaefer_summaries.Rds
  • Schaefer_diagnostics.Rds


There is no make option for the figures (yet), but they are fairly straightforward and quick to produce. In R from the same working directory,


All five figures will be in the figs directory, as both TIFF and PDF types. The TIFF files are inserted into the Word manuscript, and the PDFs are high quality vector images for the published version. Figure 2 also outputs an SVG version. This is lightly edited in Inkscape for the publication version. The axes for the two constrained P parameterization that were not fit are moved to the nearest facets in each direction.

Supplementary Appendices

Supplementary Appendix A is a Word file with a description and table.

Supplementary Appendix B summarizes the priors for the Pella-Tomlinson shape parameter, the coefficient of variation of the catch observations, and the prior on each instantaneous fishing mortality rate. This can be generated by running


Supplementary Appendix C plots priors for parameters and derived quantities not presented in the manuscript. Note that this loads the full fits and may be slow and/or use large amounts of memory during rendering.


Again, these should be run with the top level directory in this repository as the working directory. This is not the default when knitting documents in RStudio.

You can’t perform that action at this time.