Lab knowledgebase: R scripts


*R scripts provided here are available to all with no strings attached. However, these come with no guarantees that the scripts do what you think they are doing, or that they won’t adversely affect your computer or stress levels. Feel free to e-mail me with any questions on using them.

Thanks
Marc


ecoPD R package

The early version of our ecoPD R package is available on R Forge. It implements the phylogenetic-community diversity metrics of Cadotte et al. 2010, Ecology Letters and for Cadotte & Davies 2010 Div. & Dist. (see publications). For a short example for installing and using this package see here.

Diversity metrics
addPart - calculates Lande's (1996) additive partitioning of diversity for richness, simpson and shannon indices.

FuncDiv - calculates functional diversity metrics: FD (Petchey and Gaston 2002) and FAD (Walker et al. 1999).


Phylogenetic diversity

PDcalc -
Calculates phylogenetic diversity for a file with multiple communities (thanks to Jonathan Davies).

randMinPD - Randomization for significance testing for the smallest phyloegentic distance in a community.

simp.phy - Calculates Simpson's index weighted by phylogenetic distance among species according to Hardy & Senterre (2007) for each community in a community x species matrix plus a 'phylo' object.

phyloBeta - Calculates additively partitioned phylogenetic diversity (alpha, beta, gamma) according Lande's (1996) scheme. It includes weighting for local (alpha) mean PD based on number of species. Also if the number of randomizations (n.rand) is greater than 0, it also produces confidence test.

MultiPD - Calculate PD from phylogeny with multiple trees (e.g., 100 most probable trees from Baysian analysis) with a set of communities.


Phylogenetic signal tests
 
Krand - Randomization for significance testing for Blomberg's K.

K script - Loops Krand through a file with multiple communities -becareful that n.rand is set to 1000 and with a bunch of communities it can take a long time.

pic.func - Function to calculate the sum of absolute phylogentically independent contrasts values and compare them to null values. This is an alternative to the K statistic for detecting phylo-signal. May be less sensitive to small sample sizes???


Other phylogenetic functions

DistPlot - plot Mantel tests, where two observations or species from a phylogeny color code the dot in a scatterplot. Allows you to see if one species is biasing Mantel tests.

subTree - Create subtree from larger phylogeny using a vector of species names.

OUM - Discrete-time Ornstein-Uhlenbeck model of trait evolution. There are seven arguments needed for the simulation. They are the number of species (NumSP), the number of time steps (nsteps), the standard deviation (SD –which controls the spread), the strength of selection (alph –which when zero is a Brownian motion model), the trait optimum (theta), line colour (colr) and line width (wid).


Other basic data manipulations

cv - Coefficient of variation on a vector.
without - without subsetting function. It is used to exclude a value.
Xunder - Removes '_' in text string, for a vector of character names. Common between Genus_species in phylogenetic data. e.g., Xunder(phy$tip.label).