Load the following libraries and install the package:
suppressPackageStartupMessages(library(doParallel))
suppressPackageStartupMessages(library(foreach))
suppressPackageStartupMessages(library(devtools))
install_github("jie108/dagbagM/dagbagM")
install_github("jie108/dagbagM/dagbag")
suppressPackageStartupMessages(library(dagbagM))
suppressPackageStartupMessages(library(dagbag))
Usage of the functions in DAGBagM
DAG with no bootstrap resample
hc: A function to learn a DAG model for the given data with **no bootstrap resamples** by the hill climbing algorithm for mixture of continuous and binary variables
dagbagM::hc(Y,nodeType, whiteList, blackList, tol, standardize, maxStep, restart, seed, verbose)
Run the following code
load("example.RData")
p<- dim(Y.n)[2] # no. of nodes
temp<- dagbagM::hc(Y=Y.n,nodeType=rep("c",p), whiteList=NULL, blackList=NULL, tol = 1e-6, standardize=TRUE, maxStep = 1000, restart=10, seed = 1, verbose = FALSE)
temp$adjacency
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE
## [6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
## [7,] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE
## [9,] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [10,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [11,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [12,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
temp$score
## [1] 282.7827 282.7827 191.7903 282.7827 143.3540 120.5393 282.7827 282.7827
## [9] 189.8682 280.6681 279.2147 208.0618
DAG for n bootstrap resamples
hc_boot_parallel: A function to learn a DAG model for bootstrap resmples of the given data by the hill climbing algorithm for mixture of continuous and binary variables
dagbagM::hc_boot_parallel(Y, node.type, n.boot, whiteList, blackList, maxStep, standardize, tol, restart, seed, nodeShuffle, numThread, verbose)
Run the following code
temp.boot<- dagbagM::hc_boot_parallel(Y=Y.n, n.boot=10, nodeType=rep("c",p), whiteList=NULL, blackList=NULL, standardize=TRUE, tol = 1e-6, maxStep = 1000, restart=10, seed = 1, nodeShuffle=TRUE, numThread = 2,verbose = FALSE)
temp.boot[,,1:3]
## , , 1
##
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] 0 0 0 0 0 0 0 0 0 0 0 0
## [2,] 1 0 0 0 0 0 0 0 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0 0 0
## [4,] 1 0 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 0 1 0 1 0
## [6,] 0 0 0 0 0 0 0 1 0 0 0 1
## [7,] 0 0 1 1 0 1 0 1 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 0 0 0 0
## [9,] 1 0 1 0 0 1 0 0 0 0 1 0
## [10,] 0 0 0 0 1 0 0 1 0 0 0 0
## [11,] 0 0 0 0 0 0 0 0 0 0 0 0
## [12,] 0 0 0 0 0 0 0 1 0 0 1 0
##
## , , 2
##
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] 0 0 1 0 0 0 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0 0 0 0 0 0 0
## [3,] 0 1 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 1 0 0 0 0 1 0 0 1
## [6,] 0 0 0 0 0 0 0 0 0 0 0 1
## [7,] 0 0 1 0 1 1 0 0 0 0 0 0
## [8,] 0 1 1 0 0 0 0 0 0 0 0 0
## [9,] 0 0 1 0 0 1 0 0 0 0 0 0
## [10,] 0 0 0 0 1 0 0 0 0 0 0 0
## [11,] 0 0 0 0 0 0 0 1 0 0 0 0
## [12,] 0 0 0 0 0 0 0 0 0 0 1 0
##
## , , 3
##
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] 0 0 0 1 0 1 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0 0 0 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 0 1 1 0 0
## [6,] 0 0 0 0 0 0 0 0 0 0 0 1
## [7,] 0 0 1 0 0 1 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 0 0 0 0
## [9,] 0 0 1 0 0 1 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 1 0 0 0 0
## [11,] 0 0 0 1 0 0 0 0 0 0 0 0
## [12,] 0 0 1 0 0 0 0 0 0 0 1 0
Bootstrap aggregation using score_shd in dagbag
score_shd: A function to use structural hamming distance to aggregate DAGs. It aggregates an ensemble of DAGs to obtain a DAG that minimizes the overall distance to the ensemble.
Run the following code
res.agg<- dagbag::score_shd(temp.boot, alpha=1, threshold=0.5)
res.agg$adj.matrix
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] 0 0 0 0 0 0 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0 0 1 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0 0 0
## [4,] 1 0 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 0 1 0 0 1
## [6,] 1 0 1 0 0 0 0 0 0 0 0 1
## [7,] 0 0 1 1 0 1 0 0 0 0 0 0
## [8,] 0 0 1 0 0 0 0 0 0 0 0 0
## [9,] 0 0 1 0 0 1 0 0 0 0 0 0
## [10,] 0 0 1 0 1 0 0 1 0 0 0 0
## [11,] 0 0 0 0 0 0 0 0 0 0 0 0
## [12,] 0 0 0 0 0 0 0 0 0 0 1 0
cor.test(Y.n[,7], Y.n[,9])
##
## Pearson's product-moment correlation
##
## data: Y.n[, 7] and Y.n[, 9]
## t = -1.1114, df = 98, p-value = 0.2691
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.30138490 0.08674763
## sample estimates:
## cor
## -0.1115715
#plot(Y.n[,7], Y.n[,9])
m<- median(Y.n[,6])
cor.test(Y.n[Y.n[,6] < m,7], Y.n[Y.n[,6] < m,9])
##
## Pearson's product-moment correlation
##
## data: Y.n[Y.n[, 6] < m, 7] and Y.n[Y.n[, 6] < m, 9]
## t = -3.9612, df = 48, p-value = 0.0002464
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.6806569 -0.2529451
## sample estimates:
## cor
## -0.4963467
#plot(Y.n[Y.n[,6] < m,7], Y.n[Y.n[,6] < m,9])
#boxplot(Y.n[,6] ~ Y.n[,12])