graph utilities {bnlearn}R Documentation

Utilities to manipulate graphs

Description

Check and manipulate graph-related properties of an object of class bn.

Usage

# check whether the graph is acyclic/completely directed.
acyclic(x, directed, debug = FALSE)
directed(x)
# check whether there is a path between two nodes.
path(x, from, to, direct = TRUE, underlying.graph = FALSE,
  debug = FALSE)
# build the skeleton or a complete orientation of the graph.
dag2ug(x)
pdag2dag(x, ordering)

Arguments

x an object of class bn.
from a character string, the label of a node.
to a character string, the label of a node (different from from).
direct a boolean value. If FALSE ignore any arc between from and to when looking for a path.
directed a boolean value. If TRUE the graph is assumed to be completely directed (no undirected arcs), and a faster cycle detection algorithm is used.
underlying.graph a boolean value. If TRUE the underlying undirected graph is used instead of the (directed) one from the x parameter.
ordering the labels of all the nodes in the graph; their order is the node ordering used to set the direction of undirected arcs.
debug a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Value

acyclic, path and directed return a boolean value.
dag2ug and pdag2dag return an object of class bn.

Author(s)

Marco Scutari

References

Bang-Jensen J, Gutin G (2009). Digraphs: Theory, Algorithms and Applications. Springer, 2nd edition.

Examples

data(learning.test)
res = gs(learning.test)

acyclic(res)
# [1] TRUE
directed(res)
# [1] FALSE
res = pdag2dag(res, ordering = LETTERS[1:6])
res
#
#   Bayesian network learned via Constraint-based methods
#
#   model:
#     [A][C][F][B|A][D|A:C][E|B:F]
#   nodes:                                 6
#   arcs:                                  5
#     undirected arcs:                     0
#     directed arcs:                       5
#   average markov blanket size:           2.33
#   average neighbourhood size:            1.67
#   average branching factor:              0.83
#
#   learning algorithm:                    grow-shrink
#   conditional independence test:         mutual information (discrete)
#   alpha threshold:                       0.05
#   tests used in the learning procedure:  41
#   optimized:                             TRUE
#
directed(res)
# [1] TRUE
dag2ug(res)
#
#   Bayesian network learned via Constraint-based methods
#
#   model:
#     [partially directed graph]
#   nodes:                                 6
#   arcs:                                  5
#     undirected arcs:                     5
#     directed arcs:                       0
#   average markov blanket size:           1.67
#   average neighbourhood size:            1.67
#   average branching factor:              0.00
#
#   learning algorithm:                    grow-shrink
#   conditional independence test:         mutual information (discrete)
#   alpha threshold:                       0.05
#   tests used in the learning procedure:  41
#   optimized:                             TRUE
#

[Package bnlearn version 1.7 Index]