Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 37 ยท Causality and Confounding

Stratification and Standardization

Adjust for confounding by comparing like with like: stratify on a confounder, average the stratum effects with the right weights, and compute standardized outcomes in pandas.

The simplest way to remove confounding from a measured variable is to compare only people who are alike on it. Split the data into strata (groups with the same value of the confounder), estimate the effect inside each stratum, then combine. This is stratification; averaging the stratum results with population weights is standardization. The idea underlies regression, matching and weighting later in the course.

Why comparing within strata works

Within a stratum, the confounder is constant, so it cannot explain a difference between treated and untreated. If the confounder (and nothing else) opens the backdoor path, the within-stratum comparison is clean.

flowchart LR
  Z["stratum (age group)"] --> T["treatment"]
  Z --> Y["outcome"]
  T --> Y

Fixing Z blocks the path T <- Z -> Y.

Step by step with pandas

A clinic gives a supplement to older and younger patients. Older patients take it more, and older patients have lower recovery scores. The supplement truly adds 5 points.

Python Naive versus stratified comparison

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Inside each age group the difference is close to the true 5. The naive effect is dragged down because the treated group is mostly older.

Combining strata: choosing the weights

The stratum effects must be combined into one number, and the weights define the estimand:

  • ATE: weight each stratum by its share of the whole population.
  • ATT: weight by its share among the treated.
  • ATU: weight by its share among the untreated.
Python ATE and ATT from strata

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The ATT is smaller than the ATE here because treated patients are mostly older, where the effect is 2.0. Same data, different weights, different (correct) answers to different questions.

Standardized outcomes

Instead of effects, you can compute standardized means: what the average outcome would be if everyone had the same confounder distribution. This is how age-standardized death rates compare countries with different age structures.

Python Direct standardization of rates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Country Y has the higher crude rate partly because it is older; and standardized, the gap becomes smaller and country X still comes out lower at each age. This is exactly the logic behind Simpson's paradox.

Limits of stratification

  • Curse of dimensionality: with many confounders (or continuous ones) strata become tiny or empty. Regression, propensity scores and matching handle this.
  • Positivity: every stratum needs both treated and untreated units. If older people never skip the supplement, there is nothing to compare in that group.
  • Only measured confounders: unmeasured ones remain.
  • Wrong variables: do not stratify on colliders or mediators.

Stratification is the "by hand" version of what regression does. Understanding it makes the later tools much less mysterious.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does comparing within strata remove confounding by the stratifying variable?

    Holding the confounder fixed blocks the backdoor path.
  2. 2. To estimate the ATT from stratum effects you weight strata by:

    ATT averages the effect over those who were treated.
  3. 3. What breaks stratification when a stratum has only treated units?

    With no untreated units there is no comparison group in that stratum.
  4. 4. Standardized rates are used to:

    They apply a common standard population to remove differences in mix.

Summary

  • Stratify on a measured confounder and compare treated and untreated inside each stratum.
  • The weights used to combine strata define whether you estimate the ATE, ATT or ATU.
  • Standardization compares groups as if they shared the same composition.
  • Many confounders or missing overlap need regression, weighting or matching.

Next: The Potential Outcomes Framework