bdgraph, bdgraph.mpl, bdgraph.dw, bdgraph.sim, compare, rgwish
# Generating multivariate normal data from a 'scale-free' graph
data.sim <- bdgraph.sim( n = 100, p = 10, graph = "scale-free", vis = TRUE )
# Running algorithm based on GGMs
bdgraph.obj <- bdgraph( data = data.sim, iter = 5000 )
## 5000 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
summary( bdgraph.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 1 0 0 0 0 1 1 0 0
## [2,] 0 0 0 0 0 1 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 0 0 0
## [6,] 0 0 0 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 0 1
## [9,] 0 0 0 0 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 1 0.04 0.03 0.03 0.02 0.67 1.00 0.03 0.47
## [2,] 0 0 0.03 0.07 0.03 1.00 0.04 0.05 0.03 0.03
## [3,] 0 0 0.00 0.02 0.04 0.02 0.01 0.03 0.03 0.03
## [4,] 0 0 0.00 0.00 0.02 0.04 0.03 0.03 0.07 0.02
## [5,] 0 0 0.00 0.00 0.00 0.02 0.01 0.04 0.06 0.02
## [6,] 0 0 0.00 0.00 0.00 0.00 0.03 0.03 0.02 0.02
## [7,] 0 0 0.00 0.00 0.00 0.00 0.00 0.03 0.08 0.02
## [8,] 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.03 0.51
## [9,] 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.02
## [10,] 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
##
## $K_hat
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 3.44 -1.37 0.00 0.00 0.00 0.00 0.24 -1.16 0.00 0.22
## [2,] -1.37 3.39 0.00 0.01 0.00 -1.98 -0.01 0.01 0.00 -0.01
## [3,] 0.00 0.00 1.51 0.00 -0.01 0.00 0.00 0.00 0.00 0.00
## [4,] 0.00 0.01 0.00 1.08 0.00 0.01 0.00 0.00 -0.01 0.00
## [5,] 0.00 0.00 -0.01 0.00 0.83 0.00 0.00 0.00 -0.01 0.00
## [6,] 0.00 -1.98 0.00 0.01 0.00 2.44 0.00 0.00 0.00 0.00
## [7,] 0.24 -0.01 0.00 0.00 0.00 0.00 0.93 0.00 -0.01 0.00
## [8,] -1.16 0.01 0.00 0.00 0.00 0.00 0.00 1.78 0.00 0.21
## [9,] 0.00 0.00 0.00 -0.01 -0.01 0.00 -0.01 0.00 0.99 0.00
## [10,] 0.22 -0.01 0.00 0.00 0.00 0.00 0.00 0.21 0.00 1.41
# To compare the result with true graph
compare( bdgraph.obj, data.sim, main = c( "Target", "BDgraph" ), vis = TRUE )
## Target BDgraph
## True Positive 9 4.000
## True Negative 36 35.000
## False Positive 0 1.000
## False Negative 0 5.000
## F1-score 1 0.571
## Specificity 1 0.972
## Sensitivity 1 0.444
## MCC 1 0.530
# Confusion Matrix
conf.mat( actual = data.sim, pred = bdgraph.obj )
## Actual
## Prediction 0 1
## 0 35 5
## 1 1 4
conf.mat.plot( actual = data.sim, pred = bdgraph.obj )
# Running algorithm based on GGMs and marginal pseudo-likelihood
bdgraph.mpl.obj <- bdgraph.mpl( data = data.sim, iter = 5000 )
## 5000 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
summary( bdgraph.mpl.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 1 0 0 0 0 1 1 0 1
## [2,] 0 0 0 0 0 1 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 0 0 0
## [6,] 0 0 0 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 0 0
## [9,] 0 0 0 0 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 1 0 0.00 0.01 0.00 0.96 1.00 0.00 0.67
## [2,] 0 0 0 0.02 0.02 1.00 0.02 0.00 0.00 0.02
## [3,] 0 0 0 0.00 0.02 0.01 0.00 0.00 0.01 0.00
## [4,] 0 0 0 0.00 0.00 0.01 0.01 0.00 0.04 0.00
## [5,] 0 0 0 0.00 0.00 0.01 0.00 0.02 0.09 0.00
## [6,] 0 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
## [7,] 0 0 0 0.00 0.00 0.00 0.00 0.00 0.06 0.00
## [8,] 0 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.24
## [9,] 0 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
## [10,] 0 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
# Confusion Matrix
conf.mat( actual = data.sim, pred = bdgraph.mpl.obj )
## Actual
## Prediction 0 1
## 0 36 4
## 1 0 5
conf.mat.plot( actual = data.sim, pred = bdgraph.mpl.obj )
# To compare the results of both algorithms with true graph
compare( list( bdgraph.obj, bdgraph.mpl.obj ), data.sim,
main = c( "Target", "BDgraph", "BDgraph_mpl" ), vis = TRUE )
## Target BDgraph BDgraph_mpl
## True Positive 9 4.000 5.000
## True Negative 36 35.000 36.000
## False Positive 0 1.000 0.000
## False Negative 0 5.000 4.000
## F1-score 1 0.571 0.714
## Specificity 1 0.972 1.000
## Sensitivity 1 0.444 0.556
## MCC 1 0.530 0.707
## End(Not run)
# Generating a 'random' graph
adj <- graph.sim( p = 6, vis = TRUE )
adj2link( adj )
## [,1] [,2]
## [1,] 1 2
## [2,] 1 6
## [3,] 2 1
## [4,] 3 4
## [5,] 4 3
## [6,] 6 1
set.seed( 5 )
# Generating multivariate normal data from a 'scale-free' graph
data.sim = bdgraph.sim( n = 200, p = 15, graph = "scale-free", vis = TRUE )
# Running BDMCMC algorithm
sample.bdmcmc = bdgraph( data = data.sim, algorithm = "bdmcmc", iter = 10000 )
## 10000 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
BDgraph::auc( pred = sample.bdmcmc, actual = data.sim, calibrate = TRUE )
## [1] 0.8519219
set.seed( 10 )
# - - Example 1
# Generating multivariate normal data from a 'random' graph
data.sim <- bdgraph.sim( n = 100, p = 10, size = 15, vis = TRUE )
bdgraph.obj <- bdgraph( data = data.sim, iter = 1000, save = TRUE )
## 1000 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
summary( bdgraph.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 0 0 0 1 0 0 0 0 1
## [2,] 0 0 0 0 1 0 0 0 0 0
## [3,] 0 0 0 0 1 0 0 1 1 1
## [4,] 0 0 0 0 0 0 1 0 0 0
## [5,] 0 0 0 0 0 1 0 0 0 0
## [6,] 0 0 0 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0 0 0 1
## [8,] 0 0 0 0 0 0 0 0 0 0
## [9,] 0 0 0 0 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 0.01 0.02 0.02 1.00 0.02 0.05 0.02 0.14 1.00
## [2,] 0 0.00 0.03 0.05 0.98 0.14 0.05 0.01 0.01 0.00
## [3,] 0 0.00 0.00 0.04 1.00 0.24 0.02 0.80 1.00 1.00
## [4,] 0 0.00 0.00 0.00 0.03 0.08 1.00 0.10 0.06 0.03
## [5,] 0 0.00 0.00 0.00 0.00 0.62 0.06 0.01 0.08 0.06
## [6,] 0 0.00 0.00 0.00 0.00 0.00 0.02 0.11 0.09 0.07
## [7,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.11 0.21 1.00
## [8,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.03 0.29
## [9,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.04
## [10,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
##
## $K_hat
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 3.06 0.00 0.00 0.00 -1.07 0.00 0.00 0.00 0.06 -1.86
## [2,] 0.00 1.32 -0.01 0.01 -0.55 -0.04 -0.01 0.00 0.00 0.00
## [3,] 0.00 -0.01 3.99 0.00 -1.08 -0.11 0.00 0.44 1.80 -1.23
## [4,] 0.00 0.01 0.00 2.60 0.00 0.01 2.09 0.02 -0.01 0.00
## [5,] -1.07 -0.55 -1.08 0.00 3.02 0.31 0.02 0.00 0.03 -0.04
## [6,] 0.00 -0.04 -0.11 0.01 0.31 1.41 0.00 0.03 0.02 -0.01
## [7,] 0.00 -0.01 0.00 2.09 0.02 0.00 4.49 -0.03 -0.08 2.00
## [8,] 0.00 0.00 0.44 0.02 0.00 0.03 -0.03 1.24 0.00 0.15
## [9,] 0.06 0.00 1.80 -0.01 0.03 0.02 -0.08 0.00 2.40 0.02
## [10,] -1.86 0.00 -1.23 0.00 -0.04 -0.01 2.00 0.15 0.02 5.32
# Confusion Matrix
#conf.mat( actual = data.sim, pred = bdgraph.obj )
#conf.mat.plot( actual = data.sim, pred = bdgraph.obj )
# To compare our result with true graph
compare( bdgraph.obj, data.sim, main = c( "Target", "BDgraph" ), vis = T )
## Target BDgraph
## True Positive 15 10.000
## True Negative 30 30.000
## False Positive 0 0.000
## False Negative 0 5.000
## F1-score 1 0.800
## Specificity 1 1.000
## Sensitivity 1 0.667
## MCC 1 0.756
# Running algorithm with starting points from previous run
bdgraph.obj2 <- bdgraph( data = data.sim, g.start = bdgraph.obj )
## 5000 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
compare( list( bdgraph.obj, bdgraph.obj2 ), data.sim,
main = c( "Target", "Frist run", "Second run" ) )
## Target Frist run Second run
## True Positive 15 10.000 10.000
## True Negative 30 30.000 30.000
## False Positive 0 0.000 0.000
## False Negative 0 5.000 5.000
## F1-score 1 0.800 0.800
## Specificity 1 1.000 1.000
## Sensitivity 1 0.667 0.667
## MCC 1 0.756 0.756
# - - Example 2
# Generating mixed data from a 'scale-free' graph
data.sim <- bdgraph.sim( n = 200, p = 7, type = "mixed", graph = "scale-free", vis = TRUE )
bdgraph.obj <- bdgraph( data = data.sim, method = "gcgm" )
## 5000 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
summary( bdgraph.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 0 1 0 1 1 0 0
## [2,] 0 0 1 0 0 0 1
## [3,] 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0
## [6,] 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 0 1 0.05 1.00 1.00 0.06 0.02
## [2,] 0 0 1.00 0.05 0.02 0.20 1.00
## [3,] 0 0 0.00 0.03 0.02 0.07 0.49
## [4,] 0 0 0.00 0.00 0.02 0.04 0.03
## [5,] 0 0 0.00 0.00 0.00 0.04 0.02
## [6,] 0 0 0.00 0.00 0.00 0.00 0.03
## [7,] 0 0 0.00 0.00 0.00 0.00 0.00
##
## $K_hat
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 5.51 1.63 -0.01 2.02 -1.57 -0.01 0.00
## [2,] 1.63 5.74 1.20 0.02 0.00 0.06 -1.47
## [3,] -0.01 1.20 1.62 0.00 0.00 -0.01 0.18
## [4,] 2.02 0.02 0.00 3.47 0.00 0.01 0.00
## [5,] -1.57 0.00 0.00 0.00 1.81 0.00 0.00
## [6,] -0.01 0.06 -0.01 0.01 0.00 1.03 -0.01
## [7,] 0.00 -1.47 0.18 0.00 0.00 -0.01 1.79
compare( bdgraph.obj, data.sim, vis = T )
## Actual pred 1
## True Positive 6 5.000
## True Negative 15 15.000
## False Positive 0 0.000
## False Negative 0 1.000
## F1-score 1 0.909
## Specificity 1 1.000
## Sensitivity 1 0.833
## MCC 1 0.884
conf.mat( actual = data.sim, pred = bdgraph.obj )
## Actual
## Prediction 0 1
## 0 15 1
## 1 0 5
conf.mat.plot( actual = data.sim, pred = bdgraph.obj )
# - - Example 1
# Generating multivariate Discrete Weibull data based on 'random' graph
data.sim <- bdgraph.sim( n = 100, p = 10, type = "dw", vis = TRUE )
summary( bdgraph.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 0 0 0 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 1 0
## [5,] 0 0 0 0 0 0 0 0 0 1
## [6,] 0 0 0 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 1 0
## [9,] 0 0 0 0 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 0.23 0.11 0.03 0.03 0.08 0.04 0.04 0.03 0.05
## [2,] 0 0.00 0.05 0.04 0.07 0.05 0.05 0.03 0.02 0.05
## [3,] 0 0.00 0.00 0.02 0.02 0.02 0.40 0.03 0.03 0.03
## [4,] 0 0.00 0.00 0.00 0.05 0.05 0.10 0.04 0.90 0.05
## [5,] 0 0.00 0.00 0.00 0.00 0.03 0.04 0.03 0.02 1.00
## [6,] 0 0.00 0.00 0.00 0.00 0.00 0.04 0.04 0.04 0.02
## [7,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.25 0.02 0.05
## [8,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.97 0.03
## [9,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.05
## [10,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
##
## $K_hat
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1.13 -0.09 0.03 0.00 0.00 -0.02 -0.01 0.01 0.00 -0.01
## [2,] -0.09 1.08 -0.01 0.01 -0.02 0.01 -0.01 0.00 0.00 0.00
## [3,] 0.03 -0.01 1.17 0.00 0.00 0.00 0.20 0.00 0.00 0.00
## [4,] 0.00 0.01 0.00 1.37 0.01 0.01 0.03 0.00 0.64 -0.01
## [5,] 0.00 -0.02 0.00 0.01 2.37 0.00 0.00 0.00 0.00 1.80
## [6,] -0.02 0.01 0.00 0.01 0.00 1.07 -0.01 0.01 -0.01 0.00
## [7,] -0.01 -0.01 0.20 0.03 0.00 -0.01 1.22 0.10 0.00 0.01
## [8,] 0.01 0.00 0.00 0.00 0.00 0.01 0.10 1.51 0.75 0.00
## [9,] 0.00 0.00 0.00 0.64 0.00 -0.01 0.00 0.75 1.90 -0.01
## [10,] -0.01 0.00 0.00 -0.01 1.80 0.00 0.01 0.00 -0.01 2.52
# To compare the result with true graph
compare( bdgraph.obj, data.sim, main = c( "Target", "BDgraph" ), vis = TRUE )
## Target BDgraph
## True Positive 10 3.000
## True Negative 35 35.000
## False Positive 0 0.000
## False Negative 0 7.000
## F1-score 1 0.462
## Specificity 1 1.000
## Sensitivity 1 0.300
## MCC 1 0.500
# - - Example 2
# Generating multivariate Discrete Weibull data based on a 'scale-free' graph
data.sim <- bdgraph.sim( n = 100, p = 10, type = "dw", graph = "scale-free", vis = TRUE )
summary( bdgraph.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 1 1 0 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0 0 0 1 0
## [3,] 0 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0 0
## [5,] 0 0 0 0 0 0 0 1 0 0
## [6,] 0 0 0 0 0 0 0 0 0 0
## [7,] 0 0 0 0 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 0 0 0 0
## [9,] 0 0 0 0 0 0 0 0 0 0
## [10,] 0 0 0 0 0 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0 0.56 0.93 0.13 0.03 0.04 0.02 0.03 0.16 0.03
## [2,] 0 0.00 0.03 0.04 0.06 0.06 0.04 0.06 1.00 0.08
## [3,] 0 0.00 0.00 0.04 0.02 0.04 0.05 0.04 0.05 0.04
## [4,] 0 0.00 0.00 0.00 0.04 0.06 0.06 0.04 0.02 0.03
## [5,] 0 0.00 0.00 0.00 0.00 0.04 0.03 1.00 0.05 0.05
## [6,] 0 0.00 0.00 0.00 0.00 0.00 0.04 0.05 0.05 0.03
## [7,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.03 0.04 0.03
## [8,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.16 0.06
## [9,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.09
## [10,] 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
##
## $K_hat
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 1.48 -0.26 -0.54 -0.04 0.00 0.00 0.00 0.00 -0.05 0.00
## [2,] -0.26 1.99 0.00 0.00 0.01 0.02 0.00 0.01 -1.09 0.01
## [3,] -0.54 0.00 1.31 -0.01 0.00 -0.01 -0.01 0.00 0.01 0.00
## [4,] -0.04 0.00 -0.01 1.10 0.00 -0.01 -0.01 0.00 0.00 0.00
## [5,] 0.00 0.01 0.00 0.00 2.07 0.00 0.00 -1.37 0.01 -0.01
## [6,] 0.00 0.02 -0.01 -0.01 0.00 1.11 0.00 0.01 -0.01 0.00
## [7,] 0.00 0.00 -0.01 -0.01 0.00 0.00 1.08 0.00 0.01 0.00
## [8,] 0.00 0.01 0.00 0.00 -1.37 0.01 0.00 2.02 0.06 -0.01
## [9,] -0.05 -1.09 0.01 0.00 0.01 -0.01 0.01 0.06 1.85 0.02
## [10,] 0.00 0.01 0.00 0.00 -0.01 0.00 0.00 -0.01 0.02 1.18
compare( bdgraph.obj, data.sim, main = c( "Target", "BDgraph" ), vis = TRUE )
## Target BDgraph
## True Positive 9 4.000
## True Negative 36 36.000
## False Positive 0 0.000
## False Negative 0 5.000
## F1-score 1 0.615
## Specificity 1 1.000
## Sensitivity 1 0.444
## MCC 1 0.625
# Generating multivariate normal data from a 'random' graph
data.sim <- bdgraph.sim( n = 70, p = 5, size = 7, vis = TRUE )
bdgraph.obj <- bdgraph.mpl( data = data.sim, iter = 500 )
## 500 MCMC sampling ... in progress:
## 10%->20%->30%->40%->50%->60%->70%->80%->90%-> done
summary( bdgraph.obj )
## $selected_g
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 1 1
## [2,] 0 0 0 0 0
## [3,] 0 0 0 0 0
## [4,] 0 0 0 0 1
## [5,] 0 0 0 0 0
##
## $p_links
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0.01 0.63 1.00
## [2,] 0 0 0.01 0.01 0.01
## [3,] 0 0 0.00 0.01 0.00
## [4,] 0 0 0.00 0.00 1.00
## [5,] 0 0 0.00 0.00 0.00
# To compare the result with true graph
compare( bdgraph.obj, data.sim, main = c( "Target", "BDgraph" ) )
## Target BDgraph
## True Positive 7 3.000
## True Negative 3 3.000
## False Positive 0 0.000
## False Negative 0 4.000
## F1-score 1 0.600
## Specificity 1 1.000
## Sensitivity 1 0.429
## MCC 1 0.429
# Generating multivariate normal data from a 'random' graph
data.sim <- bdgraph.sim( n = 6, p = 4, size = 4 )
data <- ( data.sim $ data - 3 ) ^ 4
data
## [,1] [,2] [,3] [,4]
## [1,] 127.38341 80.238575 120.591788 108.82721
## [2,] 67.12798 25.482843 114.160020 12.94563
## [3,] 4.91958 3.635155 27.602746 42.05637
## [4,] 193.11517 104.620542 51.664960 91.78984
## [5,] 80.86019 16.291977 8.429095 137.41795
## [6,] 461.84819 42.986082 86.954324 92.49113
# Transfer the data by truncation
bdgraph.npn( data, npn = "truncation" )
## [,1] [,2] [,3] [,4]
## [1,] 0.4752025 1.0673137 1.6504720 1.0673137
## [2,] -0.4752025 0.0000000 1.0673137 -1.0673137
## [3,] -1.0673137 -1.0673137 -0.4752025 -0.4752025
## [4,] 1.0673137 1.6504720 0.0000000 0.0000000
## [5,] 0.0000000 -0.4752025 -1.0673137 1.6504720
## [6,] 1.6504720 0.4752025 0.4752025 0.4752025
# Transfer the data by shrunken
bdgraph.npn( data, npn = "shrunken" )
## [,1] [,2] [,3] [,4]
## [1,] 127.38341 80.238575 120.591788 108.82721
## [2,] 67.12798 25.482843 114.160020 12.94563
## [3,] 4.91958 3.635155 27.602746 42.05637
## [4,] 193.11517 104.620542 51.664960 91.78984
## [5,] 80.86019 16.291977 8.429095 137.41795
## [6,] 461.84819 42.986082 86.954324 92.49113
# Transfer the data by skeptic
bdgraph.npn( data, npn = "skeptic" )
## [,1] [,2] [,3] [,4]
## [1,] 1.0000000 0.7860501 0.2684665 0.4450419
## [2,] 0.7860501 1.0000000 0.5608548 0.1494602
## [3,] 0.2684665 0.5608548 1.0000000 -0.2090569
## [4,] 0.4450419 0.1494602 -0.2090569 1.0000000
# Generating multivariate normal data from a 'random' graph
data.sim <- bdgraph.sim( p = 10, n = 50, prob = 0.3, vis = TRUE )
print( data.sim )
## graph generated by bdgraph.sim
## Data type = Gaussian
## Sample size = 50
## Graph type = random
## Number of nodes = 10
## Graph size = 10
## Sparsity = 0.7778
# Generating multivariate normal data from a 'hub' graph
data.sim <- bdgraph.sim( p = 6, n = 3, graph = "hub", vis = FALSE )
round( data.sim$data, 2 )
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 1.45 -0.57 0.70 -1.15 0.38 1.40
## [2,] 1.34 -0.24 0.71 -1.20 -0.11 1.00
## [3,] -0.73 1.33 0.72 0.47 -0.06 0.57
# Generating mixed data from a 'hub' graph
data.sim <- bdgraph.sim( p = 8, n = 10, graph = "hub", type = "mixed" )
round( data.sim $ data, 2 )
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] 5 4 0.00 0 -1.93 -2.09 0.24 -1.50
## [2,] 5 4 0.00 0 -2.10 -1.92 -0.35 -1.87
## [3,] 13 1 0.14 1 0.86 0.90 -0.54 0.94
## [4,] 11 0 0.11 1 0.14 1.09 0.82 0.19
## [5,] 15 0 0.31 1 1.38 1.51 1.09 1.62
## [6,] 11 3 0.10 1 -0.71 0.14 -0.87 -0.20
## [7,] 10 1 0.07 0 0.43 1.11 2.26 -0.12
## [8,] 12 3 0.09 0 0.14 0.13 -0.97 -0.39
## [9,] 5 6 0.01 0 -2.18 -1.71 1.10 -2.12
## [10,] 6 5 0.00 0 -2.03 -1.33 -0.79 -1.93
# Generating only a 'scale-free' graph (with no data)
graph.sim <- bdgraph.sim( p = 8, graph = "scale-free" )
plot( graph.sim )
graph.sim$G
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] 0 1 1 1 1 0 1 0
## [2,] 1 0 0 0 0 1 0 1
## [3,] 1 0 0 0 0 0 0 0
## [4,] 1 0 0 0 0 0 0 0
## [5,] 1 0 0 0 0 0 0 0
## [6,] 0 1 0 0 0 0 0 0
## [7,] 1 0 0 0 0 0 0 0
## [8,] 0 1 0 0 0 0 0 0
## attr(,"class")
## [1] "graph"