A wrapper that lets you drive pcalg algorithms within the causalDisco framework. For arguments to the test, score, and algorithm, see the pcalg documentation, which we link to in the respective sections below.
Public fields
dataA
data.frameholding the data set currently attached to the search object. Can be set withset_data().scoreA function that will be used to build the score, when data is set. Can be set with
$set_score(). Recognized values are:"sem_bic"- BIC score for Gaussian observed data. See pcalg::GaussL0penObsScore."sem_bic_int"- BIC score for Gaussian data from jointly interventional and observational Gaussian data. See pcalg::GaussL0penIntScore.
testA function that will be used to test independence. Can be set with
$set_test(). Recognized values are:"fisher_z"- Fisher Z test for Gaussian data. Seepcalg::gaussCItest()."g_square"- G square test for discrete data. Seepcalg::binCItest()andpcalg::disCItest().
algA function that will be used to run the search algorithm. Can be set with
$set_alg(). Recognized values are:"fci"- FCI algorithm. Seefci()and the underlyingpcalg::fci()."ges"- GES algorithm. Seeges()and the underlyingpcalg::ges()."pc"- PC algorithm. Seepc()and the underlyingpcalg::pc().
paramsA list of parameters for the test and algorithm. Can be set with
$set_params(). The parameters are passed to the test and algorithm functions.suff_statSufficient statistic. The format and contents of the sufficient statistic depends on which test is being used.
continuousLogical; whether the sufficient statistic is for a continuous test. If both continuous and discrete are
TRUE, the sufficient statistic is build for a mixed test.discreteLogical; whether the sufficient statistic is for a discrete test. If both continuous and discrete are
TRUE, the sufficient statistic is build for a mixed test.knowledgeA list of fixed constraints for the search algorithm. Note, that pcalg only works with symmetric knowledge. Thus, the only allowed types of knowledge is forbidden edges in both directions.
adapt_dfLogical; whether to adapt the degrees of freedom for discrete tests.
Methods
Method set_score()
Sets the score for the search algorithm.
Usage
PcalgSearch$set_score(method, params = list())Method set_knowledge()
Sets the knowledge for the search algorithm. Due to the nature of pcalg, we cannot set knowledge before we run it on data. So we set the function that will be used to build the fixed constraints, but it can first be done when data is provided.
Examples
### pcalg_search R6 class examples ###
# Generally, we do not recommend using the R6 classes directly, but rather
# use the disco() or any method function, for example pc(), instead.
# Load data
data(num_data)
# Recommended:
my_pc <- pc(engine = "pcalg", test = "fisher_z")
my_pc(num_data)
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: PDAG
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 X1 --> Y
#> 2 X1 --- Z
#> 3 X2 --- X3
#> 4 X2 --> Y
#> 5 X3 --> Y
#> 6 Z --> Y
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 X1
#> 2 X2
#> 3 X3
#> 4 Z
#> 5 Y
#> ── Knowledge object ────────────────────────────────────────────────────────────
# or
disco(data = num_data, method = my_pc)
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: PDAG
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 X1 --> Y
#> 2 X1 --- Z
#> 3 X2 --- X3
#> 4 X2 --> Y
#> 5 X3 --> Y
#> 6 Z --> Y
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 X1
#> 2 X2
#> 3 X3
#> 4 Z
#> 5 Y
#> ── Knowledge object ────────────────────────────────────────────────────────────
# Example with detailed settings:
my_pc2 <- pc(
engine = "pcalg",
test = "fisher_z",
alpha = 0.01,
m.max = 4,
skel.method = "original"
)
disco(data = num_data, method = my_pc2)
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: PDAG
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 X1 --> Y
#> 2 X2 --- X3
#> 3 X2 --> Y
#> 4 X3 --> Y
#> 5 Z --> X1
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 X1
#> 2 X2
#> 3 X3
#> 4 Z
#> 5 Y
#> ── Knowledge object ────────────────────────────────────────────────────────────
# With knowledge
kn <- knowledge(
num_data,
X1 %!-->% X2,
X2 %!-->% X1
)
disco(data = num_data, method = my_pc2, knowledge = kn)
#>
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: PDAG
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 X1 --> Y
#> 2 X2 --- X3
#> 3 X2 --> Y
#> 4 X3 --> Y
#> 5 Z --> X1
#> ── Nodes ──
#>
#> name
#> <chr>
#> 1 X1
#> 2 X2
#> 3 X3
#> 4 Z
#> 5 Y
#> ── Knowledge object ────────────────────────────────────────────────────────────
#>
#> ── Variables ──
#>
#> var tier
#> <chr> <chr>
#> 1 X1 NA
#> 2 X2 NA
#> 3 X3 NA
#> 4 Y NA
#> 5 Z NA
#> ── Edges ──
#>
#> ✖ X1 → X2
#> ✖ X2 → X1
# Using R6 class:
s <- PcalgSearch$new()
s$set_test(method = "fisher_z", alpha = 0.05)
s$set_data(tpc_example)
s$set_alg("pc")
g <- s$run_search()
print(g)
#> ── caugi graph ─────────────────────────────────────────────────────────────────
#> Graph class: PDAG
#>
#> ── Edges ──
#>
#> from edge to
#> <chr> <chr> <chr>
#> 1 child_x1 --- child_x2
#> 2 child_x2 --> oldage_x5
#> 3 child_x2 --- youth_x4
#> 4 oldage_x5 --> oldage_x6
#> 5 youth_x3 --> 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 ────────────────────────────────────────────────────────────
