cycletest {deal}R Documentation

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. This is used in autosearch

Usage

cycletest(nw)
findleaf (nw) 

Arguments

nw an object of class network

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.

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.

Author(s)

Susanne Gammelgaard Bøttcher alma@math.auc.dk,
Claus Dethlefsen dethlef@math.auc.dk.

References

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

See Also

networkfamily, drawnetwork, autosearch, perturb

Examples

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)

[Package Contents]