| PcalgSearch | R Documentation |
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.
dataA data.frame holding the data set currently attached to the
search object. Can be set with set_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.
See pcalg::gaussCItest().
"fisher_z_twd" - Fisher Z test for Gaussian data with test-wise deletion.
See micd::gaussCItwd().
"fisher_z_mi" - Fisher Z test for Gaussian data with multiple imputation.
See micd::gaussCItestMI().
"g_square" - G square test for discrete data.
See pcalg::binCItest() and pcalg::disCItest().
"g_square_twd" - G square test for discrete data with test-wise deletion.
See micd::disCItwd().
"g_square_mi" - G square test for discrete data with multiple imputation.
See micd::disMItest().
"conditional_gaussian" - Test for conditional independence in mixed data.
See micd::mixCItest().
"conditional_gaussian_twd" - Test for conditional independence in mixed data
with test-wise deletion.
See micd::mixCItwd().
"conditional_gaussian_mi" - Test for conditional independence in mixed data
with multiple imputation.
See micd::mixMItest().
algA function that will be used to run the search algorithm.
Can be set with $set_alg(). Recognized values are:
"fci" - FCI algorithm. See fci() and the underlying pcalg::fci().
"ges" - GES algorithm. See ges() and the underlying pcalg::ges().
"pc" - PC algorithm. See pc() and the underlying pcalg::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.
new()Constructor for the PcalgSearch class.
PcalgSearch$new()
set_params()Sets the parameters for the test and algorithm.
PcalgSearch$set_params(params)
paramsA list of parameters to set.
set_data()Sets the data for the search algorithm.
PcalgSearch$set_data(data, set_suff_stat = TRUE)
dataA data.frame or a matrix containing the data.
set_suff_statLogical; whether to set the sufficient statistic. for the data.
set_suff_stat()Sets the sufficient statistic for the data.
PcalgSearch$set_suff_stat()
set_test()Sets the test for the search algorithm.
PcalgSearch$set_test(method, alpha = 0.05, suff_stat_fun = NULL, args = NULL)
methodA string specifying the type of test to use.
Can also be a user-defined function with
signature function(x, y, conditioning_set, suff_stat), where x and y are the variables being tested for
independence, conditioning_set is the conditioning set, and suff_stat is the sufficient statistic for the
test. If a user-defined function is provided, then suff_stat_fun must also be provided, which is a
function that should take the data as input and returns a sufficient statistic for the test. Optionally,
the signature of the user-defined test function can also include an args parameter, which is a list of
additional arguments to pass to the test function. If args is provided, then the test function should have the
signature function(x, y, conditioning_set, suff_stat, args), and the args parameter will be passed to the
test function.
EXPERIMENTAL: user-defined tests syntax are subject to change.
alphaSignificance level for the test.
suff_stat_funA function that takes the data as input and returns a sufficient statistic for the test.
Only needed if method is a user-defined function.
argsA list of additional arguments to pass to the test.
Only needed if method is a user-defined function with an args parameter in its signature.
set_score()Sets the score for the search algorithm.
PcalgSearch$set_score(method, params = list())
methodA string specifying the type of score to use.
paramsA list of parameters to pass to the score function.
set_alg()Sets the algorithm for the search.
PcalgSearch$set_alg(method)
methodA string specifying the type of algorithm to use.
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.
PcalgSearch$set_knowledge(knowledge_obj, directed_as_undirected = FALSE)
knowledge_objA Knowledge object that contains the fixed constraints.
directed_as_undirectedLogical; whether to treat directed edges as undirected.
run_search()Runs the search algorithm on the data.
PcalgSearch$run_search(data = NULL, set_suff_stat = TRUE)
dataA data.frame or a matrix containing the data.
set_suff_statLogical; whether to set the sufficient statistic
clone()The objects of this class are cloneable with this method.
PcalgSearch$clone(deep = FALSE)
deepWhether to make a deep clone.
### 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)
# or
disco(data = num_data, method = my_pc)
# 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)
# With knowledge
kn <- knowledge(
num_data,
X1 %!-->% X2,
X2 %!-->% X1
)
disco(data = num_data, method = my_pc2, knowledge = kn)
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.