pcalg only supports undirected (symmetric) background constraints:
fixed_gaps - forbidding edges (zeros enforced)
Usage
as_pcalg_constraints(
kn,
labels = kn$vars$var,
directed_as_undirected = lifecycle::deprecated()
)Arguments
- kn
A
Knowledgeobject. Must have no tier information.- labels
Character vector of all variable names, in the exact order of your data columns. Every variable referenced by an edge in
knmust appear here.- directed_as_undirected
This argument no longer has any effect and will be removed in a future release. Specify directed edges in both directions in
knowledge()instead.
Value
A list with one element, fixed_gaps: an n × n logical
matrix corresponding to the pcalg fixedGaps argument.
Details
This function takes a Knowledge object (with only forbidden edges, no
tiers) and returns the logical constraint matrix in the exact variable
order you supply.
Required edges in a Knowledge object are directed statements. pcalg
constraints are adjacency-level only, so a required edge cannot be honored;
any required edges are dropped with a warning.
Errors
If the
Knowledgeobject contains tiered knowledge.If any forbidden edge lacks its symmetrical counterpart.
See also
Other knowledge helpers:
+.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(),
set_knowledge(),
unfreeze()
Examples
# 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)
print(pc_constraints)
#> $fixed_gaps
#> child_x1 child_x2 oldage_x5 oldage_x6 youth_x3 youth_x4
#> child_x1 FALSE FALSE FALSE FALSE TRUE FALSE
#> child_x2 FALSE FALSE FALSE FALSE FALSE FALSE
#> oldage_x5 FALSE FALSE FALSE FALSE FALSE FALSE
#> oldage_x6 FALSE FALSE FALSE FALSE FALSE FALSE
#> youth_x3 TRUE FALSE FALSE FALSE FALSE FALSE
#> youth_x4 FALSE FALSE FALSE FALSE FALSE FALSE
#>
# 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
