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
ydepends onxbeyond the conditioning set, as a function of both; the other half tests the covariance of that function withy, 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 withfloor((N - 1) / d)basis functions forNrows anddpredictors, 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 onzis hard to learn from a few hundred rows (see Limitations)."boosting"and"linear"are as forGCM."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 least1.seed (
int|None) – Seed for the sample splits, the cross-validation folds of"boosting", and the trees of"forest".NoneusesANDREY_SEED, or0when it is unset.
- Raises:
ValueError – If
datais not 2-D, has fewer than 12 rows, contains NaN or infinity, or has values too large or too small to standardize,regressionis not one of the choices, orn_splitsis 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
zfor both variables, and ofxandzfor 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 givenzit can break the level, and betweenxandzthe 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 responseyand the other the predictorx, 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,yis regressed on(x, z)to giveg;g~is the part ofgthatxcarries, thexterm of an additivegandgitself under the other regressions;gis regressed onzto givem, andh = g~ - mtakes the sign of the mean of(y - g + h) h. The squared residuals ofgare 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 constantcthat brings the mean of the squared residuals over it to at most 1, is the conditional variancev, at least 0.01. On the second part,f = h / vandyare each regressed onz, and the statistic is the GCM statistic of the products of their residuals. Then_splitsstatistics 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 or0, whichever is larger. A split whose products are all zero adds0, and one whose products are one nonzero constant an infinity of its sign. The splits are drawn fromseedover 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
yas 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:mregressesg, as in the authors’ code; the paper regressesg~, 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
cto 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’sm - 1shrinks each split’s statistic by the factorsqrt((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, wherexnearly copies the conditional mean ofyonz:"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 ofyonx; one that changes only the spread ofygoes unseen, as does a dependence of the mean ofxonythat leaves the mean ofyunchanged. 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