Directed acyclic graphs (DAGs) via Bayesian networks (BNs). It uses bnlearn::boot.strength()
to estimate the strength of each edge as its empirical frequency over a set of networks learned from bootstrap samples. It computes (1) the probability of each edge (modulo its direction) and (2) the probabilities of each edge's directions conditional on the edge being present in the graph (in either direction). Stability thresholds are usually set as 0.85
for strength (i.e., an edge appearing in more than 85% of BNs bootstrap samples) and 0.50
for direction (i.e., a direction appearing in more than 50% of BNs bootstrap samples) (Briganti et al., 2023). Finally, for each chosen algorithm, it returns the stable Bayesian network as the final DAG.
Arguments
- data
Data.
- algorithm
Structure learning algorithms for building Bayesian networks (BNs). Should be function name(s) from the
bnlearn
package. Better to perform BNs with all three classes of algorithms to check the robustness of results (Briganti et al., 2023).Defaults to the most common algorithms:
"pc.stable"
(PC),"hc"
(HC), and"rsmax2"
(RS), for the three classes, respectively.(3) Hybrid Algorithms (combination of constraint-based and score-based algorithms)
- algorithm.args
An optional list of extra arguments passed to the algorithm.
- n.boot
Number of bootstrap samples (for learning a more "stable" network structure). Defaults to
1000
.- seed
Random seed for replicable results. Defaults to
NULL
.- strength
Stability threshold of edge strength: the minimum proportion (probability) of BNs (among the
n.boot
bootstrap samples) in which each edge appears.Defaults to
0.85
(85%).Two reverse directions share the same edge strength.
Empirical frequency (?~100%) will be mapped onto edge width/thickness in the final integrated
DAG
, with wider (thicker) edges showing stronger links, though they usually look similar since the default range has been limited to 0.85~1.
- direction
Stability threshold of edge direction: the minimum proportion (probability) of BNs (among the
n.boot
bootstrap samples) in which a direction of each edge appears.Defaults to
0.50
(50%).The proportions of two reverse directions add up to 100%.
Empirical frequency (?~100%) will be mapped onto edge greyscale/transparency in the final integrated
DAG
, with its value shown as edge text label.
- node.text.size
Scalar on the font size of node (variable) labels. Defaults to
1.2
.- edge.width.max
Maximum value of edge strength to scale all edge widths. Defaults to
1.5
for better display of arrow.- edge.label.mrg
Margin of the background box around the edge label. Defaults to
0.01
.- file
File name of saved plot (
".png"
or".pdf"
).- width, height
Width and height (in inches) of saved plot. Defaults to
6
and4
.- dpi
Dots per inch (figure resolution). Defaults to
500
.- ...
Arguments passed on to
qgraph()
.
Value
Return a list (class dag.net
) of Bayesian network results and qgraph
object with its grob
(Grid Graphical Object).
References
Briganti, G., Scutari, M., & McNally, R. J. (2023). A tutorial on Bayesian networks for psychopathology researchers. Psychological Methods, 28(4), 947–961. doi:10.1037/met0000479
Burger, J., Isvoranu, A.-M., Lunansky, G., Haslbeck, J. M. B., Epskamp, S., Hoekstra, R. H. A., Fried, E. I., Borsboom, D., & Blanken, T. F. (2023). Reporting standards for psychological network analyses in cross-sectional data. Psychological Methods, 28(4), 806–824. doi:10.1037/met0000471
Scutari, M., & Denis, J.-B. (2021). Bayesian networks: With examples in R (2nd ed.). Chapman and Hall/CRC. doi:10.1201/9780429347436
Examples
bn = dag_network(airquality, seed=1)
#> Running BN algorithm "pc.stable" with 1000 bootstrap samples...
#> Running BN algorithm "hc" with 1000 bootstrap samples...
#> Running BN algorithm "rsmax2" with 1000 bootstrap samples...
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
bn
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Displaying DAG with BN algorithm "pc.stable"
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Displaying DAG with BN algorithm "hc"
#> Warning: Package `gridGraphics` is required to handle base-R plots. Substituting empty plot.
#> Displaying DAG with BN algorithm "rsmax2"
# bn$pc.stable
# bn$hc
# bn$rsmax2
## All DAG objects can be directly plotted
## or saved with print(..., file="xxx.png")
# bn$pc.stable$DAG.edge
# bn$pc.stable$DAG.strength
# bn$pc.stable$DAG.direction
# bn$pc.stable$DAG
# ...
if (FALSE) { # \dontrun{
print(bn, file="airquality.png")
# will save three plots with auto-modified file names:
- "airquality_DAG.NET_BNs.01_pc.stable.png"
- "airquality_DAG.NET_BNs.02_hc.png"
- "airquality_DAG.NET_BNs.03_rsmax2.png"
# arrange multiple plots using cowplot::plot_grid()
# but still with unknown issue on incomplete figure
c1 = cor_network(airquality, "cor")
c2 = cor_network(airquality, "pcor")
bn = dag_network(airquality, seed=1)
plot_grid(
~print(c1),
~print(c2),
~print(bn$hc$DAG),
~print(bn$rsmax2$DAG),
labels="AUTO"
)
} # }