View source: R/phylo_correlation.R
| phylo_correlation | R Documentation |
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")
traits_matrix |
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. |
phylo_tree |
A phylogenetic tree object of class "phylo" (from the ape package). The tree should contain the same species as in the traits matrix. |
method |
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.
A list containing two matrices:
r |
A symmetric correlation matrix with phylogenetically corrected correlation coefficients |
P |
A symmetric matrix of p-values corresponding to the correlation tests |
The function requires at least 3 species with complete data for each trait pair
Non-binary trees are automatically converted to binary using multi2di()
Species present in the tree but missing from the trait matrix will generate warnings
The function handles missing values by performing pairwise complete case analysis
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.