API reference

andrey.core.ci_regression.PCM#

class andrey.core.ci_regression.PCM(data, *, regression='additive', n_splits=6, seed=None)[source]#

The projected covariance measure (PCM): whether one variable improves the prediction of another given the conditioning set.

One half of the rows learns how y depends on x beyond the conditioning set, as a function of both; the other half tests the covariance of that function with y, both after regressing out the conditioning set. The statistic is averaged over several random splits.

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

  • regression (str) – The regressions of the test. "additive" fits an additive model, one penalized thin plate regression spline [2] per predictor with floor((N - 1) / d) basis functions for N rows and d predictors, its smoothing chosen by generalized cross-validation [3], and fits the conditional variance through the log link with half as many basis functions, the regressions of the paper’s additive settings [1] (Section 6.1) as the authors’ code fits them; it holds the level where the conditional means are sums of smooth functions of one variable each and fits only the additive part of an interaction. "forest" is a random forest of 500 trees that tries every predictor at each split and leaves nodes of 5 rows or fewer unsplit, as the authors’ code does for its random-forest experiments; it learns interactions and loses the level where a conditional mean on z is hard to learn from a few hundred rows (see Limitations). "boosting" and "linear" are as for GCM. "additive" favors the level where the conditional means are additive: on the null of the paper’s Section 6.1 (seven conditioning variables, 500 draws per size) it rejected 0.4% at 0.05 with 250 rows and 0.2% with 500. It gives up interactions, rejecting 97.6% of the Section 6.2 null at 500 rows, and time as the rows grow. "forest" favors interactions: it rejected 34.4% of that null at 500 rows, where no regression measured held the level, and 4.0% of 50 draws at 10,000. It gives up the Section 6.1 null, rejected in 99.9% of draws at 250 rows and 97.3% at 500, as "boosting" rejected 97.7% at 250. "linear" and the time of the four were not measured against each other.

  • n_splits (int) – The number of random sample splits whose statistics are averaged, at least 1.

  • seed (int | None) – Seed for the sample splits, 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 12 rows, contains NaN or infinity, or has values too large or too small to standardize, regression is not one of the choices, or n_splits is below 1.

Notes

When to use. For continuous data at a few hundred rows where, with the default additive regression, the conditional mean of each variable is a sum of smooth functions of one variable each: of z for both variables, and of x and z for the response [1]. It tests conditional mean independence, which conditional independence implies, and keeps its level whenever the regressions on the conditioning set are accurate enough, whatever the regression that learns the dependence [1]. An interaction, such as a product of two variables, is outside the additive model: in the mean given z it can break the level, and between x and z the test sees only its additive part.

How it works. Of a query’s two variables, the one with the larger tie_ranks() rank within the query’s columns is the response y and the other the predictor x, so the direction depends on the values of those columns and not on the column order, the argument order, or the other columns. Each split puts half of the rows, at random, in the first part [1] (Algorithm 1). On the first part, y is regressed on (x, z) to give g; g~ is the part of g that x carries, the x term of an additive g and g itself under the other regressions; g is regressed on z to give m, and h = g~ - m takes the sign of the mean of (y - g + h) h. The squared residuals of g are regressed on (x, z), through the log link under "additive" (the penalized gamma deviance, smoothed by the generalized cross-validation score of the deviance), and the fit’s positive part, plus the smallest constant c that brings the mean of the squared residuals over it to at most 1, is the conditional variance v, at least 0.01. On the second part, f = h / v and y are each regressed on z, and the statistic is the GCM statistic of the products of their residuals. The n_splits statistics are averaged and the p-value is the standard normal tail above the average, the one-sided test of Algorithm 1DR with its threshold at the normal quantile [1]. The reported statistic is the average or 0, whichever is larger. A split whose products are all zero adds 0, and one whose products are one nonzero constant an infinity of its sign. The splits are drawn from seed over the rows in lexicographic order of the query’s own columns, so they do not depend on other columns. An additive fit with fewer than 3 basis functions for some predictor, too few rows or distinct values, is the least-squares line, as is one whose smoothing search fails; a variance fit through the log link without a minimum, or with a squared residual of 0, uses the identity link with the same basis.

These measurements use the paper’s y as response, as the paper does; the rank rule selects it in about half the draws on those designs, and the reverse direction was not measured. Where the paper and authors’ code differ, Andrey uses:

  • m regresses g, as in the authors’ code; the paper regresses g~, which in the measurements had more power in the paper’s first setting at 250 rows (71.6% against 54.8%) and almost none in its third at 500 (1.0% against 13.4%), below the authors’ code (7.6%).

  • The variance fit has half the basis functions of the mean fits, as in the authors’ code; the paper’s full basis changed 28 of 4,500 decisions and took about 2.5 times as long.

  • The variance adds c to the fit’s positive part, as in the paper; the authors’ code adds it first, the same for a forest, whose fit is never negative, and less powerful with least squares.

  • The standard deviation divides by the second part’s row count m, as in the paper; the authors’ code’s m - 1 shrinks each split’s statistic by the factor sqrt((m - 1) / m), which in the measurements turned a few rejections near the level into acceptances and changed no other decision.

Limitations. On the null design of the paper’s Section 6.1 (seven conditioning variables, 500 draws per size), the default rejected a true independence at 0.05 in 0.4% of draws at 250 rows and 0.2% at 500 (the authors’ code with the same regressions: 0.6% and 0.2%), and in the paper’s three alternative settings its power was at or above the authors’ code’s on the same data, for example 54.8% against 48.8% in the first setting at 250 rows and 13.4% against 7.6% in the third at 500. On the null of Section 6.2, whose conditional means hold an interaction, it rejected 97.6% at 500 rows (the authors’ code 95.6%); the paper runs that design from 10,000 rows, where "forest" rejected 4.0% of 50 draws, and no regression measured holds it at 500 (the forest rejected 34.4%). The tree regressions fail the Section 6.1 null, where x nearly copies the conditional mean of y on z: "forest" rejected 99.9% at 250 rows and 97.3% at 500, "boosting" 97.7% at 250. A query on nine columns takes about 7 s at 250 rows, 29 s at 500, and 6 minutes at 1,000 on one core, so a PC search, which runs a query for each pair and conditioning set it tries, is slow. The variance floor of 0.01, in units of the standardized response, is the authors’ code’s value; the paper sets none. The test detects a dependence of the mean of y on x; one that changes only the spread of y goes unseen, as does a dependence of the mean of x on y that leaves the mean of y unchanged. Which variable is the response follows a rule on the data that has nothing to do with the causal question, so swapping the roles can change the answer.

References

static least_rows(size, **options)[source]#

The fewest rows a query given size conditioning variables is tested on: 12, so each half of a split holds the 6 rows a forest splits and the learned function can vary.

Return type:

int