Skip to content

Thesis Chapters 3-5: Analysis for the extreme outcome experiments

License

Notifications You must be signed in to change notification settings

joelholwerda/thesis-empirical-extremes

Repository files navigation

PhD thesis analysis code (Chapters 3-5)

In this repository, you can find the analysis code for the experiments in Chapters 3-5 that examined the role of extreme outcomes.

Prerequisites

  • To run the analysis code you will need R and RStudio installed on your computer
  • You will also need to install CmdStanR by following the instructions here

Getting started

The easiest way to access the analysis code is downloading the .zip file. To do this:

  1. Click the "Code" button and then click the "Download ZIP" option
  2. This will download a .zip file containing the code to your computer
  3. Extract the contents of the .zip file to a directory of your choice

Alternatively, you can open the Terminal or Command Prompt, navigate to the folder where you want to clone this repository, and run the following command: git clone https://github.com/joelholwerda/thesis-empirical-extremes.git.

Running the analysis

  1. Open the 00_open_project.Rproj file. This opens a new session in RStudio and sets the working directory to the correct location
  2. Open the 01_wrangle_data.R file. This wrangles the raw data and outputs .csv files loaded in the subsequent models and figures.
  3. Click the "Source" button to run the entire script or highlight sections and press Cmd + Enter
  4. Open and run the 02_model_data.R file. This uses brms to fit the Bayesian models and test the reported hypotheses. Some of these models take several minutes to run. See the "Options" section below for ways to speed up this process
  5. Open and run the 03_create_figures.R file. This creates the figures and saves them as .pdf files in the output/figures folder
  6. Open and run the 04_alternate_models.R file. This includes numerous other models that could have been used to analyse our results and examines whether our conclusions were contingent on the reported models

The renv package is used for dependency management. 01_wrangle_data.R calls renv::restore() to install the correct version of each package listed in the renv.lock file. More information about the renv package can be found here.

Options

You can change the following options in the 02_model_data.R file:

  • Setting options(quick_version = TRUE) allows faster but less precise parameter estimation by reducing the number of samples taken in the brms models. Set to FALSE to reproduce published values
  • The fitted models are cached in output/fitted_models. Setting options(overwrite_saved_models = TRUE) ensures that the models are run every time instead of loading a cached version. In order to save time, this should be set to FALSE unless changes have been made to the model
  • Set run_diagnostics to TRUE to create additional diagnostic plots for the brms models (e.g., rank histograms, posterior predictive checks). Even if FALSE, the Stan warnings (e.g., divergences, rhat) will still be displayed if applicable
  • The number of cores used for the brms models will be the number of available cores minus the value of the reserved_cores variable (or one if the number of reserved cores is greater than or equal to the number of available cores)

Other files

  • The src folder contains various functions used to run the analysis

  • Information about each experiment is stored in the src/wrangle/exp_info folder. This is used to import the raw data using import_csv.R (csv files) and import_mat.R (Matlab files) and perform initial wrangling using wrangle_all_csv.R and wrangle_all_mat.R

Get help

If you have trouble running the code in this repository or have questions, contact me at joeldavidholwerda@gmail.com.

About

Thesis Chapters 3-5: Analysis for the extreme outcome experiments

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages