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 continuous data sets.

Exporting a network structure to pcalg

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

Importing a network structure from pcalg

Importing network structures is implementeed in

> 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)

  Random/Generated Bayesian network

    [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 objects is not supported. Note that as graphs are imported with they are checked to be acyclic, unless the user specifies check.cycles = FALSE.

Last updated on Wed Nov 9 16:45:33 2022 with bnlearn 4.9-20221107 and R version 4.2.2 (2022-10-31).