CLGLearner.independenceStatistic
- CLGLearner.independenceStatistic(X, Y, Z)
Compute the terms of the r-centered statistic of X and Y given Z, stored in
r_XYZ.The values of X and Y (their residuals given Z when Z is not empty) are centered; each term is \(x_i y_i / \max(|x_i|, |y_i|)^2\), between -1 and 1, and the statistic is their mean.
- Parameters:
X (
int) – id of the first variable tested.Y (
int) – id of the second variable tested.Z (
set[int]) – The conditioned variable’s id set.
- Return type:
None
Example
import pyagrum as gum
import pyagrum.clg as gclg
gum.initRandom(42) # the draws of pyagrum.clg come from the random generator of aGrUM
clg = gclg.SEM.toclg("""
A = 0[1]
B = 2A[1]
C = -1.5B[1]
""")
gclg.ForwardSampling(clg).makeSample(2000).tocsv("data.csv")
learner = gclg.CLGLearner("data.csv")
learner.independenceStatistic(0, 1, set()) # stored in learner.r_XYZ
r = learner.r_XYZ[(frozenset({0, 1}), frozenset())]
round(float(r.mean()), 2) # the r-centered statistic of A and B (0 when they are independent)
# 0.33
Class