Code Monkey home page Code Monkey logo

tunabayes's Introduction

Code used in Parameterizations for Bayesian state-space models

Status: Accepted at Fisheries Research

Prerequisites

System

  • 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

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 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

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 results directory

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

Figures

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 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

rmarkdown::render("notes/Manuscript/Appendix_B_Priors.Rmd")

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.

rmarkdown::render("notes/Manuscript/Appendix_C_posteriors.Rmd")

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.

tunabayes's People

Contributors

jkbest2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.