Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is Causal Inference?

Learn what causal inference is, how it differs from prediction, why 'what if' questions need special methods, and see your first simulated cause and effect in Python.

Does a new onboarding flow make people stay longer? Did a scholarship raise graduation rates? Would this patient have recovered without the drug? Each of these asks about a cause and its effect. Causal inference is the set of ideas and methods that let you answer such questions from data, including data that did not come from a perfect experiment.

Most of the machine learning and statistics you meet first is about prediction: given what you can see, guess something else. Causal inference is about intervention: what would happen if you changed something. The difference sounds small and turns out to be enormous.

Prediction versus intervention

Suppose a hospital notices that patients who receive an expensive treatment have worse outcomes than patients who do not. A prediction model would happily learn "treatment predicts death". But the sickest patients are the ones who get the treatment, so the pattern says little about what the treatment does.

Question type Example What you need
Description How many patients took the drug? Counting
Prediction Who is likely to be readmitted? A model that fits the data well
Causal Would readmissions fall if we gave everyone the drug? A model of how the data were generated

A good predictor can be a terrible guide for decisions. A causal estimate answers the question "if I act, what changes?".

Three kinds of questions

Describe What happened?
Predict What will we see?
Intervene What if we act?

Causal inference is the third kind.

1 / 2

The core difficulty

For one person you can observe what happened with the treatment or without it, never both. The unobserved world is called the counterfactual. Every causal method is a way of borrowing information from other people, other times or random assignment to fill in what we cannot see. You will study this precisely in the potential outcomes framework.

Your first causal simulation

In real data you never know the true effect. In a simulation you set it yourself, so you can check whether a method recovers it. This habit is used all through this course.

Below, a study app (the treatment) truly raises an exam score by 5 points. Students are assigned by a coin flip, so the groups are comparable.

Python A randomized treatment with a known 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 difference in means lands close to 5. Randomization made treated and untreated students alike on average, including in ability, which nobody measured.

When the shortcut fails

Now let students choose. Weaker students are keener to use the app. Same true effect, different assignment rule.

Python The same effect, but students choose

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 comparison is negative. The app helps every student, yet users look worse because they were weaker to begin with. This hidden common cause is called a confounder, and the next chapters teach you how to deal with it.

Nothing in the data table warns you. Both datasets look identical in shape. What differs is the story of how the numbers came to be, which is why causal inference needs assumptions, not just algorithms.

Where causal inference is used

  • Medicine: does a drug or screening program save lives?
  • Economics and policy: did a minimum-wage change, tax or training program work?
  • Technology: did a feature, a price or a recommendation change behavior? See A/B testing.
  • Social science and education: do class sizes, tutoring or housing affect outcomes?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which question is causal?

    It asks what would happen under an intervention (a price change). The others describe or predict.
  2. 2. Why can't we observe an individual's causal effect directly?

    A person either gets the treatment or not. The other outcome is a counterfactual that is never observed.
  3. 3. In the second simulation the naive estimate was negative although the true effect was +5. The most likely reason is:

    Weaker students chose the app more often, so the treated group started lower.
  4. 4. A model that predicts outcomes very accurately is therefore also good at telling you the effect of an intervention.

    Predictive accuracy and causal validity are different goals.

Summary

  • Causal inference answers "what if we intervene?", unlike description or prediction.
  • We never observe both outcomes for one unit, so every method borrows information.
  • Randomization makes simple comparisons trustworthy; self-selection does not.
  • Simulations with a known true effect are the best way to test a method.

Next: Correlation vs Causation