bnlearn (version 0.8)

choose.direction: Try to infer the direction of an undirected arc

Description

Check both possible directed arcs for existence, and choose the one with the lowest p-value.

Usage

choose.direction(x, arc, data, criterion = NULL, ..., debug = FALSE)

Arguments

x
an object of class bn.
arc
a character string vector of length 2, the labels of two nodes of the graph.
data
a data frame, containing the data the Bayesian network was learned from.
criterion
the label of either a score or an independence test. See bnlearn-package for details.
...
additional tuning parameters for the network score. See score for details.
debug
a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Value

  • choose.direction returns invisibly an updated copy of x.

See Also

score, arc.strength.

Examples

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

## the arc A - B has no direction.
choose.direction(res, data = learning.test, arc = c("A", "B"), debug = TRUE)
# * testing A - B for direction.
#   > testing A -> B with conditioning set '  '.
#     > p-value is 0 .
#   > testing B -> A with conditioning set '  '.
#     > p-value is 0 .
#   @ nothing to do, same p-value.

## let's see score equivalence in action.
choose.direction(res, data = learning.test, criterion = "aic",
  arc = c("A", "B"), debug = TRUE)
# * testing A - B for direction.
#     > delta between scores for nodes A B is 1166.914 .
#     > delta between scores for nodes B A is 1166.914 .
#   > initial score for node A is -5495.051 .
#   > initial score for node B is -4834.284 .
#   > score delta for arc A -> B is 1166.914 .
#   > score delta for arc B -> A is 1166.914 .
#   @ nothing to do, same score delta.

## arcs which introduce cycles are handled correctly.
res = set.arc(res, "A", "B")
# now A -> B -> E -> A is a cycle.
choose.direction(res, data = learning.test, arc = c("E", "A"), debug = TRUE)
# * testing E - A for direction.
#   > testing E -> A with conditioning set '  '.
#     > p-value is 1.426725e-99 .
#   > testing A -> E with conditioning set ' B F '.
#     > p-value is 0.9818423 .
#   > adding E -> A creates cycles!.
#   > arc A -> E isn't good, either.

Run the code above in your browser using DataLab