Perform an independence test using G-Square test 1. This test is based on the log likelihood ratio test.
from causallearn.utils.cit import CIT gsq_obj = CIT(data, "gsq") # construct a CIT instance with data and method name pValue = gsq_obj(X, Y, S)
Please be kindly informed that we have refactored the independence tests from functions to classes since the release v0.1.2.8. Speed gain and a more flexible parameters specification are enabled.
For users, you may need to adjust your codes accordingly. Specifically, if you are
running a constraint-based algorithm from end to end: then you don’t need to change anything. Old codes are still compatible. For example,
from causallearn.search.ConstraintBased.PC import pc from causallearn.utils.cit import gsq cg = pc(data, 0.05, gsq)
explicitly calculating the p-value of a test: then you need to declare the
gsq_objand then call it as above, instead of using
gsq(data, X, Y, condition_set)as before. Note that now
causallearn.utils.cit.gsqis a string
"gsq", instead of a function.
Please see CIT.py for more details on the implementation of the (conditional) independent tests.
data: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples and n_features is the number of features.
method: string, “gsq”.
cache_path. See Advanced Usages.
p: the p-value of the test
Tsamardinos, I., Brown, L. E., & Aliferis, C. F. (2006). The max-min hill-climbing Bayesian network structure learning algorithm. Machine learning, 65(1), 31-78.