## Supplement 1. R code and fynbos data set.

## File List

Merow_et_al_R_code.r -- R code for all analyses

fynbos_abundance_matrix.csv -- matrix of relative abundance (rows) by sites (columns)

fynbos_trait_matrix.csv -- matrix of species (rows) by traits (columns)

## Description

The file Merow_et_al_R_code.r contains R code for constructing the EM models shown in the main text. This includes the basic EM model, calculating the Hellinger fit metric, Lagrange multipliers and plotting results for both local and regional communities. We also include code for predicting community-aggregated traits from splines, cross validation, generating informative priors and permutation tests. The file fynbos_abundance_matrix.csv contains site by site relative abundance data for the eight elevational communities we used (derived from 43 5 × 10 m releves) from the Baviaanskloof Mountains, South Africa. The file fynbos_trait_matrix.csv contains data for each species on the following traits: graminoid (binary), succulent (binary), maximum height, leaf longevity (ordinal 1–3, 1 is lowest), flowering duration, pubescence (binary), leaf width, leaf perimeter^2/leaf area, leaf area/basal diameter, stem length/stem basal diameter^(2/3). These traits have been rescaled to lie on the interval [0,1].

Checksum values are as follows:

For fynbos_trait_matrix.csv the columns sum to: col 1 (life.form.graminoid) = 19, col 2 = 2, col. 3 = 5.84708, col. 4 = 24, col. 5 = 18.09093, col. 6 = 14, col. 7 = 7.75024, col. 8 = 8.16681, col. 9 = 6.7815, and last col. = 8.2096.

For fynbos_abundance_matrix.csv, all columns sum to 1.