Run the GFCI (Greedy Fast Causal Inference) algorithm for causal discovery using one of several engines. This combines the FGES and FCI algorithms.
Arguments
- engine
Character; which engine to use. Must be one of:
"tetrad"Tetrad Java library.
- score
Character; name of the scoring function to use.
- 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. score and algorithm parameters).
Details
For specific details on the supported scores, and parameters for each engine, see:
TetradSearch for Tetrad.
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 incaugi, it is currently stored with classUNKNOWN.
See also
Other causal discovery algorithms:
boss(),
boss_fci(),
fci(),
ges(),
grasp(),
grasp_fci(),
gs(),
iamb-family,
pc(),
sp_fci(),
tfci(),
tges(),
tpc()
Examples
data(num_data)
# Requires Tetrad to be installed
if (verify_tetrad()$installed && verify_tetrad()$java_ok) {
# Recommended path using disco()
gfci_tetrad <- gfci(
engine = "tetrad",
score = "sem_bic",
test = "fisher_z"
)
disco(tpc_example, gfci_tetrad)
# or using gfci_tetrad directly
gfci_tetrad(tpc_example)
}
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: UNKNOWN
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 child_x2 o-o child_x1
#> 2 child_x2 o-> oldage_x5
#> 3 child_x2 o-o youth_x4
#> 4 oldage_x5 --> oldage_x6
#> 5 youth_x3 o-> oldage_x5
#> 6 youth_x4 --> oldage_x6
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 child_x2
#> 2 child_x1
#> 3 youth_x4
#> 4 youth_x3
#> 5 oldage_x6
#> 6 oldage_x5
#> ── Knowledge object ────────────────────────────────────────────────────────────
#### With tier knowledge ####
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()
gfci_tetrad <- gfci(
engine = "tetrad",
score = "sem_bic",
test = "fisher_z"
)
disco(tpc_example, gfci_tetrad, knowledge = kn)
# or using gfci_tetrad directly
gfci_tetrad <- gfci_tetrad |> set_knowledge(kn)
gfci_tetrad(tpc_example)
}
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: UNKNOWN
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 child_x2 o-o child_x1
#> 2 child_x2 o-> oldage_x5
#> 3 child_x2 o-o youth_x4
#> 4 oldage_x5 --> oldage_x6
#> 5 youth_x3 o-> oldage_x5
#> 6 youth_x4 --> oldage_x6
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 child_x2
#> 2 child_x1
#> 3 youth_x4
#> 4 youth_x3
#> 5 oldage_x6
#> 6 oldage_x5
#> ── Knowledge object ────────────────────────────────────────────────────────────
# With all algorithm arguments specified
if (verify_tetrad()$installed && verify_tetrad()$java_ok) {
gfci_tetrad <- gfci(
engine = "tetrad",
score = "poisson_prior",
test = "rank_independence",
depth = 3,
max_degree = 2,
max_disc_path_length = 5,
use_heuristic = FALSE,
complete_rule_set_used = FALSE,
guarantee_pag = TRUE,
start_complete = TRUE,
num_threads = 2,
verbose = TRUE
)
disco(num_data, gfci_tetrad)
}
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: UNKNOWN
#>
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 X1
#> 2 X2
#> 3 X3
#> 4 Z
#> 5 Y
#> ── Knowledge object ────────────────────────────────────────────────────────────
