Interfacing with the deal R package

The deal package (link) is one of the oldest R packages for structure and parameter learning; notably, it supports conditional linear Gaussian networks. It implements a single option for learning: hill climbing with a posterior score followed by posterior estimates of the parameters.

Exporting a network structure to deal

It is possible to export a network structure learned from data to deal; since deal does not have separate classes for network structures and fitted networks (e.g. like bn vs objects in bnlearn), it is not possible to export a network structure that does not have an associated data set, such as one created with modelstring(). Furthermore, deal does not support partially directed graphs, so the network structure must be completely directed.

Since the two packages use the same model string representation, that is the easiest way of exporting the network structure. Both packages have functions called modelstring() that take network models and return their string representation; and in deal does the opposite, much like model2network() in bnlearn.

> library(bnlearn)
Loading required package: methods
> data(learning.test)
> res = hc(learning.test)
> modelstring(res)
[1] "[A][C][F][B|A][D|A:C][E|B:F]"
> library(deal)

Attaching package: 'deal'

The following objects are masked from 'package:bnlearn':

    modelstring, nodes, nodes<-, score
> bnlearn::node.ordering(res)
[1] "A" "C" "F" "B" "D" "E"
> net = deal::network(learning.test[, node.ordering(res)])
> net =, net)
> 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]"

Note that deal requires the columns of the data set to follow the topological ordering of the nodes in the graph.

Importing a network structure from deal

The same technique can be used to import a network structure from deal.

> res2 = bnlearn::model2network(deal::modelstring(net))
Last updated on Tue Nov 14 15:44:59 2017 with bnlearn 4.3-20171001 and R version 3.0.2 (2013-09-25).