Bayesian General Mixed Yule-Coalescent (GMYC) model for species delimitation in R β₯ 4.0
bGMYC4 implements a Bayesian version of the General Mixed Yule-Coalescent model for species delimitation from single-locus data. It uses Markov Chain Monte Carlo (MCMC) simulation to evaluate the posterior distribution of species boundaries, allowing the use of multiple phylogenetic trees to account for phylogenetic uncertainty. The package includes interactive diagnostics, parameter tuning, and visualization tools. Full documentation and interactive vignette available in both English and Russian. Full simple interactiv scrip available in inst\scripts
| Feature | Description |
|---|---|
| π² Single & Multi-tree analysis | Run GMYC on one tree or pool uncertainty across multiple BEAST2 trees |
| π Interactive diagnostics | Real-time MCMC checks: trace plots, acceptance rates, ESS, Gelman-Rubin RΜ, auto-tuning hints |
| βοΈ Parameter tuning | Safe input handlers with biological hints for priors, scales, and thresholds |
| π‘οΈ Heatmap visualization | Conspecificity probability matrices ordered by tree topology |
| π Bilingual workflow | Full EN/RU documentation and interactive vignette |
| 𧬠BEAST2 ready | Automatic cleaning of Nexus annotations and ultrametricity enforcement |
| β‘ Optimized performance | Parallel bgmyc.multiphylo(), pure-R post-processing, vectorized matrices |
| β Full CRAN compliance | 0 errors, 0 warnings, 0 notes |
| β‘ High-performance prallelization | Stable parallel backend for Windows |
| π§Ή Pure-R post-processing | No external sort/uniq dependencies |
| π Detailed guide | Interactive vignette with dynamic convergence diagnostics (need knitr, rmarkdown, pandoc). Full simple interactiv scrip available in inst\scripts
|
install.packages("bGMYC4")
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
remotes::install_github("DmitryKarabanov/bGMYC4", build_vignettes = TRUE)
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)
ape, future, future.apply, parallel, knitr, rmarkdown
mcmcse (for ESS & Gelman-Rubin $\hat{R}$ convergence checks)library(bGMYC4)
browseVignettes("bGMYC4")
# Or run directly:
vignette("bGMYC4-interactive", package = "bGMYC4")
# Load built-in test data
data(east10)
# Run single-tree analysis (short MCMC for testing)
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)
)
# Check convergence
plot(result)
# Build conspecificity matrix
prob_mat <- spec.probmat(result)
plot(prob_mat, east10[[1]])
# Extract species clusters (your threshold)
out <- bgmyc.point(prob_mat, ppcutoff = 0.05)
cat("Delimited clusters:", length(out), "\n")
| 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 |
Data selection
east10 (simulated).tree, .trees)Tree preprocessing
[&...]
fix_ultrametric())Interactive diagnostics
bgmyc.singlephy() on one treeplot(result))Multi-tree analysis
bgmyc.multiphylo() on sampled treesVisualization and delimitation
spec.probmat())ppcutoff (e.g., 0.05)| Parameter | Role | Recommended Range | Notes |
|---|---|---|---|
mcmc |
Chain length |
10k (test), 50k+ (final) |
Longer = better posterior resolution |
burnin |
Burn-in |
20β30% of mcmc
|
Discards non-stationary start |
thinning |
Sampling interval | 10β50 |
Reduces autocorrelation & RAM usage |
py1, py2
|
Yule rate priors |
0, 0.5β1.5
|
Model: Ξ» β n^py; >1.5 blurs Yule/Coalescent boundary |
pc1, pc2
|
Coalescent priors |
0, 1.0β2.0
|
Models Ne change; <1 β decline, >1 β growth |
t1, t2
|
Threshold prior (species count) |
2, min(y, ntips-1)
|
Must be < ntips; auto-capped to prevent crashes |
scale |
MCMC proposal widths | c(20β30, 10β15, 3β7) |
Tune via acceptance rates; higher = more conservative |
ppcutoff |
Species lumping threshold |
0.05 , 0.01
|
Low = captures high intraspecific variation / ILS |
The optimized bGMYC4 is fully compatible with R β₯ 4.5 and includes:
| Feature / ΠΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ | Description |
|---|---|
| π Automatic parallelization |
bgmyc.multiphylo() runs in parallel via future.apply (uses all CPU cores by default) |
| π§Ή Pure-R post-processing |
bgmyc.spec() and spec.probmat() use native R functions β no external sort/uniq dependencies |
| π Vectorized operations | Faster heatmap construction and matrix indexing |
| π Parallel-safe RNG |
future.seed = TRUE ensures reproducible multi-tree analyses |
| π₯οΈ R β₯ 4.5 compatibility | Full support for modern R features, byte-compilation (compiler::enableJIT(3)), and optimized memory management |
mcmcse is installed. Target: ESS > 200.mcmcse is available. Target: RΜ < 1.05.# Before running bgmyc.multiphylo():
future::plan(future::multisession, workers = 8) # Use 8 cores instead of all
# After bgmyc.spec():
write.csv(spec_out$specprobs,
file = "bGMYC_clusters.csv",
row.names = FALSE,
fileEncoding = "UTF-8")
# Compare Yule vs Coalescent rates:
rates <- checkrates(result_multi)
plot(rates) # Opens 4 diagnostic plots
# Add to your ~/.Rprofile for automatic JIT acceleration:
compiler::enableJIT(3) # +2β3% speedup on all MCMC loops, no code changes
| Issue | Solution |
|---|---|
Your input tree is not ultrametric |
Use fix_ultrametric() or check BEAST2 export settings |
start[3] out of bounds |
Ensure t1 < start[3] < t2; script auto-clamps values |
Error in read.nexus |
Verify files are Nexus format; use read.tree() for Newick |
| Non-ASCII warning in check | All R code now uses ASCII-only; comments may contain UTF-8 |
Error: package 'ape' is not available |
Run install.packages("ape") first |
future::evalFuture() failed |
Ensure package is installed |
Non-ASCII characters in Rd file |
All R code is ASCII; comments may contain UTF-8 β this is CRAN-compliant |
ESS: package 'mcmcse' not installed |
Run install.packages("mcmcse"). The package works without it, but full convergence stats require it. |
If you use bGMYC4 in your research, 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. Developed with assistance from Qwen3.6 AI assistant.},
url = {https://github.com/DmitryKarabanov/bGMYC4},
}
Please, cite the foundational works:
Contributions are welcome!
bGMYC4 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3.0.
See LICENSE for details.
Dmitry Karabanov
π§ dk[at]ibiw.ru
π Institute for Biology of Inland Waters, RAS
π ORCID
βΉοΈ This package was developed with assistance from Qwen3.6, an AI language model by Alibaba Cloud. The AI provided code optimization suggestions, 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 πΏπ¬