Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions causal-inference-for-the-brave-and-true/11-Propensity-Score.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Simply comparing those with and without the intervention, we can see that the treated have an achievement score that is, on average, 0.3185 (0.4723 - 0.1538) higher than the average score (which is zero, since the score is standardized). But is this big or small? I know that interpreting standardized outcomes can be challenging, but bear with me for a moment. I think it is worth going through this because it won't be the last time you will encounter standardized scores.\n",
"The intercept tells us that the untreated mean is -0.1538. The coefficient on the intervention, 0.4723, is the treated-minus-untreated difference, so the treated mean is $-0.1538 + 0.4723 = 0.3185$. Standardization makes the pooled outcome mean zero; it does not make the untreated mean zero.\n",
" \n",
"The outcome variable being standardized means that it is measured in standard deviations. So, the treated are 0.3185 deviations above the untreated. That is what this means. As for if this is small or big, let's remember some stuff about the normal distribution. We know that 95% of its mass is between 2 standard deviations, leaving 2.5% on one tail and 2.5% on another. This also means that if someone is 2 standard deviations above the mean, 97.5% (95% plus the left 2.5% tail) of all the individuals are below that person. By looking at the normal CDF, we also know that about 85% of its mass is below 1 standard deviation and that 70% of its mass is below 0.5 standard deviations. Since the treated group has an average standardized score of about 0.5, this means that they fall above 70% in terms of individual achievement. Or, in other words, they are in the top 30% who achieve more. Here is what this looks like in a picture."
"The observed groups therefore differ by 0.4723 standard deviations. For orientation, under a standard-normal reference, a score of 0.3185 is around the 62.5th percentile. This comparison is descriptive, not yet causal: participation in the intervention was not randomized. Here is what the two group means look like in the outcome distribution."
]
},
{
Expand Down Expand Up @@ -433,41 +433,50 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If I know what e(x) is, X alone tells me nothing more that can help me learn what T would be. Which means that controlling for e(x) acts the same way as controlling for X directly. Think of it in terms of our mindset program. Treated and non treated are initially not comparable because the more ambitious are both more likely to take the treatment and of achieving more in life. However, if I take 2 individuals, one from the treated and one from the control, but with the same probability of receiving the treatment, they are comparable. Think about it. If they have the exact same probability of receiving the treatment, the only reason one of them received it and the other did not is pure chance. Holding the propensity score constant acts in a way of making the data look as good as random. \n",
"The propensity score has a precise **balancing property**: once we condition on $e(X)$, the covariates $X$ contain no additional information about treatment. In notation, $T \\perp X \\mid e(X)$. This is not the same as saying that the potential outcomes are independent of treatment. To replace adjustment for the full covariate vector with adjustment for the propensity score, we also need conditional exchangeability, $(Y_0,Y_1) \\perp T \\mid X$.\n",
"\n",
"Now that we got the intuition, let's look at the mathematical proof. We want to show that $(Y_1, Y_0) \\perp T | e(x)$ is equivalent to saying that \n",
"In the mindset example, the observed treated and untreated groups are initially not comparable. Under conditional exchangeability, however, treated and untreated units with the same propensity score have balanced covariate distributions, and treatment is independent of the potential outcomes within propensity-score strata. The propensity score reduces the dimension of the adjustment problem; it cannot repair unmeasured confounding.\n",
"\n",
"$\n",
"E[T|e(x), X] = E[T|e(x)] \n",
"$\n",
"For a binary treatment, first consider the balancing property. Because $e(X)=P(T=1\\mid X)$ is a function of $X$,\n",
"\n",
"This simply says that once I condition on $e(x)$, X can give me no extra information about $T$. The proof of this is quite weird. We will show that the equation above is true by converting it to a trivial statement. First take a look at the left hand side $E[T|e(x), X]$.\n",
"$$\n",
"P(T=1\\mid X,e(X))=P(T=1\\mid X)=e(X),\n",
"$$\n",
"\n",
"$\n",
"E[T|e(x), X] = E[T|X] = e(x)\n",
"$\n",
"while the law of iterated expectations gives\n",
"\n",
"$$\n",
"P(T=1\\mid e(X))=E[P(T=1\\mid X)\\mid e(X)]=e(X).\n",
"$$\n",
"\n",
"We use the fact that $e(x)$ is just a function of X, so conditioning on it gives no further information after we've conditioned on X itself. Then, we use the definition of the propensity score $E[T|X]$. \n",
"Thus $T \\perp X \\mid e(X)$. This establishes covariate balance, but it does not yet mention the potential outcomes.\n",
"\n",
"For the right hand side, we will use the law of iterated expectations $E[A] = E[E[A|B]]$. This law says that we can compute the expected value of A by looking at the value of A broken down by B and then averaging that. \n",
"Now assume conditional exchangeability, $(Y_0,Y_1) \\perp T \\mid X$. Applying iterated expectations again,\n",
"\n",
"$\n",
"E[T|e(x)] = E[E[T|e(x),X]|e(x)] = E[e(x)|e(x)] = e(x)\n",
"$\n",
"$$\n",
"\\begin{aligned}\n",
"P(T=1\\mid Y_0,Y_1,e(X))\n",
"&=E[P(T=1\\mid Y_0,Y_1,X,e(X))\\mid Y_0,Y_1,e(X)]\\\\\n",
"&=E[P(T=1\\mid X)\\mid Y_0,Y_1,e(X)]\\\\\n",
"&=e(X).\n",
"\\end{aligned}\n",
"$$\n",
"\n",
"The first equality comes from the law of iterated expectations. The second comes from what we've figured out when dealing with the left hand side. Since both the left and right hand side equals, $e(x)$, this equation is trivially true.\n",
"The second equality uses conditional exchangeability; the last uses the definition of the propensity score and the fact that we are conditioning on $e(X)$. Since $P(T=1\\mid e(X))=e(X)$ as well, we obtain $(Y_0,Y_1) \\perp T \\mid e(X)$. Positivity, $0<e(X)<1$, is a separate requirement for identifying both treatment states. Balance alone neither creates overlap nor rules out unmeasured confounding.\n",
"\n",
"## Propensity Weighting\n",
"\n",
"![img](./data/img/ps/balance.png)\n",
"\n",
"OK, we got the propensity score. Now what? Like I've said, all we need to do is condition on it. For example, we could run a linear regression that conditions only on the propensity score, instead of all the Xs. For now, let's look at a technique that just uses the propensity score and nothing else. The idea is to write the conditional difference in means with the propensity score\n",
"OK, we got the propensity score. Now what? Like I've said, all we need to do is condition on it. For example, we could run a linear regression that conditions only on the propensity score, instead of all the Xs. For now, let's look at a technique that just uses the propensity score and nothing else. The idea is to rewrite the conditional difference in means using the conditional treatment probabilities\n",
"\n",
"$\n",
"E[Y|X,T=1]-E[Y|X,T=0] = E\\bigg[\\dfrac{Y}{e(x)}|X,T=1\\bigg]P(T) - E\\bigg[\\dfrac{Y}{(1-e(x))}|X,T=0\\bigg](1-P(T))\n",
"E[Y|X,T=1]-E[Y|X,T=0] = e(X)E\\bigg[\\dfrac{Y}{e(X)}\\bigg|X,T=1\\bigg] - (1-e(X))E\\bigg[\\dfrac{Y}{1-e(X)}\\bigg|X,T=0\\bigg].\n",
"$\n",
"\n",
"We can simplify this further, but let's take a look at it like this because it gives us some nice intuition of what the propensity score is doing. The first term is estimating $Y_1$. It is taking all those that are treated and scaling them by the inverse probability of treatment. What this does is it makes those with very low probability of treatment have a high weight. This makes sense, right? If someone has a low probability of treatment, that individual looks like the untreated. However, that same individual was treated. This must be interesting. We have a treated that looks like the untreated, so we will give that entity a high weight. This creates a population with the same size as the original, but where everyone is treated. By the same reasoning, the other term looks at the untreated and gives a high weight to those that look like the treated. This estimator is called the Inverse Probability of Treatment Weighting (IPTW), since it scales each unit by the inverse probability of the treatment it received.\n",
"The multiplying probabilities here are conditional on $X$: $P(T=1\\mid X)=e(X)$ and $P(T=0\\mid X)=1-e(X)$. Replacing them with the marginal probability $P(T)$ would only be valid when the treatment probability is constant across $X$.\n",
"\n",
"We can simplify this further, but let's take a look at it like this because it gives us some nice intuition of what the propensity score is doing. Under conditional exchangeability, the first term identifies $E[Y_1\\mid X]$. It takes those who are treated and scales them by the inverse probability of treatment. What this does is make those with very low probability of treatment have a high weight. This makes sense, right? If someone has a low probability of treatment, that individual looks like the untreated. However, that same individual was treated. This must be interesting. We have a treated unit that looks like the untreated, so we will give that unit a high weight. In expectation, this creates a weighted population with the same size as the original, but where everyone is treated. By the same reasoning, the other term looks at the untreated and gives a high weight to those that look like the treated. This estimator is called Inverse Probability of Treatment Weighting (IPTW), since it scales each unit by the inverse probability of the treatment it received.\n",
"\n",
"In a picture, here is what this weighting does.\n",
"\n",
Expand All @@ -479,18 +488,18 @@
"\n",
"$$\n",
"\\begin{align}\n",
"E[Y|X,T=1]-E[Y|X,T=0] &= E\\bigg[\\dfrac{Y}{e(x)}|X,T=1\\bigg]P(T) - E\\bigg[\\dfrac{Y}{(1-e(x))}|X,T=0\\bigg](1-P(T)) \\\\\n",
"&=E\\bigg[\\dfrac{YT}{e(x)}\\bigg|X\\bigg] - E\\bigg[\\dfrac{Y(1-T)}{(1-e(x))}\\bigg|X\\bigg] \\\\\n",
"&=E\\bigg[\\dfrac{YT}{e(x)} - \\dfrac{Y(1-T)}{(1-e(x))}\\bigg|X\\bigg] \\\\\n",
"&=E\\bigg[Y\\dfrac{T(1-e(x)) - e(x)(1-T)}{e(x)(1-e(x))}\\bigg|X\\bigg] \\\\\n",
"&=E\\bigg[Y \\dfrac{T-e(x)}{e(x)(1-e(x))}\\bigg|X\\bigg]\n",
"E[Y|X,T=1]-E[Y|X,T=0] &= e(X)E\\bigg[\\dfrac{Y}{e(X)}\\bigg|X,T=1\\bigg] - (1-e(X))E\\bigg[\\dfrac{Y}{1-e(X)}\\bigg|X,T=0\\bigg] \\\\\n",
"&=E\\bigg[\\dfrac{YT}{e(X)}\\bigg|X\\bigg] - E\\bigg[\\dfrac{Y(1-T)}{1-e(X)}\\bigg|X\\bigg] \\\\\n",
"&=E\\bigg[\\dfrac{YT}{e(X)} - \\dfrac{Y(1-T)}{1-e(X)}\\bigg|X\\bigg] \\\\\n",
"&=E\\bigg[Y\\dfrac{T(1-e(X)) - e(X)(1-T)}{e(X)(1-e(X))}\\bigg|X\\bigg] \\\\\n",
"&=E\\bigg[Y \\dfrac{T-e(X)}{e(X)(1-e(X))}\\bigg|X\\bigg].\n",
"\\end{align}\n",
"$$\n",
"\n",
"which if we integrate over X becomes our propensity score weighting estimator.\n",
"Under conditional exchangeability, the left side identifies $E[Y_1-Y_0\\mid X]$. Averaging over $X$ therefore gives the ATE and the propensity-score weighting identity\n",
"\n",
"$\n",
"E\\bigg[Y \\dfrac{T-e(x)}{e(x)(1-e(x))}\\bigg]\n",
"ATE=E[Y_1-Y_0]=E\\bigg[Y \\dfrac{T-e(X)}{e(X)(1-e(X))}\\bigg].\n",
"$\n",
"\n",
"Notice that this estimator requires that $e(x)$ and $1-e(x)$ are larger than zero. In words, this means that everyone needs to have at least some chance of receiving the treatment and of not receiving it. Another way of stating this is that the treated and untreated distributions need to overlap. This is the **positivity assumption** of causal inference. It also makes intuitive sense. If treated and untreated don't overlap, it means they are very different and I won't be able to extrapolate the effect of one group to the other. This extrapolation is not impossible (regression does it), but it is very dangerous. It is like testing a new drug in an experiment where only men receive the treatment and then assume women will respond to it equally well.\n",
Expand Down Expand Up @@ -793,7 +802,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Propensity score weighting is saying that we should expect treated individuals to be 0.38 standard deviations above their untreated fellows, in terms of achievements. We can also see that if no one got the treatment, we should expect the general level of achievements to be 0.12 standard deviation lower than what it is now. By the same reasoning, we should expect the general level of achievement to be 0.25 standard deviations higher if we've given everyone the seminar. Contrast this to the 0.47 ATE estimate we've got by simply comparing treated and untreated. This is evidence that the bias we have is indeed positive and that controlling for X gives us a more modest estimate of the impact of the growth mindset.\n",
"Propensity score weighting is saying that we should expect treated individuals to be 0.38 standard deviations above their untreated fellows, in terms of achievements. We can also see that if no one got the treatment, we should expect the general level of achievements to be 0.12 standard deviation lower than what it is now. By the same reasoning, we should expect the general level of achievement to be 0.25 standard deviations higher if we've given everyone the seminar. Contrast this to the 0.47 unadjusted difference-in-means estimate we've got by simply comparing treated and untreated. This is evidence that the bias we have is indeed positive and that controlling for X gives us a more modest estimate of the impact of the growth mindset.\n",
"\n",
"## Standard Error\n",
"\n",
Expand Down