| PTN_corr | R Documentation |
This function calculates correlation coefficients for given plant traits and generates a correlation network plot. It supports both standard correlation analysis and phylogenetically corrected correlation analysis using phylogenetic independent contrasts.
PTN_corr(
traits_matrix,
rThres = 0.2,
pThres = 0.05,
method = "pearson",
phylo_correction = FALSE,
phylo_tree = NULL
)
traits_matrix |
A numeric matrix or data frame where each column represents a plant trait and each row represents a sample (species). Row names should contain species names when using phylogenetic correction. |
rThres |
Numeric, threshold for correlation coefficient, default is 0.2. Only correlations with absolute values above this threshold will be displayed in the plot. Must be between 0 and 1. |
pThres |
Numeric, threshold for p-value, default is 0.05. Only correlations with p-values below this threshold will be displayed in the plot. Must be between 0 and 1. |
method |
Character, specifies the correlation method to use: "pearson" (default) or "spearman". |
phylo_correction |
Logical, whether to apply phylogenetic correction using phylogenetic independent contrasts. Default is FALSE. |
phylo_tree |
A phylo object (from the ape package) containing the phylogenetic tree. Required when phylo_correction = TRUE. Species names in the tree must match row names in traits_matrix. |
The function performs the following steps:
Validates input parameters and data structure
If phylogenetic correction is requested, matches species between traits_matrix and phylo_tree
Calculates correlation coefficients using either standard correlation or phylogenetic independent contrasts
Adjusts p-values using the False Discovery Rate (FDR) method
Creates a correlation network plot using hierarchical clustering for trait ordering
Marks non-significant correlations with red crosses based on both correlation and p-value thresholds
When phylo_correction = TRUE, the function uses phylogenetic independent contrasts to account for phylogenetic relationships among species, which helps control for the non-independence of species data due to shared evolutionary history.
Returns a correlation network plot object created by corrplot. The plot displays correlations as circles, with positive correlations in blue and negative correlations in red. Non-significant correlations (based on thresholds) are marked with red crosses.
Missing values (NA) should be handled before using this function
When using phylogenetic correction, ensure species names are consistent between traits_matrix row names and phylo_tree tip labels
The function requires the Hmisc, corrplot, and (optionally) ape packages
Felsenstein, J. (1985). Phylogenies and the comparative method. The American Naturalist, 125(1), 1-15.
He, N., Li, Y., Liu, C., et al. (2020). Plant trait networks: improved resolution of the dimensionality of adaptation. Trends in Ecology & Evolution, 35(10), 908-918.
Li, Y., Liu, C., Sack, L., Xu, L., Li, M., Zhang, J., & He, N. (2022). Leaf trait network architecture shifts with speciesārichness and climate across forests at continental scale. Ecology Letters, 25(6), 1442-1457.
data(PFF)
rownames(PFF) <- PFF$species
PFF_traits <- PFF[, c("Height", "Leaf_area","LDMC","SLA","SRL","SeedMass","FltDate",
"FltDur","Leaf_Cmass","Leaf_Nmass","Leaf_CN","Leaf_Pmass",
"Leaf_NP","Leaf_CP","Root_Cmass","Root_Nmass","Root_CN")]
PFF_traits <- na.omit(PFF_traits)
head(PFF_traits)
PTN_corr(traits_matrix = PFF_traits, rThres = 0.2, pThres = 0.05, method = "pearson")
data(PFF_tree)
PTN_corr(traits_matrix = PFF_traits, rThres = 0.2, pThres = 0.05, method = "pearson",
phylo_correction = TRUE, phylo_tree = PFF_tree)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.