dag_network | R Documentation |
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.
dag_network(
data,
algorithm = c("pc.stable", "hc", "rsmax2"),
algorithm.args = list(),
n.boot = 1000,
seed = NULL,
strength = 0.85,
direction = 0.5,
node.text.size = 1.2,
edge.width.max = 1.5,
edge.label.mrg = 0.01,
file = NULL,
width = 6,
height = 4,
dpi = 500,
...
)
data |
Data. |
algorithm |
Structure learning algorithms for building Bayesian networks (BNs). Should be function name(s) from the Defaults to the most common 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 |
seed |
Random seed for replicable results.
Defaults to |
strength |
Stability threshold of edge strength: the minimum proportion (probability) of BNs (among the
|
direction |
Stability threshold of edge direction: the minimum proportion (probability) of BNs (among the
|
node.text.size |
Scalar on the font size of node (variable) labels.
Defaults to |
edge.width.max |
Maximum value of edge strength to scale all edge widths. Defaults to |
edge.label.mrg |
Margin of the background box around the edge label. Defaults to |
file |
File name of saved plot ( |
width , height |
Width and height (in inches) of saved plot.
Defaults to |
dpi |
Dots per inch (figure resolution). Defaults to |
... |
Arguments passed on to |
Return a list (class dag.net
) of Bayesian network results and qgraph
object with its grob
(Grid Graphical Object).
Briganti, G., Scutari, M., & McNally, R. J. (2023). A tutorial on Bayesian networks for psychopathology researchers. Psychological Methods, 28(4), 947–961. \Sexpr[results=rd]{tools:::Rd_expr_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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1037/met0000471")}
Scutari, M., & Denis, J.-B. (2021). Bayesian networks: With examples in R (2nd ed.). Chapman and Hall/CRC. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1201/9780429347436")}
S3method.network
cor_network()
bn = dag_network(airquality, seed=1)
bn
# 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
# ...
## Not run:
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"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.