Section 11.10

Confounding

Definition

Confounding is a defect of a comparison: a second factor, besides the condition being studied, differs between the compared groups and also affects the outcome, so the observed difference mixes the effect of the condition with the effect of that factor. The second factor is called a confounder. In performance experiments the time of measurement, the device, the workload and the background load are common confounders. Collecting more data of the same kind does not separate the two effects; only the design of the experiment, or an explicit assumption, can.

The idea

A new software version is measured only after the machine has warmed up §11.27: its caches, the small fast memories that hold recently used data, already hold the data the program needs. The old version was measured right after power-on. The new version looks faster. Two things changed together, the code and the warmup state, and the measurements contain only their combined effect. The warmup state is a confounder: it differs between the groups, and by itself it changes how long a request takes.

Two runners timed on different days, one with the wind behind and one against it, are a fair picture: the time difference mixes the runners’ speed with the wind. The picture stops where real experiments get harder: wind is easy to notice, whereas many confounders, such as a background task on the test computer, go unnoticed until someone looks for them.

The cleanest defense is a minimal contrast: conditions built to differ in exactly the one thing under study. Suppose the question is how much longer a request takes when a table of access-control §1.7 rules, each of which allows or denies some requests, denies it rather than allows it. Deleting the rule, so that a default decision applies, also changes the lookup: the table gets shorter, and the search ends without a match. Changing the default instead changes the decision for every request that no rule matches, not only for the one under study. Flipping only the byte that holds the rule’s decision leaves the table and the search path unchanged, so the two conditions differ only in the decision.

How it works

  1. List every factor apart from the condition that could change the outcome: the time and order of the runs, the warmup state, the device, the temperature, the input, the background load, the build options and the measuring instrumentation §14.24 itself.

  2. From the run records, check whether each factor took different values under the different conditions. A factor that differs between the conditions and affects the outcome is a confounder.

  3. Remove each confounder by design, in this order of preference: build a minimal contrast; hold the factor constant; block on it, so that every condition runs at every level of the factor (see the blocking §11.9 entry); randomize or interleave the order, so that the remaining factors cannot follow the condition systematically.

  4. If the design cannot remove a confounder, measure it and adjust for it: compare the conditions inside each level of the confounder, then combine. This needs overlap, meaning that every level occurs under both conditions, and it needs every confounder to have been measured.

A causal diagram helps with step 2. It is a directed acyclic graph §14.17 in which an arrow from one factor to another means that the first directly affects the second. In the warmup example, the schedule decides both which version runs and when it runs; the time decides the warmup state; the warmup state affects how long a request takes. That chain is a second route linking version and outcome besides the direct effect of the code, and the comparison measures both routes together.

Not every factor that differs between the groups is a confounder to adjust for. A factor that the condition itself causes, such as the number of cache misses (memory accesses that do not find their data in a cache) the new code produces, lies on the route through which the condition acts; adjusting for it removes part of the real effect. Selecting or adjusting on a factor that both the condition and the outcome affect, such as keeping only the runs that finished within a time limit, can create a difference that was not there.

Worked example

Let the old version take 10 milliseconds (ms) when cold. Warmup alone saves 5 ms, and the new code alone adds 2 ms. The old version, always measured cold, gives 10 ms. The new version, always measured warm, gives 10−5+2=710 - 5 + 2 = 7 ms. The observed change is 7−10=−37 - 10 = -3 ms: the new version looks 3 ms faster, although at a fixed warmup state it is 2 ms slower. Confounding has reversed the sign of the effect.

A second explanation fits the same numbers: the new code saves 3 ms and warmup changes nothing. Both explanations predict 10 ms and 7 ms. More repetitions of the same two combinations shrink the uncertainty around −3-3 ms but cannot choose between the explanations, because both predict the same data.

Measuring the two missing combinations settles the question. The old version warm gives 10−5=510 - 5 = 5 ms and the new version cold gives 10+2=1210 + 2 = 12 ms. Cold against cold, 12−10=212 - 10 = 2 ms; warm against warm, 7−5=27 - 5 = 2 ms. The code effect of 2 ms and the warmup effect of 5−10=−55 - 10 = -5 ms are now separated.

Stated precisely

In a simple additive model, write Y=μ+τZ+γW+ε,Y = \mu + \tau Z + \gamma W + \varepsilon, where YY is the time a request takes, μ\mu (mu) is the cold time of the old version, ZZ is 1 for the new version and 0 for the old, WW is 1 for a warm machine and 0 for a cold one, τ\tau (tau) is the code effect, γ\gamma (gamma) is the warmup effect, and ε\varepsilon (epsilon) is the remaining variation. In the example μ=10\mu = 10, τ=2\tau = 2, γ=−5\gamma = -5 and ε=0\varepsilon = 0, all in ms. Because W=ZW = Z in every measured run, the model reduces to Y=μ+(τ+γ)Z+εY = \mu + (\tau + \gamma) Z + \varepsilon. The data determine τ+γ=2−5=−3\tau + \gamma = 2 - 5 = -3 ms and nothing about τ\tau and γ\gamma separately.

In general terms, let Y(1)Y(1) and Y(0)Y(0) be the outcomes a unit would show under the new and under the old condition (its potential outcomes; see the causal inference §11.11 entry), and assume that each unit’s observed outcome is the potential outcome of the condition it received. Write E[⋅∣Z=z]E[\,\cdot \mid Z = z] for the mean over the units that received condition zz. If the new condition adds the same effect τ\tau to every unit, then E[Y∣Z=1]−E[Y∣Z=0]=τ+(E[Y(0)∣Z=1]−E[Y(0)∣Z=0]).E[Y \mid Z = 1] - E[Y \mid Z = 0] = \tau + (E[Y(0) \mid Z = 1] - E[Y(0) \mid Z = 0]). The term in parentheses is the confounding bias: the difference the two groups would show if both had received the old condition. In the example it is 5−10=−55 - 10 = -5 ms, the warm group against the cold group under the old code, and the observed difference is 2+(−5)=−32 + (-5) = -3 ms. No confounding means that this term is zero; random assignment §11.8 makes it zero on average over the possible assignments.

Limits and common mistakes

A small p-value §11.23 or a narrow confidence interval §11.18 says that the combined difference is unlikely to be chance. It says nothing about which factor caused the difference.

Confounding can create a false effect, hide a real one or reverse its sign, as in the warmup example. A comparison pooled over groups can point one way while the comparison inside every group points the other way; that reversal is called Simpson’s paradox.

Adjustment cannot recover a combination that was never measured. If the new version only ever ran warm, no analysis of those data gives its cold behavior: there is no overlap.

Adjustment covers only the confounders that were recorded. A sensitivity analysis §11.46 asks how strong an unrecorded confounder would have to be to explain the result away.

Confounding is different from interaction. An interaction means that the effect of the condition depends on another factor; that factor need not differ between the compared groups.

Questions answered

Did one firmware variant always run later, on a different board, or under different load?

If one firmware variant always ran later, on a different board or under different load, the comparison is confounded, and the measured difference cannot be credited to the variant. Firmware is the software, stored in a device’s own memory, that controls the device. A variant that always runs later is tied to everything that changes with time, such as warmup, temperature and radio conditions; a different board adds that board’s hardware differences; a different load adds the cost of the other work. To check, tabulate each variant against start time, board, load, input, build options and instrumentation from the run records; any factor whose values differ between the variants is a candidate confounder. Repair the design: run every variant on every board, which is blocking; randomize or interleave the order; and hold the load fixed, or apply each load level to every variant. If the runs cannot be repeated, report the result as the combined effect of the variant and the confounder. Neither a small p-value, nor more repetitions of the same schedule, nor a plausible mechanism removes a confounder.

Related entries: Randomization (§11.8), Blocking (§11.9), Causal inference (§11.11), Internal validity (§11.45), Sensitivity analysis (§11.46).