Check both possible directed arcs for existence, and choose the one with the lowest p-value, the highest score or the highest bootstrap probability.
choose.direction(x, arc, data, criterion = NULL, ..., debug = FALSE)
choose.direction
returns invisibly an updated copy of x
.
an object of class bn
.
a character string vector of length 2, the labels of two nodes of the graph.
a data frame containing the data the Bayesian network was learned from.
a character string, the label of a score function, the label
of an independence test or bootstrap
. See
network scores
and independence tests
for
details on the first two possibilities.
additional tuning parameters for the network score. See
score
for details.
a boolean value. If TRUE
a lot of debugging output is
printed; otherwise the function is completely silent.
Marco Scutari
If criterion
is bootstrap
, choose.directions
accepts the
same arguments as boot.strength()
: R
(the number of bootstrap
replicates), m
(the bootstrap sample size), algorithm
(the
structure learning algorithm), algorithm.args
(the arguments to pass
to the structure learning algorithm) and cpdag
(whether to transform
the network structure to the CPDAG representation of the equivalence class it
belongs to).
If criterion
is a test or a score function, any node connected to one
of the nodes in arc
by an undirected arc is treated as a parent of
that node (with a warning).
score
, arc.strength
.
data(learning.test)
res = pc.stable(learning.test)
## the arc A - B has no direction.
choose.direction(res, learning.test, arc = c("A", "B"), debug = TRUE)
## let's see score equivalence in action.
choose.direction(res, learning.test, criterion = "aic",
arc = c("A", "B"), debug = TRUE)
## arcs which introduce cycles are handled correctly.
res = set.arc(res, "A", "B")
# now A -> B -> E -> A is a cycle.
choose.direction(res, learning.test, arc = c("E", "A"), debug = TRUE)
if (FALSE) {
choose.direction(res, learning.test, arc = c("D", "E"), criterion = "bootstrap",
R = 100, algorithm = "iamb", algorithm.args = list(test = "x2"), cpdag = TRUE,
debug = TRUE)
}
Run the code above in your browser using DataLab