|
1 | 1 | #' Compute UniFrac Dissimilarity from a Sparse Matrix. |
2 | 2 | #' |
3 | 3 | #' @description Calculates the UniFrac dissimilarity between samples based on phylogenetic branch lengths and abundance or presence/absence data. |
4 | | -#' The UniFrac distance between two samples \eqn{A} and \eqn{B}, with phylogenetic tree edges \eqn{i = 1 \ldots n} of lengths \eqn{L_i}, is computed differently depending on the \code{weighted} and \code{normalized} flags: |
5 | | -#' Weighted UniFrac: |
6 | | -#' \eqn{d(A,B) = \frac{\sum_{i}^n L_i |A_i - B_i|}{\sum_{i}^n L_i (A_i + B_i)}} |
7 | | -#' Normalized Weighted UniFrac: |
8 | | -#' \eqn{d(A,B) = \sum_{i}^n L_i |A_i - B_i|} |
9 | | -#' where \eqn{A_i} and \eqn{B_i} are the abundance weights for branch \eqn{i} computed by propagating tip abundances to internal nodes. |
10 | | -#' |
11 | | -#' Unweighted UniFrac (always normalized): |
12 | | -#' \eqn{d(A,B) = \frac{\sum_{i}^n L_i |A'_i - B'_i|}{\sum_{i}^n L_i \max(A'_i, B'_i)}} |
13 | | -#' |
14 | | -#' where \eqn{A'_i} and \eqn{B'_i} are binary indicators (presence/absence) on branches \eqn{i}, derived by propagating tip presence to internal nodes. |
15 | | -#' When \code{weighted = FALSE}, input counts are first converted to presence/absence before distance computation. |
16 | | -#' |
| 4 | +#' |
| 5 | +#' @details |
| 6 | +#' The UniFrac distance between two samples \eqn{A} and \eqn{B}, with phylogenetic tree edges \eqn{i = 1 \ldots n} of lengths \eqn{L_i}, is computed differently depending on the \code{weighted} and \code{normalized} flags. |
| 7 | +#' When \code{weighted = FALSE}, input counts are first converted to presence/absence data. |
| 8 | +#' \describe{ |
| 9 | +#' \item{Weighted UniFrac (\code{normalized = FALSE} and \code{weighted = TRUE}):}{ |
| 10 | +#' \eqn{d(A,B) = \frac{\sum_{i}^n L_i |A_i - B_i|}{\sum_{i}^n L_i (A_i + B_i)}} |
| 11 | +#' } |
| 12 | +#' \item{Normalized Weighted UniFrac (\code{normalized = TRUE} and \code{weighted = TRUE}):}{ |
| 13 | +#' \eqn{d(A,B) = \sum_{i}^n L_i |A_i - B_i|} |
| 14 | +#' } |
| 15 | +#' \item{Unweighted UniFrac (\code{weighted = FALSE}, unweighted is always normalized):}{ |
| 16 | +#' \eqn{d(A,B) = \frac{\sum_{i}^n L_i |A_i - B_i|}{\sum_{i}^n L_i \max(A_i, B_i)}} |
| 17 | +#' } |
| 18 | +#'} |
17 | 19 | #' @param x A \link[Matrix]{sparseMatrix} of strictly positive counts or presence/absence data. |
18 | 20 | #' @param tree A `phylo` class tree. |
19 | 21 | #' @param weighted Logical indicating whether to compute weighted (abundance) or unweighted (presence/absence) UniFrac (default: TRUE). |
20 | 22 | #' @param normalized Logical indicating whether to normalize weighted UniFrac distances to be between 0 and 1 (default: TRUE). Unweighted UniFrac is always normalized. |
21 | 23 | #' @param threads Integer number of threads to use for parallel computation (default: 1). |
22 | 24 | #' @return A symmetric matrix of pairwise UniFrac distances between columns of \code{x}. |
23 | 25 | #' @references |
24 | | -#' Lozupone, C., Hamady, M., Kelley, S. T., & Knight, R. (2007). Quantitative and qualitative beta diversity measures lead to different insights into factors that structure microbial communities. Applied and Environmental Microbiology, 73(5), 1576–1585. |
25 | | -#' |
26 | 26 | #' Lozupone, C., & Knight, R. (2005). UniFrac: a new phylogenetic method for comparing microbial communities. Applied and Environmental Microbiology, 71(12), 8228–8235. |
27 | | -#' |
28 | | -#' Lozupone, C., & Knight, R. (2008). Species divergence and the measurement of microbial diversity. FEMS Microbiology Reviews, 32(4), 557–578. |
29 | | -#' |
30 | 27 | #' @examples |
31 | 28 | #' library("OmicFlow") |
32 | 29 | #' |
|
0 commit comments