pcalg (version 2.5-0)

dag2cpdag: Convert a DAG to a CPDAG

Description

Convert a DAG (Directed Acyclic Graph) to a Completed Partially Directed Acyclic Graph (CPDAG).

Usage

dag2cpdag(g)

Arguments

g

an R object of class "graph" (package graph), representing a DAG.

Value

A graph object containing the CPDAG.

Details

This function converts a DAG into its corresponding (unique) CPDAG as follows. Because every DAG in the Markov equivalence class described by a CPDAG shares the same skeleton and the same v-structures, this function takes the skeleton and the v-structures of the given DAG g. Afterwards it simply uses the 3 orientation rules of the PC algorithm (see references) to orient as many of the remaining undirected edges as possible.

The function is a simple wrapper function for dag2essgraph which is more powerfull since it also allows the calculation of the Markov equivalence class in the presence of interventional data.

The output of this function is exactly the same as the one using

pc(suffStat, indepTest, alpha, labels)

using the true correlation matrix in the function gaussCItest with a large virtual sample size and a large alpha, but it is much faster.

References

C. Meek (1995). Causal inference and causal explanation with background knowledge. In Proceedings of the Eleventh Conference on Uncertainty in Artificial Intelligence (UAI-95), pp. 403-411. Morgan Kaufmann Publishers, Inc.

P. Spirtes, C. Glymour and R. Scheines (2000) Causation, Prediction, and Search, 2nd edition, The MIT Press.

See Also

dag2essgraph, randomDAG, pc

Examples

Run this code
# NOT RUN {
p <- 10  ## number of random variables
s <- 0.4 ## sparseness of the graph

## generate a random DAG
set.seed(42)
g <- randomDAG(p, s)
g01 <- 1*(as(g,"matrix") > 0) # 0/1-version of adjacency matrix
print.table(g01, zero.=".")

## compute its unique CPDAG
system.time(
  res <- dag2cpdag(g)
)
## res has some bidirected edges
##  ==> adj.matrix: no longer upper triangular, but {0,1}
print.table(as(res, "matrix"), zero.=".")
dm <- as(res, "matrix") - g01 ## difference: 2 entries in lower tri.
print.table(dm, zero.=".")
stopifnot(all(dm %in% 0:1), sum(dm == 1) == 2)

## Find CPDAG with PC algorithm:
## As dependence oracle, we use the true correlation matrix in
## gaussCItest() with a large "virtual sample size" and a large alpha:
system.time(
rpc <- pc(suffStat = list(C = cov2cor(trueCov(g)), n = 10^9),
          indepTest = gaussCItest, alpha = 0.9999, p = p)
)
## confirm that it coincides with dag2cpdag()'s result:
stopifnot(all.equal(as( res,     "matrix"),
                    as(rpc@graph,"matrix"), tol=0))
# }

Run the code above in your browser using DataCamp Workspace