## 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
if (require(Rgraphviz)) {
## 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
}
Run the code above in your browser using DataLab