Números de Hill: diversidad taxonómica, filogenética y funcional

MicroBioMeta calcula la diversidad y devuelve la figura lista para publicar. Este tutorial explica el marco de los números de Hill y cómo usarlo en las funciones que trabajan con él: alpha_hill_plot() y alpha_diversity_plot() para diversidad alfa, y beta_ord_plot() y beta_test_table() para diversidad beta. Los cálculos con árbol o con rasgos vienen de hilldiv3 (Alberdi and Gilbert 2019).

Por qué números de Hill

Los números de Hill (Hill 1973; Jost 2007) expresan la diversidad como un número efectivo: cuántos taxones igual de abundantes darían la misma diversidad que la muestra. Una muestra con valor 10 es el doble de diversa que una con valor 5, algo que no se cumple con los índices de Shannon o Simpson.

El orden \(q\) define cuánto peso reciben las abundancias:

Orden Peso de los taxones Equivale a
\(q = 0\) Todos cuentan igual Riqueza
\(q = 1\) Proporcional a su abundancia Exponencial de Shannon
\(q = 2\) Sobre todo los dominantes Inverso de Simpson

La misma idea se extiende a otras dos dimensiones de la diversidad (Chao et al. 2014). Las tres son números efectivos, en equivalentes de especies o linajes (Chao et al. 2021), pero cuentan cosas distintas: taxones, linajes o grupos funcionales. Di siempre cuál reportas.

diversity Qué toma en cuenta Qué necesitas Unidad
"taxonomic" Abundancias La tabla Número efectivo de features
"phylogenetic" Qué tan emparentados están los taxones (Chao et al. 2010) Árbol enraizado Número efectivo de linajes
"functional" Qué tan distintos son sus rasgos (Chao et al. 2019) Rasgos por taxón Número efectivo de grupos funcionales

Preparar los datos

Usamos el ejemplo 18S del paquete (eucariontes microscópicos, sobre todo hongos).

library(MicroBioMeta)

table_fungi <- read.delim(
    system.file("extdata", "table_fungi.txt", package = "MicroBioMeta"),
    row.names = 1, check.names = FALSE
)
taxonomy_fungi <- read.delim(
    system.file("extdata", "taxonomy_fungi.txt", package = "MicroBioMeta"),
    check.names = FALSE
)
metadata_fungi <- read.delim(
    system.file("extdata", "metadata_fungi.txt", package = "MicroBioMeta"),
    check.names = FALSE
)
metadata_fungi <- metadata_fungi[metadata_fungi$SAMPLEID %in% colnames(table_fungi), ]
table_fungi <- table_fungi[, metadata_fungi$SAMPLEID]

table_fung <- merge_feature_taxonomy(table = table_fungi, taxonomy = taxonomy_fungi)

El árbol

Las puntas del árbol deben ser los taxones de la tabla. Con QIIME 2 (Bolyen et al. 2019), el árbol sale de las secuencias representativas, y exported-tree/tree.nwk es lo que lees en R:

qiime phylogeny align-to-tree-mafft-fasttree \
    --i-sequences rep-seqs.qza \
    --output-dir phylogeny
qiime tools export --input-path phylogeny/rooted_tree.qza --output-path exported-tree
tree_fungi <- ape::read.tree(
    system.file("extdata", "tree_fungi.nwk", package = "MicroBioMeta")
)

Revisa el árbol antes de usarlo: unas pocas secuencias espurias en una rama muy larga pueden aplanar \(q = 1\) y \(q = 2\), porque esa rama domina el árbol. En este ejemplo quitamos tres ASVs Unassigned (10 lecturas) por esa razón.

Los rasgos

traits es una tabla con taxones en filas y rasgos en columnas. Sirve cualquier rasgo medido. En comunidades microbianas, una fuente común es la tabla de familias de genes predichas por ASV con PICRUSt2 (Douglas et al. 2020), como EC_predicted.tsv. Son predicciones, no mediciones, así que repórtalas como tales.

traits_fungi <- read.delim(
    system.file("extdata", "traits_fungi.txt", package = "MicroBioMeta"),
    row.names = 1, check.names = FALSE
)

Los taxones que están en la tabla pero no en el árbol o en los rasgos se descartan con un aviso que dice cuántos son. Aquí pasa con los tres ASVs de arriba.

Diversidad alfa con números de Hill

alpha_hill_plot() usa la misma llamada para los tres tipos. Solo cambian diversity y su insumo, y el título del eje y sigue la unidad de cada tipo.

alpha_hill_plot(
    table = table_fung,
    metadata = metadata_fungi,
    x_col = "Type_of_soil",
    fill_col = "Type_of_soil",
    facet_by = "Treatment",
    x_axis_title = "Type of soil",
    show_legend = FALSE,
    stat = "kruskal.test"
)

alpha_hill_plot(
    table = table_fung,
    metadata = metadata_fungi,
    x_col = "Type_of_soil",
    fill_col = "Type_of_soil",
    facet_by = "Treatment",
    x_axis_title = "Type of soil",
    show_legend = FALSE,
    stat = "kruskal.test",
    diversity = "phylogenetic",
    tree = tree_fungi
)

alpha_hill_plot(
    table = table_fung,
    metadata = metadata_fungi,
    x_col = "Type_of_soil",
    fill_col = "Type_of_soil",
    facet_by = "Treatment",
    x_axis_title = "Type of soil",
    show_legend = FALSE,
    stat = "kruskal.test",
    diversity = "functional",
    traits = traits_fungi
)

Dos detalles de estos valores:

  • Los valores filogenéticos se leen a una misma profundidad, la profundidad media del árbol en las muestras (Chiu et al. 2014), para que las muestras sean comparables. Por eso una muestra puede quedar apenas por debajo de 1. iNEXT.3D usa en cambio la edad de la raíz, así que sus valores no son iguales.
  • Los valores funcionales dependen de un umbral \(\tau\): los taxones a esa distancia o más cuentan como grupos funcionales distintos. Por defecto es la distancia media entre dos lecturas de las muestras juntas (Chao et al. 2019), y puedes cambiarlo con tau.

Índices clásicos

alpha_diversity_plot() muestra los índices clásicos, también con diversity:

diversity Índice Significado Unidad
"taxonomic" Chao1, Shannon, Simpson Riqueza y equitatividad Distinta en cada índice
"phylogenetic" PD de Faith (Faith 1992) Suma de longitudes de rama hasta la raíz Longitud de rama
"functional" Q de Rao (Rao 1982) Distancia media entre dos lecturas al azar Distancia (Gower)
alpha_diversity_plot(
    table = table_fung,
    metadata = metadata_fungi,
    x_col = "Type_of_soil",
    fill_col = "Type_of_soil",
    x_axis_title = "Type of soil",
    show_legend = FALSE,
    stat = "kruskal.test",
    diversity = "phylogenetic",
    tree = tree_fungi
)

alpha_diversity_plot(
    table = table_fung,
    metadata = metadata_fungi,
    x_col = "Type_of_soil",
    fill_col = "Type_of_soil",
    x_axis_title = "Type of soil",
    show_legend = FALSE,
    stat = "kruskal.test",
    diversity = "functional",
    traits = traits_fungi
)

Estos índices se relacionan con los números de Hill, pero no son la misma cantidad. El PD de Faith es el \(q = 0\) filogenético antes de dividir entre la profundidad del árbol, y la Q de Rao da el \(q = 2\) funcional mediante \(1 / (1 - Q / \tau)\) cuando \(\tau\) es la mayor distancia entre dos taxones. Elige el índice clásico si necesitas comparar con estudios que lo reportan, y el número de Hill si quieres todos los tipos en un mismo marco.

Diversidad beta

Las métricas

hilldiv3::hillpair() convierte los números de Hill en disimilitudes entre muestras (Jost 2007; Chiu et al. 2014; Chao et al. 2023). En MicroBioMeta son una opción más de distance, junto a "jaccard" o "aitchison", con el orden definido por q. Van de 0 (muestras idénticas) a 1 (nada compartido), así que no tienen problema de unidades.

distance Tipo Taxonómica: \(q = 0\), \(1\), \(2\) Filogenética: \(q = 0\), \(1\), \(2\)
"U" Tipo Jaccard Jaccard, Horn, solapamiento regional Phylo-Jaccard (UniFrac no ponderado), phylo-Horn, phylo-regional-overlap
"C" Tipo Sørensen Sørensen, Horn, Morisita-Horn Phylo-Sørensen (PhyloSor), phylo-Horn, phylo-Morisita-Horn
"S" Recambio tipo Jaccard Jaccard, sin nombre, Morisita-Horn Phylo-Jaccard, sin nombre, phylo-Morisita-Horn
"V" Recambio tipo Sørensen Sørensen, sin nombre, sin nombre Phylo-Sørensen, sin nombre, sin nombre

Los nombres filogenéticos vienen de Chiu et al. (2014), y PhyloSor de Bryant et al. (2008); UniFrac es de Lozupone and Knight (2005). Las versiones funcionales no tienen nombres propios: Chao et al. (2019) las llama medidas funcionales tipo Sørensen y tipo Jaccard, así que repórtalas así, con \(q\) y \(\tau\). En \(q = 1\), "U" es phylo-Horn, no el UniFrac ponderado.

Estas métricas describen las diferencias en términos de números de Hill; no son composicionales. Si tu análisis principal usa CLR/Aitchison, mantenlo y usa estas como complemento.

Ordenación

Las métricas de Hill funcionan con ordination = "PCoA" o "NMDS", igual que cualquier distancia que no sea "compositional". beta_ord_plot() mantiene la misma escala en los dos ejes, así que la gráfica se achata cuando el primer eje explica casi toda la variación. En el ejemplo funcional agregamos ggplot2::coord_cartesian() para llenar la figura; ten en cuenta que los ejes ya no comparten escala.

beta_ord_plot(
    table = table_fung,
    metadata = metadata_fungi,
    distance = "U",
    q = 1,
    ordination = "PCoA",
    group_col = "Type_of_soil",
    legend_title = "Type of soil"
)

beta_ord_plot(
    table = table_fung,
    metadata = metadata_fungi,
    distance = "U",
    q = 1,
    ordination = "PCoA",
    group_col = "Type_of_soil",
    legend_title = "Type of soil",
    diversity = "phylogenetic",
    tree = tree_fungi
)

beta_ord_plot(
    table = table_fung,
    metadata = metadata_fungi,
    distance = "U",
    q = 1,
    ordination = "PCoA",
    group_col = "Type_of_soil",
    legend_title = "Type of soil",
    diversity = "functional",
    traits = traits_fungi
) + ggplot2::coord_cartesian()

PERMANOVA y betadisper

beta_test_table() recibe los mismos argumentos. Un PERMANOVA (Anderson 2001) prueba si los grupos difieren, y betadisper (Anderson 2006) si difiere su dispersión. Reporta ambos: un PERMANOVA significativo con dispersiones desiguales puede reflejar diferencias de dispersión, no de posición.

Usamos \(q = 1\) y el mismo modelo para los tres tipos. En ese orden el suelo y el tratamiento difieren en todos, y la interacción solo en el filogenético.

Taxonómica:

beta_test_table(
    table = table_fung,
    metadata = metadata_fungi,
    formula_str = "Type_of_soil * Treatment",
    distance = "U",
    q = 1
)

Filogenética:

beta_test_table(
    table = table_fung,
    metadata = metadata_fungi,
    formula_str = "Type_of_soil * Treatment",
    distance = "U",
    q = 1,
    diversity = "phylogenetic",
    tree = tree_fungi
)

Funcional:

beta_test_table(
    table = table_fung,
    metadata = metadata_fungi,
    formula_str = "Type_of_soil * Treatment",
    distance = "U",
    q = 1,
    diversity = "functional",
    traits = traits_fungi
)

test = "betadisper" funciona igual para los tres tipos. Aquí está el filogenético. En \(q = 1\) las dispersiones difieren entre tipos de suelo en los tres, así que lee el PERMANOVA de Type_of_soil con eso en mente.

beta_test_table(
    table = table_fung,
    metadata = metadata_fungi,
    formula_str = "Type_of_soil",
    distance = "U",
    q = 1,
    test = "betadisper",
    diversity = "phylogenetic",
    tree = tree_fungi
)

Referencias

Alberdi, Antton, and M. Thomas P. Gilbert. 2019. “A Guide to the Application of Hill Numbers to DNA-Based Diversity Analyses.” Molecular Ecology Resources 19 (4): 804–17. https://doi.org/10.1111/1755-0998.13014.
Anderson, Marti J. 2001. “A New Method for Non-Parametric Multivariate Analysis of Variance.” Austral Ecology 26 (1): 32–46. https://doi.org/10.1111/j.1442-9993.2001.01070.pp.x.
Anderson, Marti J. 2006. “Distance-Based Tests for Homogeneity of Multivariate Dispersions.” Biometrics 62 (1): 245–53. https://doi.org/10.1111/j.1541-0420.2005.00440.x.
Bolyen, Evan, Jai Ram Rideout, Matthew R. Dillon, et al. 2019. “Reproducible, Interactive, Scalable and Extensible Microbiome Data Science Using QIIME 2.” Nature Biotechnology 37 (8): 852–57. https://doi.org/10.1038/s41587-019-0209-9.
Bryant, Jessica A., Christine Lamanna, Hélène Morlon, Andrew J. Kerkhoff, Brian J. Enquist, and Jessica L. Green. 2008. “Microbes on Mountainsides: Contrasting Elevational Patterns of Bacterial and Plant Diversity.” Proceedings of the National Academy of Sciences 105 (supplement_1): 11505–11. https://doi.org/10.1073/pnas.0801920105.
Chao, Anne, Chun-Huo Chiu, and Lou Jost. 2010. “Phylogenetic Diversity Measures Based on Hill Numbers.” Philosophical Transactions of the Royal Society B: Biological Sciences 365 (1558): 3599–609. https://doi.org/10.1098/rstb.2010.0272.
Chao, Anne, Chun-Huo Chiu, and Lou Jost. 2014. “Unifying Species Diversity, Phylogenetic Diversity, Functional Diversity, and Related Similarity and Differentiation Measures Through Hill Numbers.” Annual Review of Ecology, Evolution, and Systematics 45 (1): 297–324. https://doi.org/10.1146/annurev-ecolsys-120213-091540.
Chao, Anne, Chun-Huo Chiu, Sébastien Villéger, et al. 2019. “An Attribute-Diversity Approach to Functional Diversity, Functional Beta Diversity, and Related (Dis)similarity Measures.” Ecological Monographs 89 (2): e01343. https://doi.org/10.1002/ecm.1343.
Chao, Anne, Peter A. Henderson, Chun-Huo Chiu, et al. 2021. “Measuring Temporal Change in Alpha Diversity: A Framework Integrating Taxonomic, Phylogenetic and Functional Diversity and the iNEXT.3D Standardization.” Methods in Ecology and Evolution 12 (10): 1926–40. https://doi.org/10.1111/2041-210X.13682.
Chao, Anne, Simon Thorn, Chun-Huo Chiu, et al. 2023. “Rarefaction and Extrapolation with Beta Diversity Under a Framework of Hill Numbers: The iNEXT.beta3D Standardization.” Ecological Monographs 93 (4): e1588. https://doi.org/10.1002/ecm.1588.
Chiu, Chun-Huo, Lou Jost, and Anne Chao. 2014. “Phylogenetic Beta Diversity, Similarity, and Differentiation Measures Based on Hill Numbers.” Ecological Monographs 84 (1): 21–44. https://doi.org/10.1890/12-0960.1.
Douglas, Gavin M., Vincent J. Maffei, Jesse R. Zaneveld, et al. 2020. “PICRUSt2 for Prediction of Metagenome Functions.” Nature Biotechnology 38 (6): 685–88. https://doi.org/10.1038/s41587-020-0548-6.
Faith, Daniel P. 1992. “Conservation Evaluation and Phylogenetic Diversity.” Biological Conservation 61 (1): 1–10. https://doi.org/10.1016/0006-3207(92)91201-3.
Hill, M. O. 1973. “Diversity and Evenness: A Unifying Notation and Its Consequences.” Ecology 54 (2): 427–32. https://doi.org/10.2307/1934352.
Jost, Lou. 2007. “Partitioning Diversity into Independent Alpha and Beta Components.” Ecology 88 (10): 2427–39. https://doi.org/10.1890/06-1736.1.
Lozupone, Catherine, and Rob Knight. 2005. “UniFrac: A New Phylogenetic Method for Comparing Microbial Communities.” Applied and Environmental Microbiology 71 (12): 8228–35. https://doi.org/10.1128/AEM.71.12.8228-8235.2005.
Rao, C. Radhakrishna. 1982. “Diversity and Dissimilarity Coefficients: A Unified Approach.” Theoretical Population Biology 21 (1): 24–43. https://doi.org/10.1016/0040-5809(82)90004-1.

Información de la sesión

sessionInfo()
## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] MicroBioMeta_0.99.0 rmarkdown_2.32     
## 
## loaded via a namespace (and not attached):
##   [1] deldir_2.0-4                gridExtra_2.3.1            
##   [3] permute_0.10-1              rlang_1.3.0                
##   [5] magrittr_2.0.5              otel_0.3.0                 
##   [7] matrixStats_1.5.0           compiler_4.6.2             
##   [9] mgcv_1.9-5                  hillR_0.5.2                
##  [11] png_0.1-9                   vctrs_0.7.3                
##  [13] stringr_1.6.0               pkgconfig_2.0.3            
##  [15] fastmap_1.2.0               backports_1.5.1            
##  [17] XVector_0.53.0              labeling_0.4.3             
##  [19] purrr_1.2.2                 xfun_0.62                  
##  [21] Rfast_2.1.5.2               randomForest_4.7-1.2       
##  [23] cachem_1.1.0                jsonlite_2.0.0             
##  [25] DelayedArray_0.39.8         BiocParallel_1.47.0        
##  [27] jpeg_0.1-11                 broom_1.0.13               
##  [29] parallel_4.6.2              cluster_2.1.8.3            
##  [31] R6_2.6.1                    bslib_0.12.0               
##  [33] stringi_1.8.9               RColorBrewer_1.1-3         
##  [35] car_3.1-5                   zCompositions_1.6.2        
##  [37] GenomicRanges_1.65.4        jquerylib_0.1.4            
##  [39] Rcpp_1.1.2                  Seqinfo_1.3.2              
##  [41] SummarizedExperiment_1.43.0 knitr_1.52                 
##  [43] hilldiv3_3.2.1              directlabels_2026.8.27     
##  [45] IRanges_2.47.5              Matrix_1.7-6               
##  [47] splines_4.6.2               tidyselect_1.2.1           
##  [49] abind_1.4-8                 yaml_2.3.12                
##  [51] ggVennDiagram_1.5.7         vegan_2.7-8                
##  [53] codetools_0.2-20            lattice_0.23-1             
##  [55] tibble_3.3.1                Biobase_2.73.2             
##  [57] withr_3.0.3                 S7_1.0.0                   
##  [59] evaluate_1.0.5              survival_3.8-12            
##  [61] RcppParallel_6.2.1          pillar_1.11.1              
##  [63] ggpubr_1.0.0                MatrixGenerics_1.25.0      
##  [65] carData_3.0-6               stats4_4.6.2               
##  [67] NADA_1.6-1.2                generics_0.1.4             
##  [69] truncnorm_1.0-9             S4Vectors_0.51.10          
##  [71] ggplot2_4.0.4               scales_1.4.0               
##  [73] ALDEx2_1.45.0               glue_1.8.1                 
##  [75] maketools_1.3.2             tools_4.6.2                
##  [77] interp_1.1-6                sys_3.4.3                  
##  [79] data.table_1.18.6.1         ggsignif_0.6.4             
##  [81] ggvenn_0.1.19               buildtools_1.0.0           
##  [83] cowplot_1.2.0               grid_4.6.2                 
##  [85] tidyr_1.3.2                 ape_5.8-1                  
##  [87] latticeExtra_0.6-31         nlme_3.1-172               
##  [89] patchwork_1.3.2             Formula_1.2-6              
##  [91] cli_3.6.6                   zigg_0.0.2                 
##  [93] S4Arrays_1.13.3             dplyr_1.2.1                
##  [95] gtable_0.3.6                ggh4x_0.3.1                
##  [97] rstatix_1.1.0               sass_0.4.10                
##  [99] digest_0.6.39               BiocGenerics_0.59.13       
## [101] SparseArray_1.13.5          ggrepel_0.9.8              
## [103] farver_2.1.2                htmltools_0.5.9            
## [105] lifecycle_1.0.5             MASS_7.3-66