# When Confounders were also Collected

### Inverse Probability Weighting

Let us come back to the original graph $G$ that consists of three variables; $a$, $y$ and $x$, with the following joint probability:

[] \begin{align} p^*(a, y, x) = p^*(x) p^*(a|x) p^*(y|a, x). \end{align} []

We also assume that we have a set $D$ of triplets $(a_n, y_n, x_n)$ drawn from this underlying graph $G$. In other words, we assume that we observe the confounder in this case. If we have a large such set, i.e. $N=|D| \gg 1$, we can use regression, as in Regression: Causal Inference can be Trivial, to approximate $p^*(y | a, x)$ in order to compute the causal effect as

[] \begin{align} \label{eq:regression} \mathbb{E}_G\left[ y | \mathrm{do}(a=\hat{a})\right] &\approx \sum_{x} p^*(x) \sum_{y} y \hat{p}(y | \hat{a}, x) \\ &\approx \frac{1} {N} \sum_{n=1}^N \mathbb{E}_{\hat{p}(y | \hat{a}, x_n)}[y]. \end{align} []

Although this regression-based approach is straightforward, this approach has a disadvantage of having to fit a regressor on the concatenation of the action $a$ and confounder $x$. The issue is exactly that of RCT with partially observed confounders, that is, we must have enough data points for each action-covariate combination in order for regression to have a low variance. We can use regularization to reduce the variance, which may unfortunately introduce a bias. We can reduce the variance by using regression to estimate a simpler quantity. In particular, we consider approximating $p^*(a|x)$. Because this is a map from $\mathcal{X}$, we just need enough data points for each covariate configuration rather than the action-covariate combination. Approximating $p^*(a|x)$ allows us to estimate the causal effect using data points drawn from the original graph $G$ rather than the modified graph $\overline{G}$ from Randomized Controlled Trials, because

[] \begin{align} \mathbb{E}_G\left[ y | \mathrm{do}(a=\hat{a})\right] &= \sum_{x} p^*(x) \sum_{a} \mathds{1}(a = \hat{a}) \sum_{y} p^*(y | \hat{a}, x) y \\ &= \sum_{x} \sum_{a} \sum_{y} p^*(x) p^*(a|x) \mathds{1}(a = \hat{a}) p^*(y | \hat{a}, x) \frac{1}{p^*(a|x)} y \\ &= \frac{1}{\sum_{n'=1}^N \mathds{1}(a_{n'}= \hat{a})} \sum_{n=1}^N \mathds{1}(a_n = \hat{a}) \frac{y_n} {p^*(\hat{a} | x_n)}. \end{align} []

Instead of the true $p^*(\hat{a}|x_n)$, we plug in the regression-based approximation $\hat{p}(\hat{a} | x_n)$ and arrive at

[] \begin{align} \label{eq:ipw} \mathbb{E}_G\left[ y | \mathrm{do}(a=\hat{a})\right] & \approx \frac{\sum_{n=1}^N \mathds{1}(a_n = \hat{a}) \frac{y_n} {\hat{p}(\hat{a} | x_n)}}{ \sum_{n'=1}^N \mathds{1}(a_{n'}= \hat{a})}. \end{align} []

In words, we look for all data points within the previously-collected set $D$ that are associated with the action $\hat{a}$ of interest. The simple average of the associated outcomes would be a biased estimate of the casual effect, since it combines the effects of $a$ on $y$ via two paths; (causal) $a \to y$ and (spurious) $a \leftarrow x \to y$. We correct this bias by weighting each data point, or the associated outcome, by the inverse probability of the action given the confounder, $\frac{1}{\hat{p}(\hat{a} | x_n)}$. This approach is thus called inverse probability weighting (IPW), and $p^*(a|x)$ is often referred to as a propensity score.

It is fine to have missing outcomes. One important advantage of the IPW-based approach is that we can approximate $p^*(a|x)$ using all $(a,x)$ pairs even if they are not associated with the outcome $y$, unlike the earlier regression-based approach which required having all three variables observed $(a,y,x)$. Imagine using clinical notes and measurements from the electronic health record (EHR) of a large hospital in order to estimate the causal effect of a particular drug on a target disease. Of course, the prescription of the drug $a$ is not made blindly but based on the patient information which includes their underlying health condition. Since the existing health conditions affect the outcome $y$ of almost any kind of a disease, such patient information is a confounder $x$. Some patients often do not return to the same hospital for follow-up checks, meaning that the EHR does not record the outcome of these patients, leaving us only with $(a,x)$. We can then use all the prescriptions to approximate the propensity score $p(a|x)$ and then use a subset of these prescriptions for which the patients' outcomes are recorded (i.e. they came back for follow-up visits) to compute the causal effect. Mathematically, it means that we solve two separate optimization problems using two different data sets (though, one is a superset of the other,) as follows:

[] \begin{align} &\hat{p}(a|x) = \arg\max_{p} \sum_{(a',x') \in D_{\pi}} \log p(a'|x'), \\ &\hat{y}(\hat{a}) = \frac{\sum_{(a',x',y') \in D_{\bar{y}}} \mathds{1}(a' = \hat{a}) \frac{y_n} {\hat{p}(\hat{a} | x_n)}}{ \sum_{(a'',x'',y'') \in D_{\bar{y}}} \mathds{1}(a'' = \hat{a}) }, \label{eq:ipw2} \end{align} []

where $D_{\bar{y}} \subseteq D_{\pi}$.

A doubly robust estimator. A major issue with the IPW-based approach is that the variance of the estimator can be very large, even if the variance of estimating the propensity score is low, because the propensity scores shows up in the denominator. On the other hand, the regression-based approach has a low variance due to the missing division by the propensity score. It is however likely a biased estimator, as we cannot easily guarantee that the choice of a non-parametric regressor can identify the correct conditional probability, due to a variety of issues, such as the lack of realizability. If the regression-based approach is correct for an instance $(a,y,x)$, $\tilde{y}(a, x)$ would coincide with $y$, and we would just use $\tilde{y}(a, x)$ as it is and prefer to avoid the IPW-based estimate due to the potentially large variance arising from the denominator. Otherwise, we want to rely on the IPW-based estimate to correct for the incorrectness arising from the regression-based approach. This can be expressed as

[] \begin{align} \hat{y}(\hat{a}) = \sum_x p(x) \sum_a \left( \frac{1}{|\mathcal{A}|} \tilde{y}(a,x) + \underbrace{ p^*(a|x) \frac{\tfrac{1}{|\mathcal{A}|}}{\hat{p}(a|x)} }_{(b)} \left( \underbrace{ y^*(a|x) - \tilde{y}(a,x) }_{\mathrm{(a)}} \right) \right). \end{align} []

If $\tilde{y}(a,x)$ is perfect, (a) disappears, as expected. If our estimate of the propensity score is perfect, (b) is $1$, resulting in using the true $y^*(a,x)$ while ignoring the regression-based approach.[Notes 1] Since we are provided with data rather than the actual probability distributions, we end up with

[] \begin{align} \hat{y}(\hat{a}) = \frac{1}{Z(\hat{a})} \sum_{(a',x',y') \in D} \mathds{1}(a' = \hat{a}) \left( \tilde{y}(\hat{a}, x_n) + \frac{1} {\hat{p}(\hat{a} | x_n)} \left(y_n - \tilde{y}(\hat{a}, x_n)\right) \right), \end{align} []

where $Z(\hat{a}) = \sum_{(a'',x'',y'') \in D} \mathds{1}(a'' = \hat{a}).$ This estimator is called a doubly robust estimator.

### Matching.

Instead of estimating $p^*(a|x)$ and multiplying the observed outcome with its inverse, we can achieve a similar outcome by manipulating data itself. When $p^*(a|x) = p^*(a)$, that is, the action is independent of the covariate, the IPW-based estimate coincides with simple averaging, just like in RCT from Randomized Controlled Trials. This happens when the ratio of actions associated with each unique $x$ in the data is the same across the data set. To make it simpler, let us express this ratio of actions by assigning the minimal number of each action in relation to the other actions. For instance, if our desired ratio between the treatment and placebo is $0.8:0.2$, we would express it for instance as $4:1$. Starting from the original data set $D=\left\{(a_1, x_1, y_1), \ldots, (a_N, x_N, y_N) \right\}$, we go through each $x_n$ by collecting as many $(a,x_n,y) \in D$ as $n_a$, where $n_a$ is the target number of examples of action $a$, for instance $4$ above. This collection can be done randomly or by following some fixed strategy, such as round-robin scheduling. Sometimes it is necessary to choose the same triplet multiple times, which is not ideal but may be necessary. By aggregating these collections, we arrive at a new dataset $\tilde{D}$. Under this new dataset $\tilde{D}$, the propensity score is guaranteed to be

[] \begin{align} \hat{p}(a|x) \propto n_a, \end{align} []

regardless of $x$. Furthermore, $\hat{p}(a|x) = \hat{p}(a)$ as well. Meanwhile, $\hat{p}(x)$ stays the same as that under the original data set $D$. Then, the expected causal outcome of any given action $a$ under this dataset is

[] \begin{align} \hat{y}(\hat{a}) = \frac{1}{N} \sum_{n=1}^N \mathds{1}(a'_n=\hat{a}) y'_n, \end{align} []

where $(a'_n, y'_n, x'_n) \in \tilde{D}$. This avoids the issue of the high variance arising from the IPW-based approach. This however does not mean that this approach always works. The most obvious issue with this approach is that the original data set may not have enough triplets associated with each $x$ to ensure that $p^*(a|x)$ is identical for all $x$. Furthermore, even if we have enough associated triplets for each $x$, we may end up with discarding many triples from the original data set to form the new data set. We never want to discard data points we have. This approach is thus appropriate when data is already well balanced and the goal is to further ensure that the propensity score is constant. A relatively simple variant of this approach, called ‘matching’ because we match triplets based on $x$, is to relax the constraint that we only consider the exact match of the covariate $x$. The original formulation samples the triplets according to the target counts with replacement from the following multiset:[Notes 2]

[] \begin{align} D(x) = \left\{ (a',y',x') \in D | x' = x \right\}. \end{align} []

This condition of $x' = x$ may be too strict, leaving us with only a very small $D(x)$. We can instead relax this condition using a predefined notion of similarity such that

[] \begin{align} \tilde{D}(x) = \left\{ (a',y',x') \in D | s(x',x) \lt \epsilon \right\}, \end{align} []

where $s(x',x)$ is a predefined distance function and $\epsilon$ a distance threshold.

## General references

Cho, Kyunghyun (2024). "A Brief Introduction to Causal Inference in Machine Learning". arXiv:2405.08793 [cs.LG].

## Notes

1. $y^*(a,x)$ is the true expected outcome given the action $a$ and the covariate $x$. Since expectation is linear, we can push the expectation all the way inside to obtain this expression.
2. It is a multiset, since there can be duplicates.