Run the Fast Causal Inference algorithm for causal discovery using one of several engines.
Usage
fci(engine = c("tetrad", "pcalg"), test, alpha = 0.05, ...)Arguments
- engine
Character; which engine to use. Must be one of:
"tetrad"Tetrad Java library.
"pcalg"pcalg R package.
- test
Character; name of the conditional‐independence test.
- alpha
Numeric; significance level for the CI tests.
- ...
Additional arguments passed to the chosen engine (e.g. test or algorithm parameters).
Details
For specific details on the supported tests and parameters for each engine, see:
TetradSearch for Tetrad,
PcalgSearch for pcalg.
Recommendation
While it is possible to call the function returned directly with a data frame,
we recommend using disco(). This provides a consistent interface and handles knowledge
integration.
Value
A function that takes a single argument data (a data frame). When called,
this function returns a list containing:
knowledgeAKnowledgeobject with the background knowledge used in the causal discovery algorithm. Seeknowledge()for how to construct it.caugiAcaugi::caugiobject representing the learned causal graph. This graph is a PAG (Partial Ancestral Graph), but since PAGs are not yet natively supported in caugi, it is currently stored with classUNKNOWN.
References
Spirtes, P., Meek, C., & Richardson, T. (1995, August). Causal inference in the presence of latent variables and selection bias. In Proceedings of the Eleventh conference on Uncertainty in artificial intelligence (pp. 499-506).
See also
Other causal discovery algorithms:
boss(),
boss_fci(),
ges(),
gfci(),
grasp(),
grasp_fci(),
gs(),
iamb-family,
pc(),
rfci(),
sp_fci(),
tfci(),
tges(),
tpc()
Examples
data(tpc_example)
# Recommended path using disco()
fci_pcalg <- fci(engine = "pcalg", test = "fisher_z", alpha = 0.05)
disco(tpc_example, fci_pcalg)
#> <Disco PAG: 6 nodes | 6 edges>
#> nodes: child_x2, child_x1, youth_x4, youth_x3, oldage_x6, oldage_x5
#> edges: child_x2o-ochild_x1, child_x2o->oldage_x5, child_x2o-oyouth_x4
#> oldage_x5-->oldage_x6, youth_x3o->oldage_x5, youth_x4-->oldage_x6
# or using fci_pcalg directly
fci_pcalg(tpc_example)
#> <Disco UNKNOWN: 6 nodes | 6 edges>
#> nodes: child_x2, child_x1, youth_x4, youth_x3, oldage_x6, oldage_x5
#> edges: child_x2o-ochild_x1, child_x2o->oldage_x5, child_x2o-oyouth_x4
#> oldage_x5-->oldage_x6, youth_x3o->oldage_x5, youth_x4-->oldage_x6
# With all algorithm arguments specified
fci_pcalg <- fci(
engine = "pcalg",
test = "fisher_z",
alpha = 0.05,
skel.method = "original",
type = "anytime",
fixedGaps = NULL,
fixedEdges = NULL,
NAdelete = FALSE,
m.max = 10,
pdsep.max = 2,
rules = c(rep(TRUE, 9), FALSE),
doPdsep = FALSE,
biCC = TRUE,
conservative = TRUE,
maj.rule = FALSE,
numCores = 1,
selectionBias = FALSE,
jci = "1",
verbose = FALSE
)
disco(tpc_example, fci_pcalg)
#> <Disco PAG: 6 nodes | 6 edges>
#> nodes: child_x2, child_x1, youth_x4, youth_x3, oldage_x6, oldage_x5
#> edges: child_x2o-ochild_x1, child_x2o->oldage_x5, child_x2o-oyouth_x4
#> oldage_x5-->oldage_x6, youth_x3o->oldage_x5, youth_x4-->oldage_x6
#### Using tetrad engine with tier knowledge ####
# Requires Tetrad to be installed
if (verify_tetrad()$installed && verify_tetrad()$java_ok) {
kn <- knowledge(
tpc_example,
tier(
child ~ tidyselect::starts_with("child"),
youth ~ tidyselect::starts_with("youth"),
oldage ~ tidyselect::starts_with("oldage")
)
)
# Recommended path using disco()
fci_tetrad <- fci(engine = "tetrad", test = "fisher_z", alpha = 0.05)
disco(tpc_example, fci_tetrad, knowledge = kn)
# or using fci_tetrad directly
fci_tetrad <- fci_tetrad |> set_knowledge(kn)
fci_tetrad(tpc_example)
}
#> <Disco UNKNOWN: 6 nodes | 6 edges>
#> nodes: child_x2, child_x1, youth_x4, youth_x3, oldage_x6, oldage_x5
#> edges: child_x2o-ochild_x1, child_x2o->oldage_x5, child_x2o-oyouth_x4
#> oldage_x5-->oldage_x6, youth_x3o->oldage_x5, youth_x4-->oldage_x6
# With all algorithm arguments specified
if (verify_tetrad()$installed && verify_tetrad()$java_ok) {
fci_tetrad <- fci(
engine = "tetrad",
test = "fisher_z",
alpha = 0.05,
complete_rule_set_used = FALSE,
max_disc_path_length = 4,
depth = 10,
stable_fas = FALSE,
guarantee_pag = TRUE
)
disco(tpc_example, fci_tetrad)
}
#> <Disco PAG: 6 nodes | 6 edges>
#> nodes: child_x2, child_x1, youth_x4, youth_x3, oldage_x6, oldage_x5
#> edges: child_x1o->child_x2, child_x2<->oldage_x5, child_x2<->youth_x4
#> oldage_x6<->oldage_x5, youth_x3o->oldage_x5, youth_x4<->oldage_x6
