modelstring: Build a model string from a Bayesian network and vice versa

View source: R/frontend-formula.R

model string utilitiesR Documentation

Build a model string from a Bayesian network and vice versa

Description

Build a model string from a Bayesian network and vice versa.

Usage

modelstring(x)
modelstring(x, debug = FALSE) <- value

model2network(string, ordering = NULL, debug = FALSE)

## S3 method for class 'bn'
as.character(x, ...)
## S3 method for class 'character'
as.bn(x, ...)

Arguments

x

an object of class bn. modelstring() (but not its replacement form) accepts also objects of class bn.fit.

string

a character string describing the Bayesian network.

ordering

the labels of all the nodes in the graph; their order is the node ordering used in the construction of the bn object. If NULL the nodes are sorted alphabetically.

value

a character string, the same as the string.

debug

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

...

extra arguments from the generic method (currently ignored).

Details

The strings returned by modelstringi() have the same format as the ones returned by the modelstring() function in package deal; network structures may be easily exported to and imported from that package (via the model2network function).

The format of the model strings is as follows. The local structure of each node is enclosed in square brackets ("[]"); the first string is the label of that node. The parents of the node (if any) are listed after a ("|") and separated by colons (":"). All nodes (including isolated and root nodes) must be listed.

Value

model2network() and as.bn() return an object of class bn; modelstring() and as.character.bn() return a character string.

Author(s)

Marco Scutari

Examples

data(learning.test)
dag = hc(learning.test)
dag
modelstring(dag)
dag2 = model2network(modelstring(dag))
dag2
all.equal(dag, dag2)

bnlearn documentation built on Sept. 11, 2024, 8:27 p.m.