Learn R Programming

⚠️There's a newer version (3.1.9) 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

716

Version

3.0.0

License

GPL (>= 2)

Maintainer

Matteo Delucchi

Last Published

September 6th, 2023

Functions in abn (3.0.0)

BIC.abnFit

Print BIC of objects of class abnFit
AIC.abnFit

Print AIC of objects of class abnFit
createAbnDag

Make DAG of class "abnDag"
check.valid.buildControls

Simple check on the control parameters
discretization

Discretization of a Possibly Continuous Data Frame of Random Variables based on their distribution
check.valid.dag

Set of simple commonsense validity checks on the directed acyclic graph definition matrix
Cfunctions

Documentation of C Functions
entropyData

Computes an Empirical Estimation of the Entropy from a Table of Counts
build.control

Control the iterations in buildScoreCache
bern_bugs

Bugs code for Bernoulli response
ex1.dag.data

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

Synthetic validation data set for use with abn library examples
FCV

Dataset related to Feline calicivirus infection among cats in Switzerland.
.onAttach

Prints start up message
compareDag

Compare two DAGs or EGs
factorial

Factorial
buildScoreCache

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

Compare two DAGs or EGs
calc.node.inla.glmm

Fit a given regression using INLA
check.valid.groups

Simple check on the grouping variable
check.valid.parents

Set of simple checks on the given parent limits
factorial_fast

Fast Factorial
categorical_bugs

Bugs code for Categorical response
check.valid.data

Set of simple commonsense validity checks on the data.df and data.dists arguments
calc.node.inla.glm

Fit a given regression using INLA
ex6.dag.data

Valdiation data set for use with abn library examples
check.which.valid.nodes

Set of simple checks on the list given as parent limits
check.valid.fitControls

Simple check on the control parameters
odds

Probability to odds
coef.abnFit

Print coefficients of objects of class abnFit
irls_binomial_cpp_fast

Fast Iterative Reweighed Least Square algorithm for Binomials
essentialGraph

Construct the essential graph
expit

expit of proportions
ex2.dag.data

Synthetic validation data set for use with abn library examples
eval.across.grid

function to get marginal across an equal grid
searchHillClimber

Find high scoring directed acyclic graphs using heuristic search.
ex4.dag.data

Valdiation data set for use with abn library examples
irls_binomial_cpp_fast_br

Fast Br Iterative Reweighed Least Square algorithm for Binomials
ex5.dag.data

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

Validation data set for use with abn library examples
irls_binomial_cpp_br

BR Iterative Reweighed Least Square algorithm for Binomials
pigs.vienna

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

Make BUGS model from fitted DAG with grouping
expit_cpp

expit function
irls_gaussian_cpp_fast

Fast Iterative Reweighed Least Square algorithm for Gaussians
ex7.dag.data

Valdiation data set for use with abn library examples
get.quantiles

function to extract quantiles from INLA output
irls_gaussian_cpp

Iterative Reweighed Least Square algorithm for Gaussians
get.var.types

Create ordered vector with integers denoting the distribution
fitAbn

Fit an additive Bayesian network model
gauss_bugs

Bugs code for Gaussian response
plot.abnFit

Plot objects of class abnFit
formula_abn

Formula to adjacency matrix
family.abnFit

Print family of objects of class abnFit
irls_poisson_cpp_fast

Fast Iterative Reweighed Least Square algorithm for Poissons
find.next.left.x

Find next X evaluation Point
fit.control

Control the iterations in fitAbn
getMargsINLA

function to extract marginals from INLA output
linkStrength

Returns the strengths of the edge connections in a Bayesian Network learned from observational data
strsplits

Recursive string splitting
mb

Compute the Markov blanket
infoDag

Compute standard information for a DAG.
mi_cpp

Mutual Information
logLik.abnFit

Print logLik of objects of class abnFit
irls_binomial_cpp

Iterative Reweighed Least Square algorithm for Binomials
irls_poisson_cpp

Iterative Reweighed Least Square algorithm for Poissons
mostProbable

Find most probable DAG structure
getModeVector

function to extract the mode from INLA output
getmarginals

Internal function called by fitAbn.bayes.
print.abnCache

Print objects of class abnCache
simulateDag

Simulate a DAG with with arbitrary arcs density
miData

Empirical Estimation of the Entropy from a Table of Counts
makebugs

Make BUGS model from fitted DAG
or

Odds Ratio from a matrix
summary.abnFit

Print summary of objects of class abnFit
scoreContribution

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

Print number of observations of objects of class abnFit
logit

Logit of proportions
print.abnHeuristic

Print objects of class abnHeuristic
searchHeuristic

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

Bugs code for Poisson response
plot.abnHeuristic

Plot objects of class abnHeuristic
skewness

Computes skewness of a distribution
print.abnFit

Print objects of class abnFit
logit_cpp

logit functions
var33

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

Plot objects of class abnMostprobable
print.abnHillClimber

Print objects of class abnHillClimber
print.abnDag

Print objects of class abnDag
plot.abnHillClimber

Plot objects of class abnHillClimber
print.abnMostprobable

Print objects of class abnMostprobable
toGraphviz

Convert a DAG into graphviz format
rank_cpp

Rank of a matrix
plot.abnDag

Plots DAG from an object of class abnDag
std.area.under.grid

Standard Area Under the Marginal
validate_dists

Check for valid distribution
summary.abnDag

Prints summary statistics from an object of class abnDag
plotAbn

Plot an ABN graphic
simulateAbn

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

Print summary of objects of class abnMostprobable
tidy.cache

tidy up cache
validate_abnDag

Check for valid DAG of class abnDag
adg

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

abn Version Information
abn-defunct

Defunct functions and data in package abn
abn-package

abn Package