Skip to content

Latest commit

 

History

History
103 lines (81 loc) · 3.89 KB

README.md

File metadata and controls

103 lines (81 loc) · 3.89 KB

gaiah-wiwa

14 March, 2017

This is a repository that holds code to perform the analyses in Ruegg, Anderson, Harrigan, Paxton, Kelly, Moore, and Smith (2017) "Genetic assignment with isotopes and habitat suitability (GAIAH), a migratory bird case study" in Methods in Ecology and Evolution.

Preliminaries

First, you gotta get the gaiah R package. That is up on CRAN.

install.packages("gaiah")

By the way, this is known to run on gaiah version 0.0.2.

Then make sure that you have all the necesary additional packages to run the analysis. Here they are, listed in their library calls:

#> library(grid)
#> library(gridExtra)
#> library(raster)  # call this before dplyr so it doesn't mask select
#> library(dplyr)
#> library(stringr)
#> library(ggplot2)
#> library(gaiah)
#> library(forcats)
#> library(tikzDevice)

So, you can get all those like this:

install.packages(c("grid", "gridExtra", "forcats", "tikzDevice"))

The tikzDevice package is there for putting nice LaTeX typesetting on the figures. In fact, some of the code in R-main/01-wiwa-analysis.R makes system calls to LaTeX to typeset those figures, so if you want reproduce everything entirely, you are going to need pdflatex on your system path and the capacity for R to make calls using the system() function.

Running the analyses

All the major analyses are in the R-script at R-main/01-wiwa-analysis.R.

You can just run it. This script creates some intermediate output files so that the computationally intensive portions of the analysis can be avoided should you need to re-run everything. After you have run through the code once, you can change the TRUEs to FALSEs in the following lines in R-main/01-wiwa-analysis.R to use the cached results rather than the recomputing everything from the beginning:

#### CHOOSE WHETHER TO USE PRE-STORED VALUES OR RECOMPUTE THINGS####
COMPUTE_ISO_POSTERIORS <- TRUE  # if false then it will just load these up from a cache
REMAKE_ALL_SUPP_MAPS <- TRUE
RECOMPUTE_PMGCD_GRID <- TRUE

The intermediate files that are produced in each of the relevant code sections are as follows, along with the approximate compute time:

Flag Option output file approx compute time
COMPUTE_ISO_POSTERIORS outputs/isotope_ref_bird_results.rda 1 hour
REMAKE_ALL_SUPP_MAPS outputs/birdmaps/bird_XX.pdf (where XX is the bird's ID) 20 minutes
RECOMPUTE_PMGCD_GRID outputs/128_pmgcd_vals.rds 10 minutes

Setting each of those flags to FALSE (once the intermediate files in R-main/01-wiwa-analysis.R makes it possible to get through the whole analysis in about 2 to 2.5 minutes on a reasonably fast laptop.

Transferring figures for the publication

I include R-main/02-move-figures.R so that the interested can see which figures produced in the previous step get placed in the document itself. In order for this to actually work you will need to have the appropriate TeX source files, etc in the right directory inside git-overleaf-repos. You also need to have pdfcrop installed on your system.

Making supplement 1

This is done with R-main/03-compile-supp-1.R. It just makes a LaTeX file that can then be typeset into the supplement.