Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 37 ยท Causality and Confounding

Confounding: The Central Problem

Understand confounders, how they bias treatment effect estimates, the direction of the bias, and how adjusting for a measured confounder recovers the truth, with Python.

A confounder is a variable that influences both the treatment and the outcome. When you ignore it, part of the association between treatment and outcome is really the confounder talking, and your estimate of the treatment effect is biased. Confounding is the main reason observational comparisons mislead, so this lesson treats it carefully.

The picture

flowchart LR
  Z["Z: confounder"] --> T["T: treatment"]
  Z --> Y["Y: outcome"]
  T --> Y

Two paths link T and Y: the direct causal arrow, and the back path T <- Z -> Y. A naive comparison mixes both.

The back path is called a backdoor path. It carries association that is not causal. To get the causal effect you must block it, usually by conditioning on Z (see the backdoor criterion).

A concrete example

A hospital offers an intensive program. Sicker patients (higher severity) are more likely to be enrolled, and sicker patients also have worse outcomes. The program truly lowers a health-risk score by 4 points.

Python Confounding hides a real benefit

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 naive difference is positive: enrolled patients look worse off. The program is beneficial, yet confounding flips the sign. This is sometimes called confounding by indication: people are treated because they are in a state that predicts bad outcomes.

Direction of the bias

Whether a confounder pushes the estimate up or down depends on two signs:

Z affects T Z affects Y Bias in the naive effect
positive positive upward (overstates)
positive negative downward (understates)
negative positive downward
negative negative upward

In the example, severity raises enrollment (+) and raises risk (+), so the naive effect is biased upward. In a linear model with a single confounder, the omitted variable bias equals roughly (effect of Z on Y) x (how strongly Z is related to T).

Adjusting for the confounder

If Z is measured, include it in a regression or compare patients with the same Z:

Python Adjusting for severity recovers the effect

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 second number is close to -4. Adjustment worked because severity captures the whole back path and is measured without error.

Unmeasured confounding

The hard case: the confounder is not in your data (genetics, motivation, true severity). You cannot adjust for what you did not record. Then you have three options:

  1. Measure it (better data).
  2. Use a design that sidesteps it: randomization, instrumental variables, difference-in-differences.
  3. Quantify the risk with sensitivity analysis: "how strong would a hidden confounder need to be to erase this result?"
Python What a hidden confounder does

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.

Nothing in the observed columns warns you. The data cannot tell you whether a hidden confounder exists; only subject knowledge can.

More data does not cure confounding. A million rows give a very precise estimate of the wrong number.

How to find confounders

  • Think about what causes both treatment and outcome, from domain knowledge.
  • A confounder must occur before the treatment. Variables influenced by treatment are not confounders (see mediators and bad controls).
  • A variable correlated with both is not automatically a confounder; draw the graph first.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which description defines a confounder?

    Common causes of treatment and outcome create a backdoor path.
  2. 2. Sicker patients are more likely to get a drug and more likely to die. Ignoring severity makes the drug look:

    Severity pushes up treatment and mortality together, so the treated group looks sicker.
  3. 3. Collecting ten times more data will fix confounding bias.

    Bias does not shrink with sample size.
  4. 4. Which option can handle an UNMEASURED confounder?

    Randomization breaks the arrow from every hidden cause into the treatment.

Summary

  • A confounder influences both treatment and outcome and opens a backdoor path.
  • Naive comparisons mix the causal effect with confounding bias, even flipping the sign.
  • Adjusting for measured confounders can remove the bias; hidden ones need design or sensitivity analysis.
  • More data never fixes bias.

Next: Simpson's Paradox