phylo_correlation: Phylogenetically Corrected Correlation Analysis

View source: R/phylo_correlation.R

phylo_correlationR Documentation

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

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.

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

Note

  • 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

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

data(PFF)
data(PFF_tree)
rownames(PFF) <- PFF$species
traits <- PFF[,4:21]
head(traits)
phylo_correlation(traits, PFF_tree, method = "pearson")


MultiTraits documentation built on March 22, 2026, 9:06 a.m.