Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

arcops

Drop, add or set the direction of an arc or an edge


Description

Drop, add or set the direction of a directed or undirected arc (also known as edge).

Usage

# arc operations.
set.arc(x, from, to, check.cycles = TRUE, check.illegal = TRUE, debug = FALSE)
drop.arc(x, from, to, debug = FALSE)
reverse.arc(x, from, to, check.cycles = TRUE, check.illegal = TRUE, debug = FALSE)

# edge (i.e. undirected arc) operations
set.edge(x, from, to, check.cycles = TRUE, check.illegal = TRUE, debug = FALSE)
drop.edge(x, from, to, debug = FALSE)

Arguments

x

an object of class bn.

from

a character string, the label of a node.

to

a character string, the label of another node.

check.cycles

a boolean value. If TRUE the graph is tested for acyclicity; otherwise the graph is returned anyway.

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.

debug

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

Details

The set.arc() function operates in the following way:

  • if there is no arc between from and to, the arc from -> to is added.

  • if there is an undirected arc between from and to, its direction is set to from -> to.

  • if the arc to -> from is present, it is reversed.

  • if the arc from -> to is present, no action is taken.

The drop.arc() function operates in the following way:

  • if there is no arc between from and to, no action is taken.

  • if there is a directed or an undirected arc between from and to, it is dropped regardless of its direction.

The reverse.arc() function operates in the following way:

  • if there is no arc between from and to, it returns an error.

  • if there is an undirected arc between from and to, it returns an error.

  • if the arc to -> from is present, it is reversed.

  • if the arc from -> to is present, it is reversed.

The set.edge() function operates in the following way:

  • if there is no arc between from and to, the undirected arc from - to is added.

  • if there is an undirected arc between from and to, no action is taken.

  • if either the arc from -> to or the arc to -> from are present, they are replaced with the undirected arc from - to.

The drop.edge() function operates in the following way:

  • if there is no undirected arc between from and to, no action is taken.

  • if there is an undirected arc between from and to, it is removed.

  • if there is a directed arc between from and to, no action is taken.

Value

All functions return invisibly an updated copy of x.

Author(s)

Marco Scutari

Examples

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

## use debug = TRUE to get more information.
set.arc(res, "A", "B")
drop.arc(res, "A", "B")
drop.edge(res, "A", "B")
reverse.arc(res, "A", "D")

bnlearn

Bayesian Network Structure Learning, Parameter Learning and Inference

v4.6.1
GPL (>= 2)
Authors
Marco Scutari [aut, cre], Robert Ness [ctb]
Initial release
2020-09-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.