| BnlearnSearch | R Documentation |
A wrapper that lets you drive bnlearn algorithms within the causalDisco framework. For arguments to the test, score, and algorithm, see the bnlearn documentation.
An R6 object with the methods documented below.
dataA data.frame holding the data set currently attached to the
search object. Can be set with set_data().
scoreCharacter scalar naming the score function used in
bnlearn. Can be set with $set_score(). Kebab-case score names (as used in bnlearn, e.g.
"pred-loglik") are also accepted and automatically translated to snake_case.
Recognised values are:
Continuous - Gaussian
"aic_g", "bic_g", "ebic_g", "loglik_g", "pred_loglik_g" -
gaussian versions of the respective scores for discrete data.
"bge" - Gaussian posterior density.
"nal_g" - node-average log-likelihood.
"pnal_g" - penalised node-average log-likelihood.
Discrete – categorical
"aic" - Akaike Information Criterion.
"bdla" - locally averaged BDE.
"bde" - Bayesian Dirichlet equivalent (uniform).
"bds" - Bayesian Dirichlet score.
"bic" - Bayesian Information Criterion.
"ebic" - Extended BIC.
"fnml" - factorised NML.
"k2" - K2 score.
"loglik" - log-likelihood.
"mbde" - modified BDE.
"nal" - node-average log-likelihood.
"pnal" - penalised node-average log-likelihood.
"pred_loglik" - predictive log-likelihood.
"qnml" - quotient NML.
Mixed Discrete/Gaussian
"aic_cg", "bic_cg", "ebic_cg", "loglik_cg", "nal_cg",
"pnal_cg", "pred_loglik_cg" - conditional Gaussian versions of the respective scores for
discrete data.
testCharacter scalar naming the conditional-independence test
passed to bnlearn. Can be set with $set_score(). Kebab-case test names
(as used in bnlearn, e.g. "mi-adf") are also accepted and automatically translated to snake_case.
Recognised values are:
Continuous - Gaussian
"cor" – Pearson correlation
"fisher_z" / "zf" – Fisher Z test
"mc_cor" – Monte Carlo Pearson correlation
"mc_mi_g" – Monte Carlo mutual information (Gaussian)
"mc_zf" – Monte Carlo Fisher Z
"mi_g" – mutual information (Gaussian)
"mi_g_sh" – mutual information (Gaussian, shrinkage)
"smc_cor" – sequential Monte Carlo Pearson correlation
"smc_mi_g" – sequential Monte Carlo mutual information (Gaussian)
"smc_zf" – sequential Monte Carlo Fisher Z
Discrete – categorical
"mc_mi" – Monte Carlo mutual information
"mc_x2" – Monte Carlo chi-squared
"mi" – mutual information
"mi_adf" – mutual information with adjusted d.f.
"mi_sh" – mutual information (shrinkage)
"smc_mi" – sequential Monte Carlo mutual information
"smc_x2" – sequential Monte Carlo chi-squared
"sp_mi" – semi-parametric mutual information
"sp_x2" – semi-parametric chi-squared
"x2" – chi-squared
"x2_adf" – chi-squared with adjusted d.f.
Discrete – ordered factors
"jt" – Jonckheere–Terpstra
"mc_jt" – Monte Carlo Jonckheere–Terpstra
"smc_jt" – sequential Monte Carlo Jonckheere–Terpstra
Mixed Discrete/Gaussian
"mi_cg" – mutual information (conditional Gaussian)
For Monte Carlo tests, set the number of permutations using the B argument.
algFunction generated by $set_alg() that runs a
structure-learning algorithm from bnlearn. Period.case alg names
(as used in bnlearn, e.g. "fast.iamb") are also accepted and automatically translated to snake_case.
Recognised values are:
Constraint-based
"fast_iamb" – Fast-IAMB algorithm. See fast_iamb() and the underlying bnlearn::fast.iamb().
"gs" – Grow-Shrink algorithm. See gs() and the underlying bnlearn::gs().
"iamb" – Incremental Association Markov Blanket algorithm.
See iamb() and the underlying bnlearn::iamb().
"iamb_fdr" – IAMB with FDR control algorithm. See iamb_fdr() and the underlying
bnlearn::iamb.fdr().
"inter_iamb" – Interleaved-IAMB algorithm. See inter_iamb() and the underlying
bnlearn::inter.iamb().
"pc" – PC-stable algorithm. See pc() and the underlying
bnlearn::pc.stable().
paramsA list of extra tuning parameters stored by set_params()
and spliced into the learner call.
knowledgeA list with elements whitelist and blacklist
containing prior-knowledge constraints added via set_knowledge().
new()Constructor for the BnlearnSearch class.
BnlearnSearch$new()
set_params()Set the parameters for the search algorithm.
BnlearnSearch$set_params(params)
paramsA parameter to set.
set_data()Set the data for the search algorithm.
BnlearnSearch$set_data(data)
dataA data frame containing the data to use for the search.
set_test()Set the conditional-independence test to use in the search algorithm.
BnlearnSearch$set_test(method, alpha = 0.05)
methodA string specifying the type of test to use. Can also be a user-defined function with signature
function(x, y, z, data, args), where x and y are the variables being
tested for independence, z is the conditioning set, data is the dataset, and args is a list of additional
arguments. The function should return the test statistic and the p-value.
See bnlearn::ci.test() for more details.
EXPERIMENTAL: user-defined tests syntax are subject to change.
alphaSignificance level for the test.
set_score()Set the score function for the search algorithm.
BnlearnSearch$set_score(method)
methodCharacter naming the score function to use.
set_alg()Set the causal discovery algorithm to use.
BnlearnSearch$set_alg(method, args = NULL)
methodCharacter naming the algorithm to use.
argsA list of additional arguments to pass to the algorithm.
set_knowledge()Set the prior knowledge for the search algorithm using a Knowledge object.
BnlearnSearch$set_knowledge(knowledge_obj)
knowledge_objA Knowledge object containing prior knowledge.
run_search()Run the search algorithm on the currently set data.
BnlearnSearch$run_search(data = NULL)
dataA data frame containing the data to use for the search.
If NULL, the currently set data will be used, i.e. self$data.
clone()The objects of this class are cloneable with this method.
BnlearnSearch$clone(deep = FALSE)
deepWhether to make a deep clone.
### bnlearn_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 = "bnlearn", test = "fisher_z", alpha = 0.05)
result <- my_pc(num_data)
# or
result <- disco(data = num_data, method = my_pc)
plot(result)
# Example with detailed settings:
my_pc2 <- pc(
engine = "bnlearn",
test = "mi_g",
alpha = 0.01
)
disco(data = num_data, method = my_pc2)
# With knowledge
kn <- knowledge(
num_data,
starts_with("X") %-->% Y
)
disco(data = num_data, method = my_pc2, knowledge = kn)
# Using additional test args (bootstrap samples)
my_iamb <- iamb(
engine = "bnlearn",
test = "mc_zf",
alpha = 0.05,
B = 100
)
disco(data = num_data, method = my_iamb)
# Using R6 class:
s <- BnlearnSearch$new()
s$set_data(num_data)
s$set_test(method = "fisher_z", alpha = 0.05)
s$set_alg("pc")
g <- s$run_search()
plot(g)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.