Learn R Programming

MultiTraits (version 0.6.0)

phylo_correlation: Phylogenetically Corrected Correlation Analysis

Description

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.

Usage

phylo_correlation(traits_matrix, phylo_tree, method = "pearson")

Value

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

Arguments

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".

Details

The function performs the following steps:

  1. Checks if the phylogenetic tree is binary and converts it if necessary

  2. Matches species between the trait matrix and phylogenetic tree

  3. For each pair of traits, calculates phylogenetic independent contrasts (PICs)

  4. Computes correlations between PICs instead of raw trait values

  5. 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.

References

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.

Examples

Run this code
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