##################################################
## Using Gaussian Data
##################################################
## Load predefined data
data(gmG)
n <- nrow (gmG8$x)
V <- colnames(gmG8$x)
## define independence test (partial correlations), and test level
indepTest <- gaussCItest
alpha <- 0.01
## define sufficient statistics
suffStat <- list(C = cor(gmG8$x), n = n)
## estimate CPDAG
pc.fit <- pc(suffStat, indepTest, alpha=alpha, labels = V, verbose = TRUE)
if (require(Rgraphviz)) {
## show estimated CPDAG
par(mfrow=c(1,2))
plot(pc.fit, main = "Estimated CPDAG")
plot(gmG8$g, main = "True DAG")
}
a <- 6
b <- 1
c <- 8
checkTriple(a, b, c,
nbrsA = c(1,5,7),
nbrsC = c(1,5),
sepsetA = pc.fit@sepset[[a]][[c]],
sepsetC = pc.fit@sepset[[c]][[a]],
suffStat=suffStat, indepTest=indepTest, alpha=alpha,
version.unf = c(2,2),
verbose = TRUE) -> ct
str(ct)
## List of 4
## $ decision: int 2
## $ version : int 1
## $ SepsetA : int [1:2] 1 5
## $ SepsetC : int 1
stopifnot(identical( ct,
list(decision = 2L, version = 1L, SepsetA = c(1L, 5L), SepsetC = 1L)))
checkTriple(a, b, c,
nbrsA = c(1,5,7),
nbrsC = c(1,5),
sepsetA = pc.fit@sepset[[a]][[c]],
sepsetC = pc.fit@sepset[[c]][[a]],
version.unf = c(1,1),
suffStat=suffStat, indepTest=indepTest, alpha=alpha) -> c2
stopifnot(identical(ct, c2)) ## in this case, 'version.unf' had no effect
Run the code above in your browser using DataLab