This function calculates phylogenetically independent correlations between traits using phylogenetic independent contrasts (PICs). It accounts for phylogenetic relationships when computing correlations, which is important when analyzing trait data from related species.
phylo_correlation(traits_matrix, phylo_tree, method = "pearson")
A list containing two matrices:
A symmetric correlation matrix with phylogenetically corrected correlation coefficients
A symmetric matrix of p-values corresponding to the correlation tests
A numeric matrix or data frame where rows represent species and columns represent traits. Row names should contain species names that match the tip labels in the phylogenetic tree.
A phylogenetic tree object of class "phylo" (from the ape package). The tree should contain the same species as in the traits matrix.
Character string specifying the correlation method to use. Options are "pearson" (default) or "spearman".
The function performs the following steps:
Checks if the phylogenetic tree is binary and converts it if necessary
Matches species between the trait matrix and phylogenetic tree
For each pair of traits, calculates phylogenetic independent contrasts (PICs)
Computes correlations between PICs instead of raw trait values
Handles missing data by using only complete cases for each trait pair
The phylogenetic independent contrasts method removes the effects of phylogenetic relatedness, allowing for proper statistical inference about trait correlations. This is crucial when analyzing data from related species, as standard correlation methods may be biased due to phylogenetic non-independence.
Felsenstein, J. (1985). Phylogenies and the comparative method. The American Naturalist, 125(1), 1-15.
Harvey, P. H., & Pagel, M. D. (1991). The comparative method in evolutionary biology. Oxford University Press.
data(PFF)
data(PFF_tree)
rownames(PFF) <- PFF$species
traits <- PFF[,4:21]
head(traits)
phylo_correlation(traits, PFF_tree, method = "pearson")
Run the code above in your browser using DataLab