misc utilities {bnlearn} R Documentation

Miscellaneous utilities

Description

Assign or extract various quantities of interest from an object of class bn of bn.fit.

Usage

## nodes
mb(x, node)
nbr(x, node)
parents(x, node)
parents(x, node, debug = FALSE) <- value
children(x, node)
children(x, node, debug = FALSE) <- value
spouses(x, node)
ancestors(x, node)
descendants(x, node)
in.degree(x, node)
out.degree(x, node)
root.nodes(x)
leaf.nodes(x)
nnodes(x)

## arcs
arcs(x)
arcs(x, check.cycles = TRUE, check.illegal = TRUE, debug = FALSE) <- value
directed.arcs(x)
undirected.arcs(x)
incoming.arcs(x, node)
outgoing.arcs(x, node)
incident.arcs(x, node)
compelled.arcs(x)
reversible.arcs(x)
narcs(x)

## adjacency matrix
amat(x)
amat(x, check.cycles = TRUE, check.illegal = TRUE, debug = FALSE) <- value

## graphs
nparams(x, data, effective = FALSE, debug = FALSE)
ntests(x)

## shared with the graph package.
# these used to be a simple nodes(x) function.
## S4 method for signature 'bn'
nodes(object)
## S4 method for signature 'bn.fit'
nodes(object)
# these used to be a simple degree(x, node) function.
## S4 method for signature 'bn'
degree(object, Nodes)
## S4 method for signature 'bn.fit'
degree(object, Nodes)

Arguments

x, object

an object of class bn or bn.fit. The replacement form of parents, children, arcs and amat requires an object of class bn.

node, Nodes

a character string, the label of a node.

value

either a vector of character strings (for parents and children), an adjacency matrix (for amat) or a data frame with two columns (optionally labeled "from" and "to", for arcs).

data

a data frame containing the data the Bayesian network was learned from. It's only needed if x is an object of class bn.

check.cycles

a boolean value. If FALSE the returned network will not be checked for cycles.

check.illegal

a boolean value. If TRUE arcs that break the parametric assumptions of x, such as those from continuous to discrete nodes in conditional Gaussian networks, cause an error.

effective

a boolean value. If TRUE the number of non-zero free parameters is returned, that is, the effective degrees of freedom of the network; otherwise the theoretical number of parameters is returned.

debug

a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Details

The number of parameters of a discrete Bayesian network is defined as the sum of the number of logically independent parameters of each node given its parents (Chickering, 1995). For Gaussian Bayesian networks the distribution of each node can be viewed as a linear regression, so it has a number of parameters equal to the number of the parents of the node plus one (the intercept) as per Neapolitan (2003). For conditional linear Gaussian networks, the number of parameters of discrete and Gaussian nodes is as above. The number of parameters of conditional Gaussian nodes is equal to 1 plus the number of continuous parents (who get one regression coefficient each, plus the intercept) times the number of configurations of the discrete parents (each configuration has an associated regression model).

Value

mb, nbr, nodes, parents, children, spouses, ancestors, descendants, root.nodes and leaf.nodes return a vector of character strings.

arcs, directed.arcs, undirected.arcs, incoming.arcs, outgoing.arcs, incident.arcs,
compelled.arcs, reversible.arcs, return a matrix of two columns of character strings.

narcs and nnodes return the number of arcs and nodes in the graph, respectively.

amat returns a matrix of 0/1 integer values.

degree, in.degree, out.degree, nparams and ntests return an integer.

Author(s)

Marco Scutari

References

Chickering DM (1995). "A Transformational Characterization of Equivalent Bayesian Network Structures". Proceedings of the Eleventh Annual Conference on Uncertainty in Artificial Intelligence, 87–98.

Neapolitan RE (2003). Learning Bayesian Networks. Prentice Hall.

Examples

data(learning.test)
cpdag = pc.stable(learning.test)

##  the Markov blanket of A.
mb(cpdag, "A")
## the neighbourhood of F.
nbr(cpdag, "F")
## the arcs in the graph.
arcs(cpdag)
## the nodes of the graph.
nodes(cpdag)
## the adjacency matrix for the nodes of the graph.
amat(cpdag)
## the parents of D.
parents(cpdag, "D")
## the children of A.
children(cpdag, "A")
## the root nodes of the graph.
root.nodes(cpdag)
## the leaf nodes of the graph.
leaf.nodes(cpdag)
## number of parameters of the Bayesian network.
dag = set.arc(cpdag, "A", "B")
nparams(dag, learning.test)