data(tpc_example)
# Define tiered knowledge
kn <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
)
)
# Fit a causal discovery model
cd_tges <- tges(engine = "causalDisco", score = "tbic")
disco_cd_tges <- disco(data = tpc_example, method = cd_tges, knowledge = kn)
# Plot with default column orientation
plot(disco_cd_tges)
# Plot with row orientation
plot(disco_cd_tges, orientation = "rows")
# Plot with custom node and edge styling
plot(
disco_cd_tges,
node_style = list(
fill = "lightblue", # Fill color
col = "darkblue", # Border color
lwd = 2, # Border width
padding = 4, # Text padding (mm)
size = 1.2 # Size multiplier
),
edge_style = list(
lwd = 1.5, # Edge width
arrow_size = 4, # Arrow size (mm)
col = "darkgreen", # Edge color
fill = "black", # Arrow fill color
lty = "dashed" # Edge line type
)
)
# To override a specific edge style which is required you need to target that individual node:
kn <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
),
child_x1 %-->% c(child_x2, youth_x4) # required edges
)
bnlearn_pc <- pc(engine = "bnlearn", test = "fisher_z")
disco_bnlearn_pc <- disco(data = tpc_example, method = bnlearn_pc, knowledge = kn)
# Edge from child_x1 to child_x2 will be orange, but edge from child_x1 to youth_x4
# will be required_col (blue) since we only override the child_x1 to child_x2 edge.
plot(
disco_bnlearn_pc,
edge_style = list(
by_edge = list(
child_x1 = list(
child_x2 = list(col = "orange", fill = "orange")
)
)
),
required_col = "blue"
)
# Plot without tiers
data(num_data)
kn_untiered <- knowledge(
num_data,
X1 %-->% c(X2, X3),
Z %!-->% Y
)
bnlearn_pc <- pc(engine = "bnlearn", test = "fisher_z")
res_untiered <- disco(data = num_data, method = bnlearn_pc, knowledge = kn_untiered)
plot(res_untiered)
# With a custom defined layout
custom_layout <- data.frame(
name = c("X1", "X2", "X3", "Z", "Y"),
x = c(0, 1, 2, 2, 3),
y = c(0, 1, 0.25, -1, 0)
)
plot(res_untiered, layout = custom_layout)
Run the code above in your browser using DataLab