1
$\begingroup$

so if I have a 3 columns of binary variables X, Y and Z with their respective values and I would like to determine whether X,Y are conditionally independent given Z. How can I go about doing this? Also how can I incorporate marginal independence (of two variables) into this equation?

Note: format is as such

X Y Z
1 0 1
0 0 1
1 1 0
etc...

and I want to output true if x,y are conditionally independent given z and false otherwise and I can test for marginal independence if I want to...

I know that P(Y|Z) - P(Y|X,Z) = 0 is one way but how would I calculate those values from the above...

Thank you.

$\endgroup$

1 Answer 1

1
$\begingroup$

"Conditional on Z" means within levels of Z. So for each level of Z, figure out whether X and Y are independent. X and Y are independent if the proportion of Y values that are equal to 1 is the same in each level of X.

Symbolically, $X \perp Y|Z \implies P(Y=1|X=1, Z=z) = P(Y=1|X=0, Z=z), \forall Z$

Some R/pseudocode:

c.ind = TRUE
for (z in unique(Z)) {
  if (mean(Y[Z==z & X==0]) != mean(Y[Z==z & X==1)) c.ind = FALSE
}
return(c.ind)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.