This directory contains the source code for the simulations and the figures found
in the paper. We developed the model in MATLAB and R, with MATLAB responsible
for the simulations, and R responsible for most of the analysis and graphing.

We also provide scripts that we used to generate all outputs reported in the main
text.

===================================================================================
    Main Text Model Runs
    Run these scripts to generate new data sets using the model
===================================================================================
Main Text

2-species Mu Sweep
Run musweep_2spp_mshock.m
* doesn't create a folder-- will dump out results wherever
* script saves outputs as .mat

4-Species Variance Sweep
Run varsweep_4spp_mshock_series.m
* This script will create a folder called  VARSWEEP-4SPP-MSHOCK within the current
  working directory and write outputs into it.

Case Studies
Run aigrettes_varsweep.m
Run flores_varsweep.m

===================================================================================
    Main Text Figures
    Run these scripts to generate paper figures from our original data
===================================================================================

Figure 1
(deterministic-- bifurcation diagram)
(Note that the left panel is generated in MATLAB rather than R)
RIGHT PANEL : Run null_clines_graph.R
LEFT PANEL  : Run bifurcation_leftpanel.m

Figure 2
None-- illustrates the 4-species network before and after various extinctions.

Figure 3
(mortality sweep-- 2 species)
Run varsweep_graphs_mshock.R

Figure 4
(spec-gen extinction comparison, 4spp)
Run mcnemar_calculations.R

Figure 5
(partner number vs. extinction risk over variance range)

Figure 6
(partner number vs. extinction risk with regression fit)
Run case_study_regressions.R


===================================================================================
    Appendix Model Runs
    Run these scripts to generate new data sets using the appendix model
===================================================================================

Appendix 1: Parameter Sweeps
* csweep_4spp_mshock.m
* kapsweep_4spp_mshock.m
* phisweep_4spp_mshock.m

Appendix 2: Additive Perturbation

2-species model

4-species model
Run varsweep_4spp_ashock_series.m
This script will create a folder called  VARSWEEP-4SPP-ASHOCK within the current
working directory and write outputs into it.

*Case Studies
Run aigrettes_stochastic.m
Run flores_stochastic.m
* Note that you can change the entry point of the stochastic perturbation by
  commenting/uncommenting the line that defines the entry point

===================================================================================
    Appendix Figures
    Run these scripts to generate appendix figures from our original data
===================================================================================

Figure A1.1 - A1.4
Run mcnemar_calculations_for_sweeps.R

Figure A1.5 (sensitivity to t_max)
Run different_lengths.R


* appendix 2
*A2.1: mu sweep
musweep_2spp_stochastic_short.m
(simulation and graphing)

*A2.2: var sweep
Run mcnemar_appendix.R

*A2.3: case studies

A2.4: entry point comparison
(note that this graph is generated in MATLAB, not R)
Run varcompar.m

*A2.5: 4-spp mu sweep
*A2.6: asymmetric parameterization
  (additive perturbation figures)

