Skip to contents

Calculates Hommola correlation coefficient and p-value by comparing the observed correlation to a null distribution generated by random permutations of the host-symbiont association while preserving the symbiont distance matrix.

Usage

hommola_wf(
  i_host_subtree_dist,
  i_symbiont_subtree_dist,
  i_host_to_symbiont_df,
  permutations,
  seed
)

Arguments

i_host_subtree_dist

A distance matrix for host subtree tips

i_symbiont_subtree_dist

A distance matrix for symbiont subtree tips

i_host_to_symbiont_df

A data frame with "Host" and "Symbiont" columns

permutations

Number of random permutations for null distribution; at least 99 recommended

seed

Random seed for reproducibility; if NA, no seed is set

Value

A list with two elements:

  • Uncollapsed_Hommola_r: The observed correlation coefficient

  • Uncollapsed_Hommola_pvalue: One-tailed p-value (# permutations with r >= observed + 1) / (total permutations + 1)

Details

The symbiont distance matrix is melted once and reused across all permutations; each permutation only re-maps symbionts to hosts and indexes into the host distance matrix, which makes the permutation loop substantially faster than recomputing the full reshape each time.

Examples

# \donttest{
library(adephylo)
h_tree <- ape::rtree(5)
s_tree <- ape::rtree(15)
hs_df <- data.frame(
  Host = rep(h_tree$tip.label, 3),
  Symbiont = s_tree$tip.label
)
h_dist <- distTips(h_tree, method = "patristic")
s_dist <- distTips(s_tree, method = "patristic")
result <- hommola_wf(h_dist, s_dist, hs_df, permutations = 99, seed = 123)
# }