Generalized covariance measure statistic (source code)

= Generalized covariance measure statistic
{title2=$T$}

For observations $(X_i,Y_i,Z_i)$, estimate the <conditional means> $f(z)=\mathbb E[X\mid Z=z]$ and $g(z)=\mathbb E[Y\mid Z=z]$, and form residual products $R_i=(X_i-\widehat f(Z_i))(Y_i-\widehat g(Z_i))$. The univariate <generalized covariance measure statistic> is
$$
T=\frac{\sqrt n\,\overline R}{\sqrt{n^{-1}\sum_iR_i^2-\overline R^2}},\qquad \overline R=n^{-1}\sum_iR_i.
$$
The denominator is an estimated <standard deviation>, not the second moment itself, and must be positive. Under <conditional independence>, accurate nuisance regressions, suitable <moment> assumptions and a product-rate condition give a <standard normal> <limit>. The test detects residual <covariance>; conditional dependence with zero residual <covariance> can escape it. Its validity depends on regression quality rather than allowing arbitrary distributions with no restrictions.<The Hardness of Conditional Independence Testing and the Generalised Covariance Measure by Rajen D. Shah and Jonas Peters>[§3.1]{ref}