Learn R Programming

⚠️There's a newer version (3.1.1) of this package.Take me there.

abn - Additive Bayesian Networks

Bayesian network analysis is a form of probabilistic graphical models which derives from empirical data a directed acyclic graph, DAG, describing the dependency structure between random variables.

An additive Bayesian network model consists of a form of a DAG where each node comprises a generalized linear model, GLM. Additive Bayesian network models are equivalent to Bayesian multivariate regression using graphical modelling, they generalises the usual multivariable regression, GLM, to multiple dependent variables.

'abn' provides routines to help determine optimal Bayesian network models for a given data set, where these models are used to identify statistical dependencies in messy, complex data. The additive formulation of these models is equivalent to multivariate generalised linear modelling (including mixed models with iid random effects).

The usual term to describe this model selection process is structure discovery.

The core functionality is concerned with model selection - determining the most robust empirical model of data from interdependent variables. Laplace approximations are used to estimate goodness of fit metrics and model parameters, and wrappers are also included to the INLA package which can be obtained from https://www.r-inla.org.

The computing library JAGS https://mcmc-jags.sourceforge.io is used to simulate 'abn'-like data.

A comprehensive set of documented case studies, numerical accuracy/quality assurance exercises, and additional documentation are available from the 'abn' website http://r-bayesian-networks.org.

Installation

You can install the latest release from CRAN with

install.packages("abn")

The recent development version can be installed from:

remotes::install_gitlab("https://git.math.uzh.ch/mdeluc/abn.git")

Example

This is a basic example which shows you how to solve a common problem:

library(abn)
## Built-in dataset with a subset of cols
mydat <- ex0.dag.data[,c("b1","b2","b3","g1","b4","p2","p4", "g2")]

## setup distribution list for each node
mydists <- list(b1="binomial", 
                b2="binomial", 
                b3="binomial",
                g1="gaussian",
                b4="binomial",
                p2="poisson",
                p4="poisson",
                g2="gaussian")

# Structural constraints
# ban arc from b2 to b1
# always retain arc from g2 to g1

## now build the cache of pre-computed scores accordingly to the structural constraints
mycache.mle <- buildScoreCache(data.df=mydat, 
                         data.dists=mydists,
                         dag.banned= ~b1|b2, 
                         dag.retained= ~g1|g2, 
                         max.parents=3,
                         method = "mle")

## Find most probable DAG
mp.dag.mle <- mostProbable(mycache.mle)

## Now fit the model to calculate its goodness-of-fit
myres <- fitAbn(object=mp.dag.mle,
                method = "mle")

## Plot the DAG
plotAbn(myres)

## Log-marginal likelihood goodness-of-fit for complete DAG
print(myres$mlik)

Copy Link

Version

Install

install.packages('abn')

Monthly Downloads

819

Version

3.0.1

License

GPL (>= 2)

Maintainer

Matteo Delucchi

Last Published

October 9th, 2023

Functions in abn (3.0.1)

calc.node.inla.glmm

Fit a given regression using INLA
check.valid.data

Set of simple commonsense validity checks on the data.df and data.dists arguments
check.valid.buildControls

Simple check on the control parameters
calc.node.inla.glm

Fit a given regression using INLA
buildScoreCache

Build a cache of goodness of fit metrics for each node in a DAG, possibly subject to user-defined restrictions
check.valid.fitControls

Simple check on the control parameters
check.valid.parents

Set of simple checks on the given parent limits
check.valid.groups

Simple check on the grouping variable
adg

Dataset related to average daily growth performance and abattoir findings in pigs commercial production.
categorical_bugs

Bugs code for Categorical response
coef.abnFit

Print coefficients of objects of class abnFit
check.valid.dag

Set of simple commonsense validity checks on the directed acyclic graph definition matrix
check.which.valid.nodes

Set of simple checks on the list given as parent limits
compareEG

Compare two DAGs or EGs
essentialGraph

Construct the essential graph
.onAttach

Prints start up message
compareDag

Compare two DAGs or EGs
entropyData

Computes an Empirical Estimation of the Entropy from a Table of Counts
eval.across.grid

function to get marginal across an equal grid
ex7.dag.data

Valdiation data set for use with abn library examples
ex6.dag.data

Valdiation data set for use with abn library examples
ex0.dag.data

Synthetic validation data set for use with abn library examples
ex1.dag.data

Synthetic validation data set for use with abn library examples
ex3.dag.data

Validation data set for use with abn library examples
createAbnDag

Make DAG of class "abnDag"
discretization

Discretization of a Possibly Continuous Data Frame of Random Variables based on their distribution
ex2.dag.data

Synthetic validation data set for use with abn library examples
ex4.dag.data

Valdiation data set for use with abn library examples
fit.control

Control the iterations in fitAbn
family.abnFit

Print family of objects of class abnFit
find.next.left.x

Find next X evaluation Point
fitAbn

Fit an additive Bayesian network model
formula_abn

Formula to adjacency matrix
ex5.dag.data

Valdiation data set for use with abn library examples
getMSEfromModes

Extract Standard Deviations from all Gaussian Nodes
gauss_bugs

Bugs code for Gaussian response
getmarginals

Internal function called by fitAbn.bayes.
getModeVector

function to extract the mode from INLA output
factorial

Factorial
factorial_fast

Fast Factorial
expit_cpp

expit function
irls_gaussian_cpp

Iterative Reweighed Least Square algorithm for Gaussians
getMargsINLA

function to extract marginals from INLA output
irls_binomial_cpp_fast_br

Fast Br Iterative Reweighed Least Square algorithm for Binomials
infoDag

Compute standard information for a DAG.
expit

expit of proportions
irls_binomial_cpp

Iterative Reweighed Least Square algorithm for Binomials
irls_poisson_cpp

Iterative Reweighed Least Square algorithm for Poissons
irls_gaussian_cpp_fast

Fast Iterative Reweighed Least Square algorithm for Gaussians
irls_poisson_cpp_fast

Fast Iterative Reweighed Least Square algorithm for Poissons
logit_cpp

logit functions
mb

Compute the Markov blanket
miData

Empirical Estimation of the Entropy from a Table of Counts
makebugsGroup

Make BUGS model from fitted DAG with grouping
modes2coefs

Convert modes to fitAbn.mle$coefs structure
mostProbable

Find most probable DAG structure
get.var.types

Create ordered vector with integers denoting the distribution
makebugs

Make BUGS model from fitted DAG
print.abnCache

Print objects of class abnCache
get.quantiles

function to extract quantiles from INLA output
or

Odds Ratio from a matrix
pigs.vienna

Dataset related to diseases present in `finishing pigs', animals about to enter the human food chain at an abattoir.
print.abnHillClimber

Print objects of class abnHillClimber
print.abnHeuristic

Print objects of class abnHeuristic
print.abnDag

Print objects of class abnDag
pois_bugs

Bugs code for Poisson response
print.abnFit

Print objects of class abnFit
nobs.abnFit

Print number of observations of objects of class abnFit
odds

Probability to odds
irls_binomial_cpp_br

BR Iterative Reweighed Least Square algorithm for Binomials
linkStrength

Returns the strengths of the edge connections in a Bayesian Network learned from observational data
plot.abnDag

Plots DAG from an object of class abnDag
logLik.abnFit

Print logLik of objects of class abnFit
mi_cpp

Mutual Information
irls_binomial_cpp_fast

Fast Iterative Reweighed Least Square algorithm for Binomials
logit

Logit of proportions
std.area.under.grid

Standard Area Under the Marginal
simulateDag

Simulate a DAG with with arbitrary arcs density
skewness

Computes skewness of a distribution
var33

simulated dataset from a DAG comprising of 33 variables
plot.abnMostprobable

Plot objects of class abnMostprobable
validate_dists

Check for valid distribution
plot.abnFit

Plot objects of class abnFit
plotAbn

Plot an ABN graphic
searchHillClimber

Find high scoring directed acyclic graphs using heuristic search.
simulateAbn

Simulate data from a fitted additive Bayesian network.
summary.abnFit

Print summary of objects of class abnFit
summary.abnDag

Prints summary statistics from an object of class abnDag
strsplits

Recursive string splitting
print.abnMostprobable

Print objects of class abnMostprobable
rank_cpp

Rank of a matrix
validate_abnDag

Check for valid DAG of class abnDag
toGraphviz

Convert a DAG into graphviz format
plot.abnHillClimber

Plot objects of class abnHillClimber
tidy.cache

tidy up cache
summary.abnMostprobable

Print summary of objects of class abnMostprobable
plot.abnHeuristic

Plot objects of class abnHeuristic
searchHeuristic

A family of heuristic algorithms that aims at finding high scoring directed acyclic graphs
scoreContribution

Compute the score's contribution in a network of each observation.
bern_bugs

Bugs code for Bernoulli response
Cfunctions

Documentation of C Functions
BIC.abnFit

Print BIC of objects of class abnFit
abn.version

abn Version Information
FCV

Dataset related to Feline calicivirus infection among cats in Switzerland.
AIC.abnFit

Print AIC of objects of class abnFit
build.control

Control the iterations in buildScoreCache
abn-package

abn Package
abn-defunct

Defunct functions and data in package abn