Description Export a bn object to deal Import a network structure from deal Author(s)
How to use the bnlearn package with the Bayesian network learning methods provided by the deal package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # load the bnlearn package.
> library(bnlearn)
> data(learning.test)
# learn the network structure.
> res = hc(learning.test)
> modelstring(res)
[1] "[A][C][F][B|A][D|A:C][E|B:F]"
# load the deal package.
> library(deal)
Attaching package: 'deal'
The following object(s) are masked from package:bnlearn :
modelstring,
nodes,
score
> bnlearn::node.ordering(res)
[1] "A" "C" "F" "B" "D" "E"
# create an empty network object.
> net = deal::network(learning.test[, node.ordering(res)])
# convert the bn object via its string representation.
> net = deal::as.network(bnlearn::modelstring(res), net)
# the network is the same, modulo some differences due to the
# partial ordering of the nodes.
> deal::modelstring(net)
[1] "[A][C][F][B|A][D|A:C][E|F:B]"
> bnlearn::modelstring(res)
[1] "[A][C][F][B|A][D|A:C][E|B:F]"
|
1 | res2 = bnlearn::model2network(deal::modelstring(net))
|
Marco Scutari
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.