Learn R Programming

bnlearn (version 0.3)

mb: Utility functions to manipulate graphs

Description

Extract various quantities of interest from an object of class bn.

Usage

mb(x, node)
  nbr(x, node)
  arcs(x)
  nodes(x)
  amat(x)
  parents(x, node)

Arguments

x
an object of class "bn".
node
a character string, the label of a node.

Value

  • mb, nbr, nodes and parents return an array of character strings. arcs returns a matrix of two columns of character strings. amat returns a matrix of 0/1 numeric values.

Examples

Run this code
data(learning.test)
res = gs(learning.test)

# the Markov blanket of A.
mb(res, "A")
# [1] "B" "D" "C"
# the neighbourhood of F.
nbr(res, "F")
# [1] "B" "E"
# the arcs in the graph.
arcs(res)
#      from to 
# [1,] "A"  "D"
# [2,] "B"  "A"
# [3,] "C"  "D"
# [4,] "E"  "B"
# [5,] "E"  "F"
# [6,] "F"  "B"
# [7,] "F"  "E"
# the nodes of the graph.
nodes(res)
# [1] "A" "B" "C" "D" "E" "F"
# the adjacency matrix for the nodes of the graph.
amat(res)
# A 0 0 0 1 0 0
# B 1 0 0 0 0 0
# C 0 0 0 1 0 0
# D 0 0 0 0 0 0
# E 0 1 0 0 0 1
# F 0 1 0 0 1 0
# the parents of D.
parents(res, "D")
# [1] "A" "C"

Run the code above in your browser using DataLab