Interfacing with the pcalg R package

The pcalg package (link) is a versatile R package for structure learning. It implements both score-based algorithms such as the Greedy Equivalent Search (GES) and constraint-based algorithms such as the PC. It is one of the few R packages that can handle discrete data sets as well as cotinuous data sets.

Exporting a network structure to pcalg

Exporting bn or bn.fit objects to pcalg is not currently implemented in bnlearn.

Importing a network structure from pcalg

Importing network structures is implementeed in as.bn().

> library(pcalg)
> data("gmG")
> suffStat = list(C = cor(gmG8$x), n = nrow(gmG8$x))
> pc.gmG = pc(suffStat, indepTest = gaussCItest, p = ncol(gmG8$x), alpha = 0.01)
> library(bnlearn)
> as.bn(pc.gmG)

  Random/Generated Bayesian network

  model:
    [partially directed graph]
  nodes:                                 8 
  arcs:                                  8 
    undirected arcs:                     2 
    directed arcs:                       6 
  average markov blanket size:           2.25 
  average neighbourhood size:            2.00 
  average branching factor:              0.75 

  generation algorithm:                  Empty

Importing fitted Bayesian networks into bn.fit objects is not supported. Note that as graphs are imported with as.bn() they are checked to be acyclic, unless the user specifies check.cycles = FALSE.

Last updated on Mon Feb 17 17:41:12 2020 with bnlearn 4.6-20190124 and R version 3.6.2 (2019-12-12).