Package {phymapnet}


Type: Package
Title: Phylogeny-Guided Bayesian Microbial Network Inference
Version: 0.1.3
Description: Implements a phylogeny-aware Bayesian graphical modeling framework for microbial network inference using a shrinkage precision estimator guided by a phylogenetic kernel, with optional hyperparameter-ensemble edge reliability analysis.
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: stats, ape, compositions
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-05-25 21:32:20 UTC; rosa
Author: Rosa Aghdam [aut, cre]
Maintainer: Rosa Aghdam <rosaaghdam@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-26 18:00:02 UTC

Build a phylogenetic kernel from a distance matrix

Description

Build a phylogenetic kernel from a distance matrix

Usage

kernel_from_dist(dist, alpha, kernel = c("gaussian", "laplacian"))

Arguments

dist

A taxa x taxa distance matrix.

alpha

Positive bandwidth parameter.

kernel

Either "gaussian" or "laplacian".

Value

A taxa x taxa kernel matrix.


Fit a single PhyMapNet model

Description

Fit a single PhyMapNet model

Usage

phymapnet_fit(
  otu,
  tree,
  alpha = 0.05,
  k = 5,
  epsilon1 = 0,
  epsilon2 = 0,
  kernel = c("gaussian", "laplacian"),
  th_sparsity = 0.95,
  normalization = c("log", "clr", "tss"),
  prune_tree = TRUE
)

Arguments

otu

samples x taxa matrix.

tree

phylo tree with tips matching taxa, or a named symmetric phylogenetic distance matrix.

alpha

kernel bandwidth (>0).

k

neighborhood scaling (integer >= 1). Uses K_neighbors = k * p internally.

epsilon1

diagonal jitter for omega_hat.

epsilon2

jitter for IB.

kernel

"gaussian" or "laplacian".

th_sparsity

quantile level for sparsification (e.g., 0.95).

normalization

"log", "clr", or "tss".

prune_tree

prune tree tips not in OTU when tree is a phylogenetic tree; distance matrices are aligned directly.

Value

A list with precision_map, adjacency, threshold, taxa, dist, kernel_mat.


Internal PhyMapNet precision MAP estimator

Description

Internal PhyMapNet precision MAP estimator

Usage

phymapnet_precision(Y, nue, epsilon1, epsilon2, C)

Prepare inputs for PhyMapNet

Description

Computes a patristic distance matrix from a phylogenetic tree, or validates a supplied phylogenetic distance matrix, then aligns taxa to the OTU table.

Usage

phymapnet_prepare_inputs(otu, tree, prune = TRUE)

Arguments

otu

A samples x taxa count/abundance matrix (rownames=samples, colnames=taxa).

tree

A phylo object with tip labels as taxa names, or a named, symmetric taxa x taxa phylogenetic distance matrix.

prune

Logical; if TRUE and tree is a phylo object, prunes tree tips not found in OTU before distances are computed. Input taxa are always aligned to their shared set.

Value

A list with otu (aligned), dist (aligned), taxa.


Edge reliability via hyperparameter ensemble

Description

Runs an ensemble over (alpha, k, epsilon1, epsilon2, kernel, normalization) and returns edge reliability as selection frequency under fixed sparsification threshold.

Usage

phymapnet_reliability(
  otu,
  tree,
  th_fixed = 0.95,
  alpha_range = seq(0.01, 0.12, by = 0.01),
  k_range = 2:10,
  epsilon1_range = seq(0, 1, by = 0.1),
  epsilon2_range = seq(0, 1, by = 0.1),
  kernels = c("gaussian"),
  normalizations = c("log", "clr", "tss"),
  consensus_cut = 0.5,
  prune_tree = TRUE,
  progress = TRUE,
  progress_every = 500
)

Arguments

otu

samples x taxa matrix.

tree

phylo tree, or a named symmetric phylogenetic distance matrix.

th_fixed

fixed quantile threshold for sparsification across all models (e.g., 0.95).

alpha_range

numeric vector.

k_range

integer vector.

epsilon1_range

numeric vector.

epsilon2_range

numeric vector.

kernels

character vector: "gaussian" and/or "laplacian".

normalizations

character vector: subset of c("log","clr","tss").

consensus_cut

reliability cutoff for binary consensus (default 0.5).

prune_tree

prune tree tips not in OTU when tree is a phylogenetic tree; distance matrices are aligned directly.

progress

print progress every progress_every models.

progress_every

integer.

Value

A list with rel_mat, consensus_mat, edge_list, N_models, grid.


Quantile sparsification

Description

Quantile sparsification

Usage

sparse_quantile(Isigma_star, quantile_level)