Condition on What the Client Already Knows
TL;DR
In a factory’s sensor data, the strongest predictor of scrap was the ball type: already known, and not something the client can change. So instead of asking which signals predict scrap, we asked which are linked to scrap once the ball type is known. Five methods answered, and after correcting for testing twelve signals, none found evidence of such a link. The methods miss different kinds of link, so together they cover more kinds than any one of them. The one method that tests each signal on its own also bounds what it didn’t find: for eleven of the twelve signals, the data rule out an average within-type slope steep enough to matter.
The problem
The factory
On a current data science project, a client wants to know where its scrap comes from. To protect the client, everything in this post is fictional: the factory, the balls, the signals, and every number and figure. What carries over from the real project is the structure of the problem, the methods, and the shape of the result.
A factory makes balls: footballs, volleyballs, basketballs. Every order runs through the same four machines, M1 to M4, one after the other, and each machine records three signals, such as a temperature, a spin speed or a pressure. Some balls come off the line below standard and are thrown away. That is the scrap.
Orders of three ball types pass four machines. Each machine records three signals, twelve in all, to . At the end, some balls are scrap.
We look at orders, not single balls. Each order has a ball type , a scrap rate , the share of its balls thrown away, and a value for each signal , its average over the time the order was on the line. There are orders: 180 of footballs, 140 of volleyballs and 80 of basketballs. Within a ball type, the scrap rate varies from order to order with a standard deviation of about 0.6 percentage points.
The obvious answer
One thing predicted scrap well: the ball type. Basketball orders lose 4.9% of their balls on average, volleyballs 3.2%, footballs 1.8%. With the 0.6-point spread within types, that puts about 80% of the variance of the scrap rate between ball types and 20% within them.
The client knew that already, and can’t act on it: an order for basketballs has to be filled with basketballs.
The ball type also gets in the way. The machines run differently for each ball type, so nearly every signal tracks the ball type, and through it, scrap. Ask which signals predict scrap, and the data keeps answering with the ones that give away the ball type.
Across all orders, a hotter M2 goes with more scrap. Within each ball type, scrap shows no trend with temperature: the trend across all orders is the ball type.
The question we asked instead
The question is not whether predicts , but whether it says anything about that doesn’t already: is the signal independent of scrap given the ball type,
Because takes only three values, this reads concretely: among basketball orders, says nothing about scrap, and the same among footballs and among volleyballs.
The ball type drives both the signals and the scrap rate. The question is whether a signal is linked to scrap beyond that.
A signal for which the data reject this independence is a candidate source of scrap, not yet a cause. A change of shift could move both the signal and scrap, or the signal could sit downstream of the defect: a ball damaged at M2 can still look different to a sensor at M4.
The methods
What independence implies
Conditional independence is a statement about whole distributions. For every ball type , signal value and scrap rate ,
That is rarely what gets tested directly. Most methods test something it implies, usually one of these two:
-
The best prediction doesn’t change. Once the ball type is known, knowing the signal doesn’t improve the best prediction of scrap. Which prediction is best depends on the error you measure: the conditional mean minimises the expected squared error, the conditional median the expected absolute error. For the mean:
-
The conditional covariance is zero. Within each ball type, signal and scrap are uncorrelated:
Independence gives the first, for the mean and the median alike, since both are read off the conditional distribution above. The second follows from the mean version of the first. The covariance given the ball type is
so it is zero when the first term equals the second, and it does:
- Average in two stages. First average over orders with the same signal value and ball type, then over the signal values. Given and , is known, so only is replaced by its average.
- The first implication. : the signal doesn’t move the mean.
- Take out what is known. depends on only, so given it is a fixed number and moves outside the average. In its simplest case, : averaging twice given the same thing is averaging once.
Neither step reverses, so either implication can hold while the signal still matters:
- Zero covariance, but the mean moves. Scrap often rises when a temperature drifts from its set point in either direction. Within a ball type that is a U, and if both the U and the spread of the temperature around the set point are symmetric, the covariance is zero. A correlation sees nothing; the conditional mean does.
- The same mean, but not the same distribution. A signal can make scrap more erratic from order to order without moving its average. A comparison of mean predictions sees nothing. For the client this case matters less: they pay for the expected scrap, which a change in spread leaves alone.
A hypothetical signal, for basketball orders: scrap rises as the temperature leaves its set point either way. The best straight line is flat, so the covariance is about zero; the conditional mean is not flat.
Five methods and what each tests
We answered the question five ways. Write for all signals together and for all of them but . For order , write for its scrap rate, for its ball type, and for the average scrap rate of the orders of ball type .
Every method that needed a regression model ran with three learners: XGBoost, a random forest, and TabICL, a pretrained transformer for tables that predicts from the training rows in context instead of being fitted to them.
TabICL is the least familiar of the three. It was built for classification, pretrained on synthetic tables only, and its second version adds regression. For this analysis it has three properties the trees lack. Nothing is fitted per fold: each fold is a new context, so cross-validation costs only predictions, and there is next to nothing to tune on the folds that score it. It returns a predictive distribution, so one model gives both the median the model comparison scores and the mean the residual model needs. And it learns differently: two tree ensembles that agree may share a bias, so a transformer that agrees with them adds more confidence than a third tree would. The price is explanation. SHAP has no exact algorithm for it as it has for trees, so its importances are sampled approximations, and a shuffled test row asks it about an order unlike any in its context.
| Method | Tests |
|---|---|
| Feature importance: SHAP and permutation importance of a model of on | , a neighbouring question |
| Model comparison: models of on and on that predict the median, scored on absolute error | |
| Residual model: a model of on | |
| Models per ball type: a model of on for each ball type | for each |
| GCM: the generalised covariance measure, for each signal |
The residual model and the models per ball type test the same equation, , written two ways; the model comparison tests its median version. All three take the signals together. Each of their equations holds if , which implies for every , but not conversely: two signals can be linked to scrap together while each alone is independent of it. So a rejection by these three would say that the signals together are linked, not which one, and perhaps no single one. They differ in how they estimate the equation, and so in how much noise they carry. Only the GCM takes one signal at a time, and feature importance answers a neighbouring question.
Feature importance asks whether a model of on uses . For a perfect model, that is whether changes with while the other signals stay fixed: whether adds anything to the other signals, not to the ball type alone. That is a neighbouring question, not an implication of ours, and the two differ in both directions. Two thermometers on one machine make each other redundant, so each can score low while both are linked to scrap. And a signal independent of scrap given the ball type can score high. Say a thermometer reads too high on hot days, while the machine’s true temperature, which drives scrap, doesn’t depend on the weather. If the outside temperature is recorded, a model uses it to correct the thermometer, although it is independent of scrap given the ball type.
Importance also comes with no threshold, and it measures something else again: how much a fitted model relies on a signal, not how much the signal helps it predict new orders. An overfitted model can rely on a signal that costs it accuracy on held-out orders. And permutation importance, which usually shuffles across all orders, can make a stand-in for the ball type look important: the shuffle breaks the signal’s link to the ball type too, and asks the model about orders that never occur, a basketball order at a football’s temperature. What the model does there is extrapolation, not information. Shuffling within each ball type avoids that, and on held-out orders it gives an exact test, but of , which is stronger than ours: a signal correlated with another within a ball type can be rejected although . Permuting only among orders with similar as well, as the conditional permutation test does, targets instead, the importance question made into a test.
The model comparison scores the model on against the model on alone, by absolute error on held-out orders. Each model predicts a conditional median: XGBoost and the random forest are fitted to minimise absolute error, and TabICL is asked for the 0.5 quantile of its predictive distribution. So the comparison tests the median version of the first implication. Absolute error keeps a few badly scrapped orders from dominating the scores. The orders must be held out: on the orders they were fitted to, the model with more inputs looks better whether or not the inputs matter. A third model, on alone, shows how much of the ball type the signals carry.
The comparison is paired: both models predict the same held-out orders, so we took the difference of their absolute errors order by order, and gave its mean a bootstrap interval and a Wilcoxon signed-rank test. That paired p-value is only a guide, for two reasons. Under the null, the two models’ predictions converge, and tests of nested models are known to be badly calibrated there. And the best of several learners, picked on the same folds that score it, looks better than it is, the selection bias of model selection. So we read the comparison learner by learner, not for the winner, and left the calibrated test to the GCM below.
The residual model removes the ball type first. With three ball types, the best prediction from the ball type alone is the average per type, so the residual estimates . The first implication says nothing should predict it. A second model, on , tries anyway. Unlike the model comparison, it doesn’t have to relearn the ball type, and it isn’t judged by the difference between two noisy scores: plotted against the actual residuals of held-out orders, its predictions show the answer at a glance.
Regressing on residuals is old: it is Robinson’s (1988) partialling out, and predicting residuals to test a model is the residual prediction test of Shah and Bühlmann. Two details keep it honest. The type averages are computed on the training folds only, so a held-out order never sees its own scrap rate. And a second stage fitted to residuals always finds something: even without new inputs, it picks up noise and whatever the first stage got wrong. So we also fitted a placebo second stage that sees only the ball type, the same idea as the shadow features of Boruta. The signals count only for what the real second stage learns beyond the placebo. Two numbers read the plot: the correlation of the predictions with the residuals, and the slope of the residuals on the predictions, which is 1 for a calibrated second stage and near 0 for one that predicts noise.
The models per ball type condition on by construction. Each sees orders of one ball type only and is scored, by squared error on held-out orders, against that type’s average scrap rate, so it can only find what the signals add within the type. Comparing them shows whether the signals matter in every ball type or in one. The price is fewer orders per model: the basketball model learns from 80.
A test per signal
Conditional independence is hard to test in general. Shah and Peters (2020) show that when has a joint density, which requires to be continuous, a test that rejects at most 5% of the time under every such distribution with also rejects at most 5% of the time under every such distribution without it, at any sample size. Every practical test buys its power with assumptions about how and depend on .
With three ball types, that problem doesn’t arise: the question splits into one ordinary independence question per ball type, . With a continuous , such as the date, it does: the averages per ball type below become regressions of and on , and the test is only as good as those regressions. A random forest can fit them, on other folds than the ones it predicts, the cross-fitting of double machine learning. Cross-fitting removes the bias a regression has on its own training rows, but not the bias of errors the two regressions share. The test stays valid only if the product of the two regressions’ errors shrinks faster than (Theorem 6 of the paper). Nobody can prove that from the data, but the residuals can be checked: if what is left of or of still depends on , the regression missed something. With three ball types, each average is off by about , the product by about , and the condition holds.
The same paper proposes the test we used, the generalised covariance measure (GCM). With a categorical it is short. Fix a signal and write for its value in order and for its average over the orders of ball type . The sample quantities below, from to , belong to this one signal, so they carry no index . Subtract each order’s ball-type averages, multiply, and check whether the products average to zero:
where and are the mean and standard deviation of . If , then for large , is approximately standard normal: its p-value is , with the standard normal distribution function, and rejects at the 5% level.
estimates the covariance within ball types, averaged over them with weights :
is in units of the signal times percentage points. Divided by the signal’s standard deviation within ball types, , with , it becomes comparable across signals measured in degrees, revolutions per minute and bar:
is the least-squares slope of on , times . On that line, an order whose signal lies one within-type standard deviation above its type’s average has a scrap rate percentage points above its type’s average. If the three ball types share one slope, estimates it, in these units; if not, the average of the three slopes weighted by . The interval is an approximate 95% confidence interval for , and it excludes zero exactly when the GCM rejects.
The GCM tests the covariance implication, averaged over ball types, so it misses any link whose average covariance is zero. The U is one: its covariance is zero within each ball type. The average adds another: covariances of opposite sign in different ball types can cancel.
A hypothetical signal, with each order centred on its ball type’s averages. Scrap rises with the temperature in footballs and falls in volleyballs. The covariances cancel, so the common slope, and with it the GCM, sees nothing; a model per ball type sees both slopes.
A GCM per ball type would close the second gap: compute from the orders of ball type alone, and compare with a distribution with three degrees of freedom, which it approximately follows under the independence. We relied on the models per ball type instead.
The first gap can be narrowed in the same machinery. Run each signal a second time as its distance from its ball type’s median, : a U around the set point is a straight line in that distance, and the GCM sees it. It costs twelve more tests. The general fix is the projected covariance measure of Lundborg, Kim, Shah and Samworth: it learns on half the orders which function of the signal predicts scrap, then tests the covariance of that function on the other half, and so finds any link that moves the conditional mean.
Three more choices make the GCM’s p-values hold up on orders from a factory.
- Dependent orders. assumes the products are independent. Orders run on the same day share the weather, the shift and the state of the machines, so their products are correlated and is too small. A variance clustered by day, or a Newey–West variance over orders sorted by start time, accounts for that. Where the averages are fitted on other folds, the folds are contiguous blocks of time, not random orders.
- A check of the null. Shuffling a signal within each ball type makes it independent of scrap given the type, by construction. Run the shuffled signals through the same test: their should be standard normal. If they spread wider, the p-values are too small, and the spread says by how much.
- Many signals. Before testing, signals that are near copies of each other, with a correlation above 0.99 within ball types, are one test, not two: test the one recorded on more orders. Twelve tests at 5% give 0.6 rejections by chance. Benjamini–Hochberg bounds the share of false rejections among the rejections, and it stays valid when the tests are positively dependent, as tests of correlated signals are. Neither correction helps against twelve links each too small to reject. The GCM paper’s joint version does: it takes over all signals and calibrates it with a multiplier bootstrap, which keeps the dependence between the tests.
Where the GCM and the models differ
Small links
As grows, settles at and at some , so grows like : any average covariance that isn’t exactly zero is eventually found. With our 400 orders, the GCM finds a link with , in percentage points of scrap per within-type standard deviation, four times out of five.
A rule of thumb gives about that number. For a weak straight-line link, , with the correlation of signal and scrap within ball types. A two-sided test at 5% rejects four times out of five once , so at and . What a link is worth grows differently: the best straight-line use of the signal lowers the squared error within ball types by the share , whatever is. So significance grows with and value doesn’t; with enough orders, a link worth nothing is significant.
A model has a harder job with the same orders: it has to find that link among twelve signals without knowing its shape, while the GCM estimates one number per signal. And a ranking of importances puts a small link at the bottom, next to the signals with no link at all, with nothing to tell them apart. The GCM reports with an interval; whether a slope of that size is worth acting on is the client’s call.
Correlated signals
Feature importance divides credit among the inputs of one model, and how correlated signals share it depends on the learner: a random forest tends to spread credit over all of them, while XGBoost tends to pick one and leave the rest near zero. SHAP explains whichever model it is given, so it inherits the split, and whether it should split credit by the model or by the data is a choice of its own. Tree importances also favour signals with many possible splits. Permuting all signals of one machine together, a grouped permutation importance, asks about the machine instead: if the group’s importance is smaller than the sum of its members’, they carry the same information.
Credit and contribution can even point opposite ways. An overfitted learner spends its splits on noise in the signals and gives them credit for it, and the same signals then cost it accuracy on held-out orders: the learner that credits the signals most can be the one they hurt most. So we read each learner’s importances next to its own held-out comparison. Credit that no held-out gain backs says how the learner works, not where scrap comes from.
The GCM doesn’t have this problem. Each test conditions only on the ball type, so correlated signals don’t compete. The flip side is that both of two correlated signals are flagged, like the two thermometers above. Asking which of them matters means conditioning on the other signals too, , and since they are continuous, that brings back the hardness result above.
Why five methods
Each method misses some kinds of link, and a null result from one method leaves its blind spot open. Here a small link is too weak for the models: it lowers the model comparison’s held-out mean absolute error by less than the standard deviation of the per-fold difference between two models, about 0.015 percentage points. For a straight-line link, that means below about 0.15. The GCM finds a link four times out of five from about .
| Can it find… | Importance | Comparison | Residual | Per type | GCM |
|---|---|---|---|---|---|
| a small link with | No | No | No | No | Yes |
| a large link with zero covariance within each type, like the U | Yes | Yes | Yes | Yes | No |
| a large link whose covariances cancel across types | Yes | Yes | Yes | Yes | No |
| a small link with | No | No | No | No | No |
| a link only in the spread, with mean and median unchanged | No | No | No | No | No |
| which signal is linked | No | No | No | No | Yes |
A Yes for a model-based method assumes that at least one of the three learners can fit the link’s shape. Feature importance does name signals, but the ones a model uses given the other signals, which can differ from the linked ones in both directions. The comparison, the residual model and the models per ball type see the same kinds of link in this grid, the comparison through the median and the other two through the mean; they differ in how much noise they carry, so each checks the others. Two kinds of link have no Yes: one only in the spread matters less to the client, as above, and the small one with is listed below. The distance probes above turn the GCM’s No for a symmetric U into a Yes, and the joint test adds power against many small links at once.
The methods also differ in what they measure, not only in what they miss: the GCM a covariance, the comparison and the per-type models a gain in held-out error, the residual model a learned correction, and feature importance what a fitted model relies on. A signal can be significant without any model gaining from it, and a model can rely on a signal that gains nothing. So we gave weight only to what several methods showed. A finding that only one method shows tells you about that method more than about the factory, unless it falls in the others’ blind spots.
The order of reading follows: first the methods that test all signals together, then the GCM per signal. If the block of signals adds nothing to the held-out error, a single signal that the GCM flags is a small link worth a look, not a lever.
The result
What we found
After correcting for testing twelve signals, none of the five methods found evidence that a signal is linked to scrap beyond the ball type. The three learners agreed for every method that used them.
- Feature importance: in each of the three models, the ball type took about 90% of the total absolute SHAP value, and no signal more than 2%. Shuffling any one signal within its ball type raised the held-out error by less than 0.005 percentage points.
- The model comparison, with five-fold cross-validation, gave a held-out mean absolute error of 1.08 percentage points with no inputs, 0.48 with the ball type alone, 0.49 with the ball type and the signals, and 0.51 with the signals alone. Per fold, adding the signals to the ball type raised the error by 0.01 on average, with a standard deviation of 0.015. On their own, the signals came close to the ball type because they carry it.
- The residual model’s predictions for held-out orders had a standard deviation of 0.08 percentage points, against 0.6 for the residuals they tried to predict, and were uncorrelated with them: their squared error was about 2% higher than that of predicting zero, no better than the placebo’s.
- The models per ball type had a held-out squared error 0% to 3% above that of their type’s average scrap rate, in all three ball types, so there was nothing to compare across types.
- The GCM rejected one of the twelve signals at the 5% level: , a spin speed at M3, with . With twelve tests, 0.6 such rejections are expected by chance if no signal is linked. After a Bonferroni correction for twelve tests, which holds however the tests depend on each other, its p-value is ; Benjamini–Hochberg gives the same. Neither the joint test over all twelve signals nor any of the twelve distance probes rejected. The shuffled signals’ spread as a standard normal should, and a variance clustered by day left the conclusion unchanged.
Held-out error of each learner’s models on the signals, with and without the ball type, minus that of the same learner on the ball type alone, with 95% bootstrap intervals over orders. Right of zero is worse.
Held-out orders. A link would tilt them towards the dashed line.
A flag from one method alone deserves a look before it is dismissed, if it falls in a blind spot of the others. ’s does: a small link with nonzero covariance is what the models miss. Its is 0.075, with a 95% interval from 0.01 to 0.14.
A test statistic that is an average can rest on a handful of orders. So the look starts with the orders behind it: drop the 5% of orders with the largest , and compute the test again. If the link runs through all orders, shrinks a little; if a few orders carry it, collapses. ’s collapses: without its 20 largest products, falls to 0.02 and from 2.3 to 0.6. Most of those orders lie far out on the signal, at spin speeds unusual for their ball type.
against scrap, each order centred on its ball type’s averages; a sample of the orders drawn. The slope through all orders is 0.075; without the 5% of orders with the largest products, it is 0.02.
A link carried by a few extreme orders can still be real, but it is a question about those orders, for the people who ran them, not a slope to act on. One more check is open: a signal and scrap that both drift over months correlate within ball types without any link between them. Shifting by a week, a month and two months and testing again would separate the two: a real link stands out among the shifted copies, a shared drift survives the shift.
What no evidence means
The GCM also bounds the links it didn’t find. The client set the bar for a signal worth acting on at : 0.15 percentage points of scrap per within-type standard deviation of the signal, a quarter of the 0.6-point standard deviation of scrap between orders of one ball type.
and its 95% interval for each signal, grouped by machine. The shaded band holds slopes too small to act on. ’s is the only interval that excludes zero, the one rejection before correction; ‘s reaches past the band.
Eleven of the twelve intervals lie inside the band, ‘s included: for each of those signals on its own, the data rule out at 95% confidence. This is an equivalence test: a 95% interval inside the band rejects both and at 2.5% each, which turns a failure to reject into a bound. The bar was set before any interval was read; one chosen after would bound nothing. If ‘s link is real, it is too small to act on. , a pressure at M4, has a few orders with extreme values that make its interval wide, from −0.20 to 0.14, so the data can’t rule out a link that matters there.
What the null leaves open:
- . More orders, or a look at its extreme orders, would narrow its interval.
- Slopes of opposite sign in different ball types. averages them, so the bound doesn’t cover them; the models per ball type would have found large ones.
- Small links with zero average covariance. The bound covers only, and the models miss small links of any shape. More orders would help the models; the GCM misses such a link at any .
- Causes no sensor measures. The raw material, or handling between machines. If scrap comes from there, no analysis of the recorded signals will find it, unless it leaves a trace in them.
On held-out orders, no model predicted any of the variance of scrap within a ball type. That variance comes from something the signals don’t measure, from links too small or oddly shaped for these methods, or from chance; a straight-line link just below the client’s bar would account for about 6% of it. So the next place to look is outside the twelve signals: what isn’t measured yet, and how much of the spread is chance.
The general move
The strongest predictor is often something the client already knows and can’t change: the product, the site, the season. Reporting it again is easy and worthless. Condition on it, and ask what is left. Sometimes the answer is nothing the data can see, and that is worth knowing too.