The chi-squared distribution supplies a reference model for a test statistic when evaluating conditional independence. A library uses that assumption to calculate a p-value, then compares the p-value with a significance threshold such as 0.05. A higher p-value favors the null hypothesis of conditional independence; it does not establish the causal model as true. section 4.3.2
A practical conditional-independence workflow is:
- Specify variables X and Y, conditioning variables Z, observed data, and a significance level. section 4.3.2
- Run pgmpy’s chi_square test and inspect the chi-squared statistic, p-value, and degrees of freedom. section 4.3.2
- Repeat the test across d-separation statements and count the proportion that fail to support conditional independence. section 4.3.2
Transportation survey
Testing education and transportation while conditioning on occupation and residence returns a chi-squared statistic of 1.1611, p-value 0.5596, and 2 degrees of freedom. With significance 0.05, the Boolean result favors conditional independence. section 4.3.2
Listing 4.4 Chi-squared test of conditional independence
from pgmpy.estimators.CITests import chi_square #1
significance = .05 #2
result = chi_square( #3
X="E", Y="T", Z=["O", "R"], #3
data=data, #3
boolean=False, #3
significance_level=significance #3
) #3
print(result)
Shows the Python call that applies the chi-squared conditional-independence test. section 4.3.2
