Given a Knowledge object, return a single string containing
the R code (using knowledge(), tier(), %-->%, and %!-->%.
that would rebuild that same object.
Arguments
- kn
A
Knowledgeobject.- df_name
Optional name of the data frame you used (used as the first argument to
knowledge()). IfNULL,knowledge()is called with no data frame.
See also
Other knowledge functions:
+.Knowledge(),
add_exogenous(),
add_tier(),
add_to_tier(),
add_vars(),
as_bnlearn_knowledge(),
as_pcalg_constraints(),
as_tetrad_knowledge(),
convert_tiers_to_forbidden(),
forbid_edge(),
get_tiers(),
knowledge(),
knowledge_to_caugi(),
remove_edge(),
remove_tiers(),
remove_vars(),
reorder_tiers(),
reposition_tier(),
require_edge(),
seq_tiers(),
unfreeze()
Examples
# turn a Knowledge object back into DSL code
data(tpc_example)
kn <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
),
child_x1 %-->% youth_x3,
oldage_x6 %!-->% child_x1
)
code <- deparse_knowledge(kn, df_name = "tpc_example")
cat(code)
#> knowledge(tpc_example,
#> tier(
#> child ~ child_x1 + child_x2,
#> youth ~ youth_x3 + youth_x4,
#> old ~ oldage_x5 + oldage_x6
#> ),
#> child_x1 %-->% youth_x3,
#> oldage_x6 %!-->% child_x1
#> )
# Explicitly add all forbidden edges implied by tiers
kn <- convert_tiers_to_forbidden(kn)
code <- deparse_knowledge(kn, df_name = "tpc_example")
cat(code)
#> knowledge(tpc_example,
#> child_x1 %-->% youth_x3,
#> oldage_x5 %!-->% c(child_x1, child_x2, youth_x3, youth_x4),
#> oldage_x6 %!-->% c(child_x1, child_x2, youth_x3, youth_x4),
#> youth_x3 %!-->% c(child_x1, child_x2),
#> youth_x4 %!-->% c(child_x1, child_x2)
#> )
