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: Interface to Stan
later: Required for among-chain parallelization (
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
gridExtra: Combining and manipulating plots from
flextable: Output pretty tables to MS Word
Reproducing the model fits
This is easy if you have
make installed. Just use
in the top-level directory of this repository (typically
tunabayes, otherwise the directory with
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
source("src/31_fitfullPT.R") source("src/32_fitfixedPT.R") source("src/33_fitSchaefer.R")
Either way, the result will be three (large) files in the
Postprocessing the fits
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
source("src/41_fullPT_summaries.R") source("src/43_fixedPT_summaries.R") source("src/45_Schaefer_summaries.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
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,
source("src/51_fig1_data.R") source("src/52_fig2_diagplots.R") source("src/53_fig3_effplots.R") source("src/54_fig4_biopost.R") source("src/55_fig5_mgtpost.R")
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 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.