Jennifer K. Cooper, Matthew Spencer, and John F. Bruno. 2015. Stochastic dynamics of a warmer Great Barrier Reef. Ecology 96:15121521.


R code used in the analysis.
Ecological Archives E096-162-S1.


File list (downloads)


Jennifer K. Cooper
School of Environmental Sciences, University of Liverpool, Liverpool, L69 3GP, UK

Matthew Spencer
School of Environmental Sciences, University of Liverpool, Liverpool, L69 3GP, UK

John F. Bruno
Department of Biology, The University of North Carolina at Chapel Hill, Chapel Hill, NC 27599-3300 USA

File list (MD5: )6ae46c25aa73795ab107e9e90800012f

Description is a zip archive containing the following files.

README.txt: these notes
paperfigures7d.R. Script produces versions of all the figures included in the manuscript (using a version of the data file with noise added, as explained below). Note that this version runs only 10 bootstrap replicates for the main analysis, for a quick demonstration (figures in the manuscript were produced using 1e4 bootstrap reps for all calculations). To save time, it also produces only rough figures, in which the stationary distributions are calculated on a grid that doesn't extend very close to the edges of the simplex.

Took a few minutes on an Intel Xeon 3.2GHz processor, 16 G RAM, 64-bit Ubuntu 12.04.

To run the analysis, start R and type


Note that this will create the following files containing bootstrap data:


The following figures will be created:

1. Raw data, perturbing vectors, and estimated parameters.
2. Probability of low coral and high algal cover, low and medium local threat, current and +2 degrees C climatology
3. Sensitivity of stationary density to increases in climatology, low and medium local threat.
4. Standard deviation of sensitivity, as above.
5. Stationary distributions at low and medium local threat, current and +2 degrees C climatology.
5. Standard deviation of stationary densities at low and medium local threat, current and +2 degrees C climatology
7. Direction of short- and long-term effects of climatology

Settings used to produce the figures in the manuscript:

Change line 67 to:
reps <- 1e4

Change line 68 to:
grid <- 4

Other figures in the manuscript: map of sites produced by setting coastdistfig to TRUE. Spatial autocorrelation of residuals: set spatialresids to TRUE. Simulated effects of observation error: set simulateobserror to TRUE. Other diagnostic plots: set checkresids to TRUE.

modelfitting3.R (functions used by paperfigures7d.R)

gbrnoise.txt Data. Tab-separated text. Each row is the data for a pair of observations on a single reef in consecutive years. Variables are:
reefid: a unique numerical code for each reef
depthavg: mean depth in m
sstlag: annual mean sea surface temperature, degrees C, for the calendar year preceding the value in the "year" variable
year: the year of the first observation in the pair
coral: proportional cover of hard coral in the year given by "year"
algae: proportion cover of macroalgae in the year given by "year"
other: proportional cover of everything else in the year given by "year"
coral.1, algae.1, other.1: the same variables in the following year
mindistsst: distance in km to the closest SST record in the CORTAD database (the record used to calculate sstlag)
threat: local threat level from Reefs at Risk Revisited
sst: annual mean sea surface temperature, degrees C, unlagged
ssta: annual mean sea surface temperature anomaly, unlagged
sstalag: annual mean sea surface temperature anomaly, lagged
long and lat: longitude and latitude for the reef
coastdistkm: distance from coast, kilometres
method: data collection method (Line Transect for all these data)
datasource: original source of the data (AIMS LTMP for all these data)

Data sources as described in Cooper et al (unpublished), Stochastic Dynamics of a Warmer Great Barrier Reef.

Because we do not have permission to distribute the raw data on reef composition, gbrnoise.txt has noise added to the reef composition data. It can therefore be used only to demonstrate the code.

R packages required (although the basic analyses will run with only the first six of these):