API reference

andrey.core.ci_regression.GCM#

class andrey.core.ci_regression.GCM(data, *, regression='boosting', seed=None)[source]#

The generalized covariance measure (GCM): the normalized covariance of two residuals.

Each query regresses x and y on the conditioning set and tests whether their residual products have zero mean, as when x and y are conditionally independent and the regressions are accurate enough.

Parameters:
  • data (ndarray) – Observed data, one row per sample. Each column is standardized to unit variance.

  • regression (str) – The regression of each variable on the conditioning set. "boosting" uses boosted trees with depth (1, 3, 4, 5, or 6) and rounds (up to 50, learning rate 0.3) minimizing 10-fold cross-validated error, the authors’ default grid; unpenalized leaf values, unlike their shrinkage, can leave smaller residuals. "forest" uses a random forest of 500 trees; "linear" uses ordinary least squares. "boosting" favors conditional means it can learn from the data, nonlinear and of several variables; it gives up time, 51 boosted fits per regression. "linear" favors time, one fit; it gives up the level where a nonlinear conditional mean leaves a covariance in the residuals, which then reads as dependence (see Limitations). "forest" favors nonlinear means without tuning; it gives up time, 500 trees per regression. The three were not measured against each other.

  • seed (int | None) – Seed for the cross-validation folds of "boosting" and the trees of "forest". None uses ANDREY_SEED, or 0 when it is unset.

Raises:

ValueError – If data is not 2-D, has fewer than 4 rows, contains NaN or infinity, or has values too large or too small to standardize, or regression is not one of the choices.

Notes

When to use. For continuous data whose variables depend on the conditioning set through a regression the chosen method can learn, such as a smooth nonlinear function plus noise, at hundreds to thousands of rows [1]. The test keeps its level whenever the product of the two regressions’ errors shrinks faster than one over the number of rows, whatever the noise’s distribution [1]. It detects a conditional covariance of x and y; a dependence that leaves their conditional covariance zero at every value of the conditioning set is the target of "wgcm".

How it works. For a conditioning set z, x and y are each regressed on z and R_i is the product of their residuals at row i. The statistic is sqrt(n) times the mean of R over its standard deviation (dividing by n), and the p-value is twice the standard normal tail beyond its absolute value [1]. An empty conditioning set uses x and y minus their means. A residual depends only on the variable and the conditioning set, so it is kept on the test object and reused by every later query on the same pair of them. Each column is standardized and rounded to 9 decimal places, and the folds and the trees are drawn over the rows in lexicographic order of the variable and the conditioning set alone, so the p-value does not change with the row or column order, with columns outside the query, or with a column’s units or sign. The exceptions: a change of units that moves a value across the rounding, and a sign flip of a column whose sorted values equal their negation’s, such as a balanced -1/1 column, which no value of the column orients. Products that are all zero give the statistic 0 and the p-value 1; products that are one nonzero constant, a covariance without noise, give an infinite statistic and the p-value 0.

Limitations. No benchmark campaign yet; the tests run it on up to 4 variables and 400 rows. A "boosting" regression fits 51 boosted models, once per variable and conditioning set. Its level depends on the regressions: a conditional mean the method cannot learn, such as a function of several variables of z jointly under "linear", leaves a covariance in the residuals and reads as dependence. At a few hundred rows, where the conditional means are hard to learn, the test rejects a true independence more often than its level, as the weighted GCM’s paper reports for it at 100 and 200 rows [2]. With "boosting", pooled over draws of 12 null designs at 200 and 400 rows (those of [1] and [2], and example 7 of [2] without its dependence), it rejected about 6.3% at 0.05 (6.4% and 7.6% in two runs on the designs of [2]), from 4 to 11% by design, and about 9% on the one-dimensional null of [2] at 200 rows. With an empty conditioning set the test is a test of correlation: a dependence without one, such as y = x**2 for a symmetric x, goes unseen.

References