Are you using, or planning to use, Bayesian network models in your work? I have more than 10 years of experience in doing that both in academia and in the industry. Feel free to get in touch at consulting@bnlearn.com to discuss your needs and to see how I can help.
bnlearn is an R package for learning the graphical structure of Bayesian networks, estimating their parameters and performing probabilistic and causal inference. First released in 2007, it has been under continuous development for more than 10 years (and still going strong). To get started and install the latest development snapshot type
install.packages("https://www.bnlearn.com/releases/bnlearn_latest.tar.gz", repos = NULL, type = "source")
in your R console. (More detailed installation instructions below.)
To report any bugs, to ask for help and for general enquiries please email me at scutari@bnlearn.com.
Downloads | |
---|---|
current release on CRAN: | |
5.0.1 | [ link ] |
latest snapshot + bugfixes: | |
5.1-20241001 | [ link ] |
From the R Studio CRAN Mirror: | |
---|---|
Research Impact: | |
Features
bnlearn provides an open implementation of large parts of the literature on Bayesian networks:
- Classes of Bayesian networks: discrete (multinomial) Bayesian networks for discrete data, Gaussian Bayesian networks for continuous data and Conditional Gaussian networks for mixed data.
- Structure learning algorithms: constraint-based (PC Stable, Grow-Shrink, IAMB, Fast-IAMB, Inter-IAMB, IAMB-FDR, MMPC, Semi-Interleaved HITON-PC, HPC), score-based (hill climbing and tabu search) and hybrid (MMHC, H2PC, RSMAX2).
- Local discovery algorithms: Chow-Liu spanning trees and ARACNE.
- Bayesian network classifiers: naive Bayes and TAN.
- Parameter learning methods: maximum likelihood, Bayesian, hierarchical and Expectation-Maximization parameter estimators.
- Conditional independence tests: mutual information, Pearson's X2, Jonckheere-Terpstra, linear correlation, Fisher's Z, shrinkage tests. Several tests are implemented as parametric, semiparametric and permutation tests.
- Network scores: log-likelihood, predictive log-likelihood, K2, AIC, BIC, different Dirichlet marginal likelihoods (BDe, BDs, BDJ), a modified Bayesian Dirichlet for mixtures of interventional and observational data, the locally averaged BDe score (BDla), fNML, qNML, a score equivalent Gaussian posterior density (BGe).
- Inference: random data generation and approximate inference for all classes of Bayesian networks, exact inference for discrete and Gaussian Bayesian networks.
- Expert knowledge: creating Bayesian networks with user-specified structures and parameters, incorporating prior knowledge into structure learning through arc priors, whitelists and blacklists.
- Model validation: prediction, cross-validation, arc strength (through bootstrap, network scores or conditional independence tests).
- Advanced plotting: network plots based on Rgraphviz, diagnostic plots based on the lattice package.
- Import and export: to and from other R package as well as standard file formats (BIF, DSC, NET).
- Missing data: supported throughout structure learning, parameter learning and inference.
A brief overview of bnlearn can be found here, with more examples here.
Package installation
bnlearn is available on CRAN and can be downloaded from its web page in the Packages section (here). It can be installed with a simple:
install.packages("bnlearn")
Development snapshots, which include bugfixes that will be incorporated in the CRAN release as well as new features, can be downloaded from the links above or installed with a simple:
install.packages("http://www.bnlearn.com/releases/bnlearn_latest.tar.gz")
The only suggested packages not hosted on CRAN are graph and Rgraphviz, which can be installed from BioConductor:
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install() BiocManager::install(c("graph", "Rgraphviz"))
following the instructions present on this and this webpages. Please also note that the gRain package, while on CRAN, depends on packages that are on Bioconductor both directly and through the gRbase package, which depends on RBGL:
BiocManager::install() BiocManager::install(c("graph", "Rgraphviz", "RBGL")) install.packages("gRain")