pdag2allDags | R Documentation |
pdag2allDags
computes all DAGs in the Markov Equivalence Class
Represented by a Given Partially Directed Acyclic Graph (PDAG).
pdag2allDags(gm, verbose = FALSE)
gm |
adjacency matrix of type amat.cpdag |
verbose |
logical; if true, some output is produced during computation |
All DAGs extending the given PDAG are computing while avoiding new
v-structures and cycles. If no DAG is found, the function returns NULL
.
List with two elements:
dags: |
Matrix; every row corresponds to a DAG; every column
corresponds to an entry in the adjacency matrix of this DAG. Thus, the
adjacency matrix (of type amat.cpdag) contained in the i-th row
of matrix |
nodeNms |
Node labels of the input PDAG. |
Markus Kalisch (kalisch@stat.math.ethz.ch)
## Example 1
gm <- rbind(c(0,1),
c(1,0))
colnames(gm) <- rownames(gm) <- LETTERS[1:2]
res1 <- pdag2allDags(gm)
## adjacency matrix of first DAG in output
amat1 <- matrix(res1$dags[1,],2,2, byrow = TRUE)
colnames(amat1) <- rownames(amat1) <- res1$nodeNms
amat1 ## A --> B
## Example 2
gm <- rbind(c(0,1,1),
c(1,0,1),
c(1,1,0))
colnames(gm) <- rownames(gm) <- LETTERS[1:ncol(gm)]
res2 <- pdag2allDags(gm)
## adjacency matrix of first DAG in output
amat2 <- matrix(res2$dags[1,],3,3, byrow = TRUE)
colnames(amat2) <- rownames(amat2) <- res2$nodeNms
amat2
## Example 3
gm <- rbind(c(0,1,1,0,0),
c(1,0,0,0,0),
c(1,0,0,0,0),
c(0,1,1,0,1),
c(0,0,0,1,0))
colnames(gm) <- rownames(gm) <- LETTERS[1:ncol(gm)]
res3 <- pdag2allDags(gm)
## adjacency matrix of first DAG in output
amat3 <- matrix(res3$dags[1,],5,5, byrow = TRUE)
colnames(amat3) <- rownames(amat3) <- res3$nodeNms
amat3
## for convenience a simple plotting function
## for the function output
plotAllDags <- function(res) {
require(graph)
p <- sqrt(ncol(res$dags))
nDags <- ceiling(sqrt(nrow(res$dags)))
par(mfrow = c(nDags, nDags))
for (i in 1:nrow(res$dags)) {
tmp <- matrix(res$dags[i,],p,p)
colnames(tmp) <- rownames(tmp) <- res$nodeNms
plot(as(tmp, "graphNEL"))
}
}
plotAllDags(res1)
amat1 ## adj.matrix corresponding to the first plot for expl 1
plotAllDags(res2)
amat2 ## adj.matrix corresponding to the first plot for expl 2
plotAllDags(res3)
amat3 ## adj.matrix corresponding to the first plot for expl 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.