##############################
## Global
##############################
set.seed(125)
p <- 10
n <- 100000
myDAG <- randomDAG(p, prob = 0.4)
plot(dag2cpdag(myDAG))
cmat <- cov2cor(trueCov(myDAG))
d.mat <- rmvDAG(n, myDAG, errDist = "normal")
x.pos <- 1
y.pos <- 5
## true value
true.eff <- causalEffect(myDAG,y.pos,x.pos)
## value using oracle (true value should be element of this)
est.eff.p <- beta.special(x.pos=x.pos,y.pos=y.pos,myDAG=myDAG,perfect=TRUE,method="global")
## value using data (true value should come close to some element of this)
est.eff.e <- beta.special(dat=d.mat,x.pos=x.pos,y.pos=y.pos,perfect=FALSE,method="global",myplot=TRUE)
true.eff
est.eff.p
est.eff.e
## Setting perfect&global always contains exact value of true value
## OK
##############################
## Local
##############################
set.seed(125)
p <- 10
n <- 100000
myDAG <- randomDAG(p, prob = 0.4)
cmat <- cov2cor(trueCov(myDAG))
d.mat <- rmvDAG(n, myDAG, errDist = "normal")
x.pos <- 1
y.pos <- 5
## true value
true.eff <- causalEffect(myDAG,y.pos,x.pos)
## value using oracle (true value should be element of this)
est.eff.p <- beta.special(x.pos=x.pos,y.pos=y.pos,myDAG=myDAG,perfect=TRUE,method="local")
## value using data (true value should come close to some element of this)
est.eff.e <- beta.special(dat=d.mat,x.pos=x.pos,y.pos=y.pos,perfect=FALSE,method="local")
plot(pcAlgo(d.mat,alpha=0.01,directed=TRUE))
true.eff
est.eff.p
est.eff.e
Run the code above in your browser using DataLab