Lab 09 · October 30, 2026
Gradient Forest
From species distributions to genomic turnover
Where along an environmental gradient does genetic composition change?
BIO597 Spatial Analysis of Biodiversity
Points are sampled individuals.
Correlations between environmental predictors and genetic data
Same climate (predictor) but a different response (SNPs).
Keep the environmental predictors; replace occurrence labels with SNP dosages.
Encoding genotype data into a compact format
Count the alternate copies
Two chromosome copies give a dosage of 0, 1, or 2.
Thinking about filtering/QC
Filter for missingness, sufficiently variable sites, LD, and take a subset so it runs faster.
Filtering chooses which genetic variation enters the analysis.
The gradient forest model
One random forest for each SNP
Each forest sees the same environments and learns one SNP’s dosage pattern.
"Out of bag" prediction error
Evaluating ability to predict genotype of holdout set of samples
Average predictions from trees that never learned from individual A.
Evaluating model fit
Aggregating OOB prediction error across all Trees/SNPs
R² = 0 matches the mean-only benchmark; positive scores improve on it.
The fitted example
Some SNPs contribute; others do not
pyGF retains SNPs with positive OOB R² and positive permutation importance.
Evaluating climate variable importance
Shuffle climate; see what breaks
If prediction error grows, the fitted forest relied on that variable.
Combining the forests
Share useful signal among the predictors
Give predictors a share of each SNP’s OOB prediction accuracy, then average over contributing SNPs.
The fitted example
Which gradients carry the most modeled signal?
BIO18 leads: precipitation of the warmest quarter.
From trees to gradients
From useful splits to a turnover curve
A cluster of informative splits becomes a steep part of the cumulative curve.
Schematic shapes. Smoothing and density correction account for where samples fall along the gradient.
The fitted example
Read the location and magnitude of turnover
Steep segment: faster modeled turnover. Endpoint: total predictor importance. X axes retain each raster’s units.
Project across the landscape
A turnover layer is a transformed climate surface
gf.plot_turnover() selects the leading predictor. High values mark cumulative position along that gradient.
Summarizing nineteen turnover coordinates
PCA gives the map and biplot a shared color key
PC1/2 locate biplot points. PC1/2/3 supply RGB colors. Similar colors indicate similar displayed coordinates.
Reading the biplot
Read the biplot as an environmental compass
Follow an arrow toward increasing transformed values; compare its contribution to PC1/2.
Schematic PCA scores and covariance arrows. Nearby points share similar scores on the displayed axes.
Aggregate versus one locus
A single SNP can emphasize a different pattern
Single-SNP view: response=snp. Each view has its own PCA basis and color scale.
Biological interpretation
The same pattern can have different explanations
A climate–genotype association gives us a hypothesis to test.
Conceptual alternatives. Fitness measurements and population-history evidence help distinguish them.
Sources and figure provenance
Further reading
pyGF is an independent implementation; conditional permutations and smoothing differ from R gradientForest.