## Simulate the true DAG
set.seed(123)
p <- 7
myDAG <- randomDAG(p, prob = 0.2) ## true DAG
myCPDAG <- dag2cpdag(myDAG) ## true CPDAG
covTrue <- trueCov(myDAG) ## true covariance matrix
## simulate data from the true DAG
n <- 10000
dat <- rmvDAG(n, myDAG)
## estimate CPDAG (see help on the function "pc")
alpha <- 0.01
indepTest <- gaussCItest
suffStat <- list(C = cor(dat), n = n)
pc.fit <- pc(suffStat, indepTest, p, alpha)
if(require(Rgraphviz))
plot(myDAG)
(eff.est1 <- ida(2,5,cov(dat),pc.fit@graph,method="local",verbose=FALSE))
(eff.est2 <- ida(2,6,cov(dat),pc.fit@graph,method="local",verbose=FALSE))
(eff.est3 <- ida(2,7,cov(dat),pc.fit@graph,method="local",verbose=FALSE))
## These three computations can be combinded in an efficient way
## by using idaFast :
(eff.estF <- idaFast(2,c(5,6,7),cov(dat),pc.fit@graph))
Run the code above in your browser using DataLab