Statistical laboratory 01

When can confounding reverse an association?

Drag any parameter of the data-generating mechanism. Everything below — the population risks, the decomposition of RDoverall, and a fresh simulated sample — is recomputed in your browser while you drag.

Data-generating mechanism

P(Y=1 | X,Z) = p0 + dxX + dzZ

prevalence of the confounder
a1 ≠ a0 makes Z a confounder
Outcome model
the risk difference within each level of Z
Adjusted to keep all four probabilities inside [0, 1].
Simulated sample
Labels

Population risks

Where RDoverall comes from

RDoverall = dx + dz(q1 − q0), where qx = P(Z=1 | X=x). The second term is pure composition: it is non-zero only because the two exposure groups contain different proportions of Z=1.

One simulated sample

Observed 2 × 2 tables