API reference

andrey.core.ci_regression.WGCM#

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

The weighted generalized covariance measure (wGCM): the GCM of weighted residual products.

Multiplying the GCM’s residual products by a function of the conditioning set before testing their mean detects conditional covariance of x and y that changes sign and averages to zero.

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

  • variant (str) – "est" estimates one weight function on 30% of the rows and tests on the rest; "fix" tests 7 fixed weights per conditioning variable, each a sign along one variable, on every row and takes the largest statistic. "est" favors a learned weight whose number does not grow with the conditioning set; it gives up 30% of the rows, time, and, where measured, power. "fix" favors every row, half the time, power, and a steadier level; it gives up a learned weight. On the same 200 draws of each of the 7 alternative cells of [1] (example 7, 1D, and 10D.Add, at 200 and 400 rows), with "boosting" tuned as in GCM, "fix" rejected at 0.05 in 21 to 96.5% against 10.5 to 60.5%, more often in all 7, and in all 7 too at critical values from each variant’s null draws (15 to 95% against 10.5 to 52.5%); paired power was not measured under shipped tuning. With shipped "boosting" on the 12 null designs of Limitations, "est" rejected true independence at 0.05 in 4 to 13% by design against 4 to 8.6%, and queries at 200 to 400 rows took 21 to 26 s against 11 to 15 s.

  • regression (str) – The regression of each variable, and of the products of residuals, on the conditioning set. "boosting" is boosted regression trees whose learning rate (0.1, 0.2, 0.3, or 0.5), depth (1 to 7), and number of rounds (up to 500) minimize the 10-fold cross-validated error averaged over the folds, stopped 10 rounds after its best, the wGCM authors’ current default; the trees’ leaf values carry no penalty, where the authors’ boosting shrinks them, and the trees search every split point exactly, where the authors’ boosting grows them on histogram bins of each feature. "forest" and "linear" are as for GCM, with the same character, except that "boosting" fits 281 boosted models per regression. The three were not measured against each other.

  • seed (int | None) – Seed for the sample split of "est", the multiplier draws of "fix", 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 17 rows (4 for "fix"), contains NaN or infinity, or has values too large or too small to standardize, or variant or regression is not one of the choices.

Notes

When to use. For continuous data where x and y may depend on each other given the conditioning set with a conditional covariance that changes sign, which the GCM does not detect, at hundreds to thousands of rows [1]. Where the dependence is a covariance of one sign or the rows are few, "gcm" has more power [1].

How it works. For a conditioning set z, the residuals of x and y on z give the products R_i as for the GCM [2]. "est" (Method 1 of [1]) splits the rows at random, 30% to estimate and 70% to test. On the first part it regresses the products on z and takes that fit as the weight w(z); on the second part, with residuals from regressions on that part, the statistic is the GCM statistic of R_i w(z_i), and the p-value is the standard normal tail above it, one-sided because the weight points the covariance up. "fix" takes the constant weight and the signs of each variable of z about its empirical 1/8, …, 7/8 quantiles, normalizes each weighted product by its standard deviation, and the statistic is sqrt(n) times the largest absolute mean; its p-value is (b + 1) / 500, where b of 499 Gaussian multiplier draws of the same maximum over the centered columns, whose covariance is the products’ sample correlation, are at least as large [1]. An empty conditioning set has no weight to estimate, and both variants give the GCM’s p-value of x and y minus their means. The statistic reported for "est" is the statistic or 0, whichever is larger, so a larger statistic always means a smaller p-value. The weight of "est" is the fitted value, as in the authors’ code; the paper takes its sign. The draws of "fix" use the centered columns, as in the paper; the authors’ code leaves them uncentered. The split and the multiplier draws are drawn from seed over the rows in lexicographic order of the query’s own columns, so they do not depend on other columns.

Limitations. No benchmark campaign yet; the tests run it on up to 4 variables and 400 rows. "est" tests on 70% of the rows, and its p-value changes with the seed. A "boosting" regression fits 281 boosted models of up to 500 rounds, 28 settings on 10 folds and the chosen one on every row, so a query takes several times as long as the GCM’s; "est" runs five such regressions per query, its split being the query’s own. "fix" uses 7 weights per conditioning variable, so its maximum spreads over more of them as the conditioning set grows; on 10 conditioning variables (10D.Add of [1] at 200 rows) it still rejected more often than "est" (see variant). At a few hundred rows, where the conditional means are hard to learn, neither variant holds its level. With "boosting", pooled over draws of the paper’s null designs at 200 and 400 rows [1], "est" rejected a true independence at 0.05 in about 6.8% of draws and "fix" in 6.0% (6.8% and 6.5% on a second set of draws), up to 7.8% on one design for either; pooled over 12 null designs (those, further nulls of [2], and example 7 of [1] without its dependence), 6.6% and 6.4%, from 4 to 13% by design for "est", the most on the a = 4 null of [2], and from 4 to 8.6% for "fix".

References

static least_rows(size, *, variant='est', **options)[source]#

The fewest rows a query given size conditioning variables is tested on: 17 for variant="est", whose 30% part then holds the 6 rows a forest splits, else 4.

Return type:

int