View source: R/knowledge-conversions.R
| as_pcalg_constraints | R Documentation |
pcalg only supports undirected (symmetric) background constraints:
fixed_gaps - forbidding edges (zeros enforced)
fixed_edges - requiring edges (ones enforced)
as_pcalg_constraints(kn, labels = kn$vars$var, directed_as_undirected = FALSE)
kn |
A |
labels |
Character vector of all variable names, in the exact order
of your data columns. Every variable referenced by an edge in |
directed_as_undirected |
Logical (default |
This function takes a Knowledge object (with only forbidden/required
edges, no tiers) and returns the two logical matrices in the exact
variable order you supply.
A list with two elements, each an n × n logical matrix
corresponding to pcalg fixed_gaps and fixed_edges arguments.
If the Knowledge object contains tiered knowledge.
If directed_as_undirected = FALSE and any edge lacks its
symmetrical counterpart. This can only hold for forbidden edges.
Other knowledge functions:
+.Knowledge(),
add_exogenous(),
add_tier(),
add_to_tier(),
add_vars(),
as_bnlearn_knowledge(),
as_tetrad_knowledge(),
convert_tiers_to_forbidden(),
deparse_knowledge(),
forbid_edge(),
get_tiers(),
knowledge(),
knowledge_to_caugi(),
remove_edge(),
remove_tiers(),
remove_vars(),
reorder_tiers(),
reposition_tier(),
require_edge(),
seq_tiers(),
unfreeze()
# pcalg supports undirected constraints; build a tierless knowledge and convert
data(tpc_example)
kn <- knowledge(
tpc_example,
child_x1 %!-->% youth_x3,
youth_x3 %!-->% child_x1
)
pc_constraints <- as_pcalg_constraints(kn, directed_as_undirected = FALSE)
print(pc_constraints)
# error paths
# using tiers
kn <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
oldage ~ starts_with("old")
),
child_x1 %-->% youth_x3
)
try(as_pcalg_constraints(kn), silent = TRUE) # fails due to tiers
# using directed knowledge
kn <- knowledge(
tpc_example,
child_x1 %!-->% youth_x3
)
try(as_pcalg_constraints(kn), silent = TRUE) # fails due to directed knowledge
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.