learn-causal-inference-with-phoebe / Practitioner session 1 of 10
Learn Causal Inference with Phoebe · Practitioner session 1 of 10

Draw the DAG before touching the data

Kestrelmark sent a re-engagement email and the customers who got it spent 10.54 more than the customers who did not. That number is real, reproducible, and not the effect of the email. The true effect is 6.23, and the gap is entirely made of things nobody wrote down: winter, tenure, and a loyalty score that looks harmless. Tonight you write them down. A causal diagram is not decoration on top of an analysis; it is the assumption set that decides whether the analysis can answer the question at all.

🟠 Advanced Data scientists and analysts Anyone who has been asked "but did it cause it" 45 min
0-3 · Welcome 3-22 · An arrow is a claim 22-40 · Build-along: draw Kestrelmark 40-45 · Q&A
Part 0

How the practitioner track works

Ten sessions, 45 minutes each, one artifact: a causal claim you can defend about one intervention. Tonight the graph. Then the three shapes in session 2, identification in 3, the front door in 4, Simpson's paradox in 5, counterfactuals in 6, heterogeneous effects in 7, targeting in 8, sensitivity in 9, and in session 10 the whole thing is scored on a bench where the true answer is known by construction. The intervention throughout is Kestrelmark's re-engagement email, sent to 5,000 subscription customers who were drifting.

Live = presented in the 45 minutes Self-study = the full depth, after class 🔍 Every diagram zooms

★ What you walk out with tonight. A diagram of one real decision your team has argued about, with every arrow written as a sentence somebody could dispute. The reason the missing arrows are the stronger claims and the ones to defend hardest. And the uncomfortable first number: at Kestrelmark, the season and the customer's tenure add two thirds of the true effect again on top of it, and no amount of extra data would have revealed that on its own.

LiveWhy the graph comes before the query3 min▶

A dataset cannot tell you which of two variables causes the other. The same table is consistent with the email raising spend, with high spenders being selected for the email, and with a third thing driving both. Choosing between those three is not a statistical operation; it is an assumption, and the graph is where the assumption gets written down where a colleague can attack it.

That is the whole argument for drawing it first. Once the graph exists, a set of purely mechanical questions become answerable: which paths carry real effect, which carry contamination, what has to be held fixed, and whether the data you have is even capable of answering the question. Without it, adjustment is a matter of taste, and session 10 measures what taste costs.

Real world

Kestrelmark's growth team reported the email as a 10.54 unit lift and asked for budget to send it to everyone. The analyst who queried it was not disputing the arithmetic. She drew six boxes on a whiteboard, put arrows from winter and tenure into both the email and the spend, and asked which of those two the campaign had controlled for. Neither. The remaining conversation took nine minutes.

Self-studyThe vocabulary for the whole track4 min▶
  • DAG - a directed acyclic graph. Directed because arrows point from cause to effect, acyclic because nothing causes itself through a loop.
  • Path - any chain of arrows between two variables, regardless of which way they point. Some paths carry causation, some carry only association.
  • Back-door path - a path from treatment to outcome that starts with an arrow pointing INTO the treatment. These are the contaminating ones, and closing them is the job. Session 3 states the criterion formally.
  • Confounder - a common cause of treatment and outcome. Opens a back-door path; adjust for it.
  • Collider - a common effect of two variables. Conditioning on one creates association where there was none. Session 2.
  • Mediator - sits on the causal path from treatment to outcome and carries part of the real effect. Adjusting for one answers a different question. Session 2.
  • Identification - whether the effect can be computed from the data you have, given the graph. Separate from, and prior to, estimation. Session 3.
  • Estimand, estimator, estimate - the quantity you want, the recipe, and the number you got. Confusing them is how teams answer a question nobody asked.
Part 1 · covers what an arrow means and what a missing arrow means

An arrow is a claim, and a missing arrow is a stronger one

9 min live

Every arrow you draw says "this can affect that, by some mechanism, to some degree". That is a modest claim and it is usually easy to defend. Every arrow you leave out says "this cannot affect that at all, by any mechanism", which is a much stronger statement and the one that will be wrong.

Season Tenure Email Spend Opened Ticket Loyalty u1 and u2 unobserved u1 u2 direct Device no arrows at all Rust arrows point INTO ticket from both sides. That shape is the one that bites.
🔍 Click to zoom - the arrows that matter for identification, every one a separate claim, with the two unobserved causes drawn dashed. The model also carries a recency segment, listed in the text version further down: it does not cause the email, so it opens no back door and does not change what has to be held fixed.
LiveReading each arrow out loud as a sentence3 min▶

The test for whether a graph is honest is whether every arrow survives being said out loud to somebody who knows the business. Kestrelmark's:

  • Season into email. The winter campaign calendar sends more email. Nobody disputes this.
  • Season into spend. People buy more in winter regardless of email. Also undisputed, and together with the arrow above this is what makes season a confounder.
  • Tenure into email and into spend. Long-tenured accounts are on more lists and buy more anyway.
  • Email into opened into spend. The email works partly because people open it. This is the mechanism, not a nuisance.
  • Email into spend, directly. Even unopened, the sender name in an inbox is a reminder. Arguable, and worth arguing about.
  • Email and spend both into ticket. Getting the email prompts questions; spending more prompts questions. Two arrows into one box.

Six sentences, five minutes, and the shape of the analysis is now fixed. Notice that not one of them required looking at the data.

LiveThe missing arrows are the load-bearing ones3 min▶

Kestrelmark's graph has no arrow from device into spend. That says mobile users do not spend differently, which is a real claim and would be worth ten minutes of checking. It also has no arrow from ticket back into spend, which says that raising a ticket does not itself change what somebody buys. Plausible for this business, false for many others.

This is the honest weakness of the whole method and it is better stated than hidden: the conclusions depend on arrows you chose not to draw, and no dataset will tell you that you were wrong. What the graph buys is that the assumption is visible and specific, so a colleague can point at one missing arrow and say "that one, I think that one exists" - which is a conversation you can have, unlike a disagreement about a number.

Draw the arrow when you are unsure. An arrow you were not certain about costs you a variable you have to handle. A missing arrow you were not certain about costs you a wrong answer with no warning. Session 9 puts a number on how wrong.

Self-studyUnobserved variables belong on the graph too4 min▶

Kestrelmark's u1 and u2 are drawn as dashed circles because nobody measured them. u1 is whatever disposition makes somebody both a target for the campaign and a certain kind of loyal; u2 is whatever makes them both loyal and a spender. Leaving them off the graph because they are not columns in the warehouse would be the single most common mistake in applied work.

  • They change what is identifiable. A back-door path running through an unmeasured variable cannot be closed by adjustment, which is a fact about your data you want to know before the analysis, not after.
  • They are why the loyalty score is dangerous. Loyalty is a common effect of u1 and u2. Session 2 shows what conditioning on it does; session 10 measures it at -0.97.
  • They are the target of sensitivity analysis. If you cannot measure it, you can still ask how strong it would have to be to overturn your finding. Session 9.
Part 2 · covers paths, and which ones contaminate

Three paths from email to spend, and only two of them are the effect

8 min live

A path is any chain of arrows connecting two variables, ignoring direction. What matters is whether the first arrow points away from the treatment, in which case the path carries real effect, or into it, in which case the path carries contamination. Kestrelmark has both kinds and the naive estimate adds them all together.

Causal paths: keep these email to spend the direct arrow, mean 5.16 email to opened to spend the mechanism, worth 1.056 together: the true effect, 6.23 the same two paths by algebra: 6.22 Back-door paths: close these email from season to spend winter sends more and sells more email from tenure to spend old accounts get more and buy more left open: they add 4.31 Naive comparison of emailed against not emailed: 10.54 the two causal paths plus the two back doors, added together and reported as one number A path is contaminating when its first arrow points into the treatment. That is the only test.
🔍 Click to zoom - four paths, two of which are the answer and two of which are the problem.
LiveWhy the naive number is 10.54 and not 6.234 min▶

Comparing the emailed group to the not-emailed group measures every open path at once. Two of those paths are the effect you want and two are the season and the tenure leaking in. The arithmetic in session 10 puts the leak at 4.31 units, which is two thirds of the true effect again on top.

Nothing about this is fixed by more data. A million rows gives you 10.54 with tighter error bars, which is a more confident wrong answer. It is fixed by holding season and tenure fixed, and knowing that those two are the right things to hold fixed comes from the graph rather than from the table.

Real world

The version of this that reaches a board deck is a campaign that "drove 10.54 units of incremental spend". The word incremental is doing work the analysis never did. Leader session 2 is about auditing exactly that sentence.

Self-studyTotal effect or direct effect: decide before you adjust3 min▶

Kestrelmark's email works two ways: some people open it and buy, some people see the sender and buy without opening. The total effect, 6.23, is both together. The direct effect, a mean of 5.16, is only the second.

  • The total effect answers "should we send the email". That is nearly always the business question, and it is the estimand for the rest of this track.
  • The direct effect answers "how much of this survives if nobody opens it". A real question for a subject-line project, and a different one.
  • Adjusting for opened silently switches you from the first to the second. Session 10 measures the switch at 5.48, roughly the mean direct effect of 5.16, and session 2 explains the mechanism.

Write the estimand down in the graph's caption before adjusting anything. It takes one sentence and it prevents the most common way a correct analysis answers the wrong question.

Build-along

Draw one real decision

★ 18 min · everyone builds

Bring a decision your team has argued about: a campaign, a feature, a price change, a policy. If you have nothing to hand, rebuild Kestrelmark's graph from the six sentences in part 1.

Write the question as one sentence with a "what if" in it. "What would total spend have been if we had sent the email to everyone, compared with sending it to nobody?" If your sentence does not contain an intervention, you are on rung 1 and no graph will help. Leader session 1 covers the ladder.

Put the treatment and the outcome on the page, far apart. Two boxes, one arrow, and resist adding anything else for a moment. Everything you add next is either helping or hurting, and the discipline is to know which as you add it.

Add every common cause you can name. Ask, for each candidate: does this affect who gets treated, and does it also affect the outcome? Two yeses makes it a confounder and it must go on the graph. Kestrelmark has two obvious ones and one that took a week to find.

Add the mechanism. How does the treatment actually work? Those intermediate steps are mediators, they belong on the graph, and they must not be adjusted for if you want the total effect.

Add the downstream consequences, and mark them. Anything caused by the treatment or by the outcome after the fact. These are the colliders, they are the most tempting variables in the table, and session 2 is about why.

Add the unobserved causes as dashed nodes. Anything you believe exists and cannot measure. If a back-door path runs entirely through dashed nodes, note it now: session 3 will tell you the effect is not identified from this data, and it is much cheaper to learn that tonight than after a month of modelling.

Read every arrow out loud to somebody who knows the business, and write down the ones they dispute. That list is the real output of tonight. A graph nobody has argued with is a diagram, not an assumption set.

★ The graph as text, so it can live in version control and be diffed # kestrelmark-email.dag - one line per arrow, read -> as "causes" season -> email # winter campaign calendar sends more season -> spend # people buy more in winter regardless tenure -> email # long accounts are on more lists tenure -> spend # long accounts buy more anyway email -> opened # the mechanism opened -> spend # the mechanism email -> spend # direct: sender name in the inbox email -> ticket # getting mail prompts questions spend -> ticket # spending prompts questions u1 -> email # unobserved disposition u1 -> loyalty # unobserved u2 -> loyalty # unobserved u2 -> spend # unobserved recency -> spend # dormant customers spend less, whatever you send them recency => effect # an EFFECT MODIFIER: it sets how much the email is worth # device: no arrows. claim: mobile users do not spend differently. # recency has no arrow into email, so it opens no back door: the set to hold # fixed is still {season, tenure} and the estimand line below is unchanged. # sessions 7 and 8 are where the => line gets used. # estimand: TOTAL effect of email on spend. do not adjust for opened.

Keep the graph in the repository next to the query. A DAG in a slide deck is a picture of last quarter's assumptions. A DAG in a text file gets reviewed in a pull request, and when somebody adds an arrow you can see who and when.

Homework

Before session 2

30 min
  1. Finish the graph for one real decision, in text, in the repository, with the estimand in a comment at the bottom.
  2. Take it to one person who knows the business and one who knows the data. Write down every arrow either of them disputes, and every arrow they say is missing.
  3. List the variables in your table that are caused by the treatment. That list is session 2's material and it is usually longer than people expect.
  4. Find one back-door path in your graph that runs through something you cannot measure. If there is one, bring it to session 3.
Check yourself

Three questions

Kestrelmark's naive comparison gives 10.54 against a true effect of 6.23. What would collecting ten times more data do to that gap?

Confounding is bias, not noise. More rows shrink the error bars around the wrong number. The fix is holding season and tenure fixed, and knowing to do that comes from the graph.

Which is the stronger claim: an arrow you drew, or an arrow you left out?

A drawn arrow says "this can matter somewhat" and costs you a variable to handle. A missing arrow says "this cannot matter at all" and costs you a wrong answer with no warning.

A colleague says the unobserved variables should be left off the graph because they are not columns in the warehouse. What is wrong with that?

Leaving them off does not remove them from the world, only from the diagram, and it hides the one fact worth learning early: that this data cannot answer the question.

Sources covered

What tonight maps to

✓ Causal diagrams as the assumption set Nodes, arrows, paths, back-door paths, unobserved variables, and the estimand written down before adjustment.
✓ Total effect against direct effect 6.23 against a mean direct effect of 5.16 on the Kestrelmark graph, and why the choice must be made before touching a covariate list.
◐ The back-door criterion, stated formally Session 3. Tonight names back-door paths and leaves the criterion and its two conditions until identification.
◐ Colliders and mediators Marked on the graph tonight, explained in session 2, measured in session 10.
· Propensity scores, IPW, difference-in-differences, synthetic control Not covered by design, in any session. Estimating an effect from observational data is the experimentation course's territory; this track stops at whether the effect is identified and what must not be conditioned on.

Session 1 cheat sheet

Graph before queryThe data cannot tell you the direction. The graph is where the assumption is written down and attacked.
An arrow is a claimRead every one aloud to somebody who knows the business.
Missing arrows are strongerThey assert no effect by any mechanism. Draw the arrow when unsure.
Back-door pathStarts with an arrow pointing INTO the treatment. That is the whole test.
10.54 against 6.23Season and tenure add two thirds of the true effect again on top.
More data does not helpConfounding is bias. More rows give a more confident wrong answer.
Unobserved nodes belong on itThey decide what is identifiable, and identifiability is cheaper to learn tonight.
Write the estimand downTotal or direct. Adjusting for the mediator switches you silently.