1

There's documentation here (https://www.rdocumentation.org/packages/pcalg/versions/2.7-3/topics/pc) on how to run the pc algorithm for binary data.

library(pcalg)
##################################################
## Using discrete data
##################################################
## Load data
data(gmD)
V <- colnames(gmD$x)
## define sufficient statistics
suffStat <- list(dm = gmD$x, nlev = c(3,2,3,4,2), adaptDF = FALSE)
## estimate CPDAG
pc.D <- pc(suffStat,
           ## independence test: G^2 statistic
           indepTest = disCItest, alpha = 0.01, labels = V, verbose = TRUE)
if (require(Rgraphviz)) {
  ## show estimated CPDAG
  par(mfrow = c(1,2))
  plot(pc.D, main = "Estimated CPDAG")
  plot(gmD$g, main = "True DAG")
}

I'm wondering if there's anyway I can use the pc.D object to visualize this in ggdag (https://cran.r-project.org/web/packages/ggdag/vignettes/intro-to-ggdag.html).

Is there a way?

Eisen
  • 1,697
  • 9
  • 27
  • It looks like [ggdag](https://cran.r-project.org/web/packages/ggdag/) uses `igraph` for its graph tools. So you could convert your graph to an `igraph` object. – user20650 Sep 01 '21 at 16:26
  • ... quick look is you can get the adjacency matrix with `as(pc.D@graph, "matrix")`. You can then use what ever graph software you want to create the graph. EDIT:: or form `igraph` object directly with `igraph::graph_from_graphnel(pc.D@graph)` – user20650 Sep 01 '21 at 16:31
  • `ggdag()` takes in a daggity object. is there any way to convert `pc.D` to daggity object? – Eisen Sep 02 '21 at 15:38

0 Answers0