Yosemite toad migration corridors: tutorial code
================================================

R scripts for the tutorial at https://paulmaierresearch.com/software/
reproducing Maier et al. (2022) Heredity 129:257-272,
https://doi.org/10.1038/s41437-022-00561-x

Setup
-----
1. Download the Dryad archive (https://doi.org/10.5061/dryad.xsj3tx99h) and
   unzip Corridors.zip, FST_YOSE.zip and ResistanceGA.zip into one folder.
2. Unzip the tutorial data bundle (yosemite-toad-corridors-data.zip) into the
   same folder. Copy its out/ folder next to these scripts.
3. Tell the scripts where the data are, then run them in order:

     export TOAD_DATA=/path/to/that/folder     # or edit DATA_DIR in 00_setup.R
     Rscript 01_genetics.R
     ...

Scripts
-------
00_setup.R           packages, paths, map helpers (sourced by the others)
features.R           feature groups and table helpers (steps 4-5)
01_genetics.R        pairwise FST from the Stacks tables; dM
02_paths.R           resistance maps, transition layer, LCP ranking (Table 3)  *
03_corridors.R       least cost corridors, buffers, extraction (Fig. 2)        *
04_bandwidth.R       random forest bandwidth selection (Table 4; a few hours)
05a_predictors.R     PCA within feature groups -> predictor tables             +
05_cubist.R          Cubist models, VIF filter, future projections (Table 5)
05b_model_figures.R  model fit and variable importance (Figs. 3-4)
06_maps.R            forecast maps and centrality (Fig. 1)                     *

*  needs meadow locations (Corridors/sources), which are not public; they can be
   requested from the corresponding author. The LCP ranking in 02_paths.R runs
   without them.
+  needs the per-pair tables; the data bundle already contains its output.

Tested with R 4.5.3, terra 1.9, sf 1.1, gdistance 1.6, caret 7.0, Cubist 0.6,
ranger 0.18, spatialRF 1.1, igraph 2.3. Set TOAD_CORES to change the number
of cores (default 8).
