bGMYC4

Reid’s Bayesian species delimitation, made reproducible and accessible

bGMYC4 logo

License: GPL v3

CRAN status

Total downloads

Lifecycle: stable

Bayesian General Mixed Yule-Coalescent (GMYC) model for species delimitation in R ≥ 4.0


🌍 Overview

bGMYC4 implements the Bayesian GMYC model of Reid & Carstens (2012): MCMC sampling of the threshold between Yule (speciation) and coalescent (within-species) branching on ultrametric trees. Pooling samples over a posterior sample of trees propagates phylogenetic uncertainty into marginal posterior probabilities of species limits and pairwise conspecificity.


What’s new in 4.3.1


✨ Key Features

Feature Description
🌲 Single & multi-tree analysis Run GMYC on one tree, or pool over a posterior sample of trees
⚡ Parallel multi-tree runs bgmyc.multiphylo(..., cores = k) uses a parallel cluster; cores = 1 (default) runs sequentially
🎲 Reproducible RNG bgmyc.multiphylo(..., seed = 42) assigns independent L’Ecuyer-CMRG substreams per tree
📊 Interactive diagnostics Trace plots, acceptance rates, ESS (optional mcmcse), split-R̂ via bgmyc.convergence()
🌡️ Heatmap visualisation Conspecificity matrices ordered by tree topology; static and interactive (plotly)
🧬 BEAST-friendly workflow The helper script in inst/scripts/ reads BEAST trees via treeio, prunes outgroups and checks ultrametricity
🐇 Pure-R post-processing Threshold-aggregated, vectorised; no external sort/uniq dependencies
📖 Interactive vignette vignette("bGMYC4-interactive", package = "bGMYC4")

📦 Installation

install.packages("bGMYC4")

🔹 From GitHub (latest version)

if (!requireNamespace("remotes", quietly = TRUE)) {
  install.packages("remotes")
}
remotes::install_github("DmitryKarabanov/bGMYC4", build_vignettes = TRUE)

🔹 From source archive

install.packages("path/to/bGMYC4.tar.gz", repos = NULL, type = "source")
# To build vignettes locally:
# install.packages("path/to/bGMYC4.tar.gz", repos = NULL, type = "source", build_vignettes = TRUE)

🔹 System requirements


🚀 Quick Start

library(bGMYC4)
data(east10)          # 10 posterior trees, 215 tips

## one tree (short chain for a smoke test)
result <- bgmyc.singlephy(
  phylo = east10[[1]],
  mcmc = 1000, burnin = 200, thinning = 10,
  py1 = 0, py2 = 1.5, pc1 = 0, pc2 = 2,
  t1 = 2, t2 = 35,
  scale = c(20, 10, 5), start = c(1, 0.5, 10)
)

plot(result)          # trace plots
summary(result)       # threshold mean + 95% HPD

## conspecificity matrix
prob_mat <- spec.probmat(result)
plot(prob_mat, east10[[1]])

## point estimate of species clusters
out <- bgmyc.point(prob_mat, ppcutoff = 0.5)
cat("Delimited clusters:", length(out), "\n")

For a publication-grade analysis, run many trees with long chains, e.g.

res <- bgmyc.multiphylo(east10, mcmc = 10000, burnin = 1000, thinning = 100,
                        cores = 4, seed = 42)
pm  <- spec.probmat(res)
summary(res)

📚 Documentation

Resource Command Description
Package help ?bGMYC4 Function reference
Interactive tutorial browseVignettes("bGMYC4") Step-by-step workflow with diagnostics
Function details ?bgmyc.multiphylo, ?spec.probmat Parameter explanations
Built-in data ?east10 Simulated dataset for testing
Performance tips vignette("bGMYC4-interactive", package = "bGMYC4") Section “Performance & Export”
Example inst/scripts/bGMYC.R Simple interactive script

Workflow

  1. Preprocess trees. Ultrametric, fully bifurcating, no zero-length terminal branches. Use fix_ultrametric() if BEAST export produced rounding-level noise.
  2. Tune on one tree. bgmyc.singlephy() → plot() → acceptance rates and ESS.
  3. Run the posterior sample. bgmyc.multiphylo() with the tuned settings.
  4. Summarise. spec.probmat() → heatmap; bgmyc.point() for a point estimate; bgmyc.spec() for the full posterior of species partitions (optionally as species-by-locality matrices via cmatrix, for downstream community analyses).

Parameters

Parameter Role Typical values Notes
mcmc Chain length 10 000 (test), 50 000+ (final) Reid & Carstens (2012) used 10 000 per tree over 100 trees
burnin Burn-in 10–30 % of mcmc The original study discarded 1 000 of 10 000
thinning Sampling interval 10–100 Reduces autocorrelation and RAM
py1, py2 Yule rate-change prior 0, 0.5–1.5 λ ∝ n^py; values above ~1.5 blur the Yule/coalescent boundary
pc1, pc2 Coalescent rate-change prior 0, 1.0–2.0 < 1 → decline, > 1 → growth
t1, t2 Threshold prior (number of species) 2, min(Nnode, …) t2 above Nnode = ntips − 1 is unreachable; the prior is truncated and a warning is issued
scale Proposal widths (py, pc, t) c(20, 10, 5) Tune via acceptance rates; aim for ~0.2–0.4 on long chains
ppcutoff Threshold for lumping tips into species in bgmyc.point() 0.05 (value used in the original bGMYC documentation), 0.01 Single linkage; see “Choosing ppcutoff” below. Do not round the matrix before calling bgmyc.point()

Choosing ppcutoff

spec.probmat() returns the marginal posterior probability that two tips were placed in the same species, pooled over all retained thresholds and (for multibgmyc) over all trees. It is therefore not comparable to a clade posterior probability. A well-supported biological species can show pairwise values well below 0.5 simply because the threshold posterior is broad or because trees disagree, whereas pairs from different species usually sit close to 0. The informative gap is near zero — which is why the original bGMYC documentation uses 0.05.

bgmyc.point() is a single-linkage procedure: tips join when P > cutoff and clusters merge transitively. A species is therefore held together by its weakest link. Even when most pairs inside a real species have P = 1, a single uncertain pair bridging two intraspecific lineages (e.g. populations from different river basins) may be their only connection. Raising the cutoff removes such bridges and fragments real species into phylogeographic subgroups, whereas pairs from different species usually have P near 0 and remain separated even at very low cutoffs. On empirical data the stability plateau is typically found at low values (0.001-0.05); the original bGMYC documentation uses 0.05.

Choose the value from your own data:

pm <- spec.probmat(res)          # do NOT round before bgmyc.point()
sw <- c(0.001, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.9)
data.frame(cutoff = sw,
           clusters = vapply(sw, function(p) length(bgmyc.point(pm, p)), integer(1)))

Look for a plateau — a range of cutoffs where the number of clusters is stable — and check it against independent evidence (morphology, geography, nuclear markers). Report the chosen cutoff and the plateau in your methods section.

Performance and parallelism

## limit the number of workers used by the package
res <- bgmyc.multiphylo(trees, mcmc = 10000, burnin = 1000, thinning = 100,
                        cores = 8, seed = 42)

bgmyc.multiphylo() uses parallel::makeCluster(). Use the cores argument.

Post-processing cost depends on the number of distinct thresholds, not on the number of retained samples, which is why long chains and large tree sets remain fast.

Convergence diagnostics

⚠️ R̂ is not computed across different trees. Each posterior tree defines its own conditional posterior, so a cross-tree R̂ is not a valid convergence statistic. summary() therefore reports per-tree diagnostics alongside the pooled marginal summary.

Troubleshooting

Issue Solution
Your input tree is not ultrametric Try fix_ultrametric(tr); if it still fails, the tree is genuinely non-clock — re-export from BEAST or check the clock model
All trees must share the same tip label set Prune/rename tips so every tree has the same labels before bgmyc.multiphylo()
'scale' must be three positive numbers Proposal widths must all be > 0
Prior bounds must satisfy py1 < py2 … Lower bound must be strictly below the upper bound
cmatrix must have rownames covering all tree tip labels Set rownames(cmatrix) to the tip labels
Trees contributed unequal numbers of samples Use identical mcmc/burnin/thinning for equal-weight model averaging
Interactive heatmap not saved Install plotly, base64enc, htmlwidgets

Citation

If you use bGMYC4, please cite:

@Manual{bGMYC4,
  title  = {bGMYC4: Bayesian General Mixed Yule-Coalescent Model for Species Delimitation},
  author = {Karabanov, Dmitry},
  year   = {2026},
  note   = {R package version 4.3.1},
  url    = {https://github.com/DmitryKarabanov/bGMYC4}
}

Foundational work:

citation("bGMYC4") prints both entries.

License

GPL (≥ 3). See the DESCRIPTION file.

Author

Dmitry Karabanov — dk[at]ibiw.ru Institute for Biology of Inland Waters, RAS ORCID: 0000-0001-6008-7441

Original bGMYC implementation: Noah Reid.

Acknowledgements

This package was developed with assistance from the Qwen AI assistant (Alibaba Cloud), which provided code review, debugging support and documentation drafting. All scientific decisions, parameter choices and biological interpretations were made by the author.


bGMYC4 – Bayesian species delimitation, made simple, reproducible, and biologist‑friendly 🌿🔬