Learn R Programming

deal (version 1.1-2)

cycletest: Test if network contains a cycle

Description

The graph in a Bayesian network must be a directed acyclic graph. The procedure cycletest returns TRUE or FALSE if it is cyclic or not.

Usage

cycletest(nw)
findleaf (nw)

Arguments

nw
The network to test if it contains a cycle.

Value

  • cycletest returns TRUE if nw contains a cycle, FALSE if not. findleaf returns an index of a leaf, or 0 if no leaf is found.

Details

First, cycletest uses findleaf to find a node without parents (called a leaf). Then, this node is deleted from the graph. If this process can be repeated until all nodes have been deleted, no cycle is present in the graph. The procedure findleaf returns the index of the first found leaf. If no leaf is found, 0 is returned.

References

Further information about Deal can be found at: http://www.math.auc.dk/novo/deal.

See Also

networkfamily, drawnetwork, autosearch, perturb

Examples

Run this code
data(rats)

# make Sex numeric so that a cycle is possible
rats$Sex <- as.numeric(rats$Sex)

# define network and prior and learn
nw <- network(rats)
nw.prior <- jointprior(nw,12)
nw <- learn(nw,rats,nw.prior)$nw

# insert a cycle
nw <- insert(nw,1,3,rats,nw.prior)$nw
nw <- insert(nw,3,4,rats,nw.prior)$nw
nw <- insert(nw,4,1,rats,nw.prior)$nw

cycletest(nw)

Run the code above in your browser using DataLab