# Instrumental Variables: When Confounders were not Collected

So far in this section we have considered a case where the confounder $x$ was available in the observational data. This allowed us to either fit the regressor directly on $p(y|a,x)$, use inverse probability weighting or re-balance the dataset using the matching scheme. It is however unlikely that we are given full access to the confounders (or any kind of covariate) in the real world. It is thus important to come up with an approach that works on passively collected data without covariates.

An instrumental variable estimator. Let us rewrite the following graph $G_0$ into a corresponding structural causal model:

The structural causal model is then

[] \begin{align} &x \leftarrow \epsilon_x \\ &a \leftarrow f_a(x, \epsilon_a) \\ &y \leftarrow f_y(a, x, \epsilon_y). \end{align} []

From this structural causal model, we can read out two important points. First, as we have learned earlier in Confounders, Colliders and Mediators, $x$ is a confounder, and when it is not observed, the path $a \leftarrow x \to y$ is open, creating a spurious effect of $a$ on $y$. Second, the choice of $a$ is not fully determined by $x$. It is determined by the combination of $x$ and $\epsilon_a$, where the latter is independent of $x$. We are particularly interested in the second aspect here, since it gives us an opportunity to modify this graph by introducing a new variable that may help us remove the effect of the confounder $x$. We now consider an alternative to the structural causal model above by assuming that we found another variable $z$ that largely explains the exogenous factor $\epsilon_a$. That is, instead of saying that the action $a$ is determined by the combination of the covariate $x$ and an exogenous factor $\epsilon_a$, we now say that it is determined by the combination of the covariate $x$, this new variable $z$ and an exogenous factor $\epsilon'_a$. Because $z$ explains a part of the exogenous factor rather than $x$, $z$ is independent of $x$ a priori. This introduction of $z$ alters the structural causal model to become

[] \begin{align} &x \leftarrow \epsilon_x \\ &z \leftarrow \epsilon_z \\ &a \leftarrow f'_a(x, z, \epsilon'_a) \\ &y \leftarrow f_y(a, x, \epsilon_y), \end{align} []

which corresponds to the following graph $G_1$:

This altered graph $G_1$ does not help us infer the causal effect of $a$ on $y$ any more than the original graph $G_0$ did. It however provides us with an opportunity to replace the original action $a$ with a proxy based purely on the newly introduced variable $z$ independent of $x$. We first notice that $x$ cannot be predicted from $z$, because $z$ and $x$ are by construction independent. The best we can do is thus to predict the associated action.[Notes 1] Let $p_{\tilde{a}}(a|z)$ be the conditional distribution induced by $g_{\tilde{a}}(z, \epsilon_a'')$. Then, we want to find $g_a$ that minimizes

[] \begin{align} \mathcal{E}_a = - \mathbb{E}_{\epsilon_z} \mathbb{E}_{\epsilon_x} \mathbb{E}_{\epsilon'_a} \left[ \log g_{\tilde{a}}(f'_a(\epsilon_x, z, \epsilon'_a), z) \right]. \end{align} []

We also notice that $z$ cannot be predicted from $a$ perfectly without $x$, because $a$ is an observed collider, creating a dependency between $z$ and $x$. The best we can do is to thus to predict the expected value of $z$. That is, we look for $g_z$ that minimizes

[] \begin{align} \mathcal{E}_z = - \mathbb{E}_{\epsilon_z} \mathbb{E}_{\epsilon_x} \left[ \log p_{\tilde{z}}(\epsilon_z | f'_a(\epsilon_x, \epsilon_z, \epsilon'_a)) \right], \end{align} []

where we have used $p_{\tilde{z}}(z|a)$ be the conditional distribution induced by $g_{\tilde{z}}(a, \epsilon'_z)$, similarly to $p_{\tilde{a}}(a|z)$ above. Once we found reasonable solutions, $\hat{g}_{\tilde{a}}$ and $\hat{g}_{\tilde{z}}$, to the minimization problems above, respectively, we can further modify the structural causal model into

[] \begin{align} &a \leftarrow \hat{a} \\ &x \leftarrow \epsilon_x \\ &\tilde{z} \leftarrow \hat{g}_{\tilde{z}}(a, \epsilon'_z) \\ &\tilde{a} \leftarrow \hat{g}_{\tilde{a}}(\tilde{z}, \epsilon''_a) \\ &y \leftarrow f_y(\tilde{a}, x, \epsilon_y). \end{align} []

Since $x$ is really nothing but an exogenous factor of $y$ without impacting $\tilde{a}$ nor $z$ in this case, we can simplify this by merging $x$ and $\epsilon_y$ into

[] \begin{align} &a \leftarrow \hat{a} \\ &\tilde{z} \leftarrow \hat{g}_z(a, \epsilon'_z) \\ &\tilde{a} \leftarrow \hat{g}_{\tilde{a}}(\tilde{z}, \epsilon''_a) \\ &y \leftarrow f_y(\tilde{a}, \epsilon'_y). \end{align} []

Because we assume the action $a$ is always given, we simply set it to a particular action $\hat{a}$. This structural causal model can be depicted as the following graph $G_2$:

In other words, we start from the action, approximately infer the extra variable $\tilde{z}$, approximately infer back the action and then predict the outcome. During two stages of inference ($\tilde{z} | a$ and $\tilde{a} | \tilde{z}$), we drop the dependence of $a$ on $z$. This happens, because $z$ was chosen to be independent of $x$ a priori. In this graph, we only have two mediators in sequence, $\tilde{z}$ and $\tilde{a}$, from the action $a$ to the outcome $y$. We can then simply marginalize out both of these mediators in order to compute the interventional distribution over $y$ given $a$, as we learned in Confounders, Colliders and Mediators. That is,

[] \begin{align} \hat{y}_{G_0}(a = \hat{a}) = \hat{y}_{G_1}(a = \hat{a}) \approx \hat{y}_{G_2}(a = \hat{a}) = \mathbb{E}_{\tilde{z}|\hat{a}} \mathbb{E}_{\tilde{a}|\tilde{z}} \mathbb{E}_{y|\tilde{a}} \left[ y \right]. \end{align} []

We call this estimator an instrumental variable estimator and call the extra variable $z$ an instrument. Unlike the earlier approaches such as regression and IPW, this approach is almost guaranteed to give you a biased estimate of the causal effect. Assume we are provided with $D=\left\{ (a_1, y_1, z_1), \ldots, (a_N, y_N, z_N) \right\}$ after we are done estimating those functions above. We can then get the approximate causal effect of the action of interest $\hat{a}$ by

[] \begin{align} \label{eq:iv_estimate} \hat{y}_{\mathrm{IV}}(\hat{a}) \approx \frac{ \sum_{n=1}^N \mathds{1}(a_n = \hat{a}) \mathbb{E}_{\epsilon''_a, \epsilon'_y} \hat{f}_y(\hat{g}_{\tilde{a}}(z_n, \epsilon''_a), \epsilon'_y) }{ \sum_{n'=1}^N \mathds{1}(a_{n'} = \hat{a}) }. \end{align} []

Additionally, if we are provided further with $D_{\bar{z}}=\left\{ (a'_1, y'_1), \ldots, (a'_{N'}, y'_{N'}) \right\}$, we can use $\hat{g}_z(a, \epsilon'_z)$ to approximate this quantity, together with $D$. Let $(a_n,y_n,r_n,z_n) \in \bar{D}$ be

[] \begin{align} (a_n,y_n,r_n,z_n) = \begin{cases} (a_n, y_n, 1, z_n),&\text{ if } n \leq N \\ (a'_{n-N'+1}, y'_{n-N'+1}, 0, -1),&\text{ if } N \lt n \leq N+N' \end{cases} \end{align} []

Then,

[] \begin{align} \hat{y}_{\mathrm{IV}}(\hat{a}) \approx \sum_{n=1}^{N+N'} \frac{ \mathds{1}(a_n = \hat{a}) \mathbb{E}_{\epsilon''_a, \epsilon'_y, \epsilon'_z} \left[ r_n \hat{f}_y(\hat{g}_{\tilde{a}}( z_n, \epsilon''_a), \epsilon'_y) + (1-r_n) \hat{f}_y(\hat{g}_{\tilde{a}}( \hat{g}_z(a_n, \epsilon'_z), \epsilon''_a), \epsilon'_y) \right] }{ \sum_{n'=1}^{N+N'} \mathds{1}(a_{n'} = \hat{a}) }. \end{align} []

In the former case, we must solve two regression problems, finding $\hat{f}_y$ and $\hat{g}_{\tilde{a}}$. When we do so by solving a least squares problem for each, we end up with two least squares problems that must be solved sequentially. Such a case is often referred as two-stage least squares. In the latter case, we benefit from extra data by solving three regression problems. Though, in most cases, we choose an easy-to-obtain instrument so that it is often enough to solve two regression problems. There are two criteria that need to be considered when choosing an instrument $z$. First, the instrument must be independent of the confounder $x$ a priori. If this condition does not hold, we end up with the following graph:

The undirected edge between $z$ and $x$ indicates that they are not independent. In this case, even if we manage to remove the edge between $a$ and $x$, there is still a spurious path $a \leftarrow z \leftrightarrow x \to y$, that prevents us from avoiding this bias. This first criterion is therefore the most important consideration behind choosing an instrument.

Instrumental variables must be predictive of the action. The second criterion is that $z$ be a cause of $a$ together with $x$. That is, a part of whatever cannot be explained by $x$ in determining $a$ must be captured by $z$. We can see why this is important by recalling the IPW-based estimate against the instrumental variable based estimate. The IPW-based estimate from Eq.eq:ipw2 is reproduced here as

[] \begin{align} \hat{y}_{\mathrm{IPW}}(\hat{a}) \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} []

If we contrast it with the instrument variable based estimate in Eq.\eqref{eq:iv_estimate}, we get

[] \begin{align} \hat{y}_{\mathrm{IPW}}(\hat{a}) - \hat{y}_{\mathrm{IV}}(\hat{a}) = \frac{ \sum_{n=1}^N \mathds{1}(a_n = \hat{a}) \overbrace{ \left( \frac{y_n} {\hat{p}(\hat{a} | x_n)} - \mathbb{E}_{\epsilon_y, \epsilon''_a} \hat{f}_y(\hat{g}_{\tilde{a}}(z_n, \epsilon''_a), \epsilon_y) \right) }^{ \mathrm{(a)} } }{ \sum_{n'=1}^N \mathds{1}(a_{n'} = \hat{a}) }, \end{align} []

where we assume $D=\left\{ (a_1, y_1, x_1, z_1), \ldots, (a_N, y_N, x_N, z_N)\right\}$. There are two estimates within (a) above that result in a bias. Among these two, $\hat{f}_y$ and $\hat{g}_{\tilde{a}}$, the former does not stand a chance of being an unbiased estimate, because it is not given the unbiased estimate of the action nor the covariate $x$. Contrast this with the regression-based estimate above where $\hat{f}_y$ afforded to rely on the true (sampled) action and the true (sampled) covariate. The latter is however where we have a clear control over. Assume that $f^*_y$ is linear. That is,

[] \begin{align} f^*_y(a, x, \epsilon_y) = a^\top \alpha^* + x^\top \beta^* + \epsilon_y, \end{align} []

where $\alpha$ and $\beta$ are the coefficients. If $\mathbb{E}[x]=0$ and $a$ is selected independent of $x$,

[] \begin{align} f^*_y(a, \epsilon_y) = a^\top \alpha^* + \epsilon_y. \end{align} []

The term (a), with the assumption that $\frac{y_n}{\hat{p}(a_n|x)} = f^*_y(a_n)$, can then be expressed as

[] \begin{align} \left(a_n - \mathbb{E}_{\epsilon''_a} \hat{g}_{\tilde{a}}(z_n, \epsilon''_a)\right)^\top \alpha^* - \mathbb{E}_{\epsilon''_a}\left[\hat{g}_{\tilde{a}}(z_n, \epsilon''_a)\right]^\top r_{\alpha}, \end{align} []

where $r_{\alpha}$ is the error in estimating $\alpha^*$, i.e., $\hat{\alpha}=\alpha^* + r_{\alpha}$. For brevity, let $\hat{g}(z_n) = \mathbb{E}_{\epsilon''_a} \hat{g}_{\tilde{a}}(z_n, \epsilon''_a)$, which allows us to rewrite it as

[] \begin{align} \left(a_n - \hat{g}(z_n)\right)^\top \alpha^* - \hat{g}(z_n)^\top r_{\alpha}. \end{align} []

Let us now look at the overall squared error:

[] \begin{align} \frac{1}{M} \sum_{m=1}^M \left( a_m^\top \alpha^* - \hat{g}(z_m)^\top (\alpha^* - r_{\alpha}) \right)^2, \end{align} []

where we use $m$ to refer to each example with $a_m=\hat{a}$. If we further expand the squared term,

[] \begin{align} &\frac{1}{M} \sum_{m=1}^M {\alpha^*}^\top a_m a_m^\top \alpha^* + (\alpha^* - r_{\alpha})^\top \hat{g}(z_m) \hat{g}^\top(z_m) (\alpha^* - r_{\alpha}) -2 {\alpha^*}^\top a_m \hat{g}^\top(z_m) (\alpha^* - r_{\alpha}) \\ &\approx {\alpha^*}^\top \mathbb{E}[a a^\top] \alpha^* + (\alpha^* - r_{\alpha})^\top \mathbb{E}[ \hat{g}(z) \hat{g}^\top(z) ](\alpha^* - r_{\alpha}) - 2 {\alpha^*}^\top \mathbb{E}[a \hat{g}^\top(z)] (\alpha^* - r_{\alpha}). \end{align} []

The first term is constant. It simply tells us that the error would be greater if the variance of the relevant dimensions of the action on the outcome, where the relevancy is determined by $\alpha^*$, is great, the chance of mis-approximating it would be simply great as well. The second term tells us that the error would be proportional to the variance of the relevant dimensions of the predicted action on the outcome, where the relevancy is determined by the predicted coefficient, $\alpha^* - \hat{r}$. That is, if the variance of the predicted outcome is great, the chance of a large error is also great. The third term is where we consider the correlation between the true action and the predicted action, again along the dimensions of relevance. This derivation tells us that the instrument must be selected to be highly predictive of the action (the third term) but also exhibit a low variance in its prediction (the second term). Here comes the classical dilemma of bias-variance trade-off in machine learning.

The linear case. The instrument variable approach is quite confusing. Consider a 1-dimensional fully linear case here in order to build up our intuition. Assume

[] \begin{align} &x \leftarrow \epsilon_x \\ &a \leftarrow \gamma x + \epsilon_a \\ &y \leftarrow \alpha a + \beta x + \epsilon_y, \end{align} []

where $\epsilon_x$ and $\epsilon_y$ are both zero-mean Normal variables. If we intervene on $a$, we would find that the expected outcome equals

[] \begin{align} \mathbb{E}[y|\mathrm{do}(a)] = \alpha a, \end{align} []

and thereby the ATE is

[] \begin{align} \mathrm{ATE} = \mathbb{E}[y|\mathrm{do}(a=1)] - \mathbb{E}[y|\mathrm{do}(a=0)] = \alpha. \end{align} []

With a properly selected instrument $z$, that is, $z \indep x$, we get

[] \begin{align} &z \leftarrow \epsilon_z \\ &a \leftarrow \gamma x + \psi z + \epsilon'_a. \label{eq:instrument-predicted-action} \end{align} []

Because $z\indep x$, the best we can do is to estimate $\psi$ to minimize

[] \begin{align} \label{eq:iv-1st-ls} \min_\psi \sum_{n=1}^N (a_n - \psi z_n)^2, \end{align} []

given $N$ $(a,z)$ pairs. The minimum attainable loss is

[] \begin{align} (\gamma x)^2, \end{align} []

assuming zero-mean $\epsilon'_a$, because the contribution from $x$ cannot be explained by the instrument $z$. With the estimated $\hat{\psi}$, we get

[] \begin{align} \hat{a} \leftarrow \hat{\psi} z + \epsilon''_a, \end{align} []

and know that

[] \begin{align} \hat{a} = a - \gamma x \end{align} []

on expectation. By plugging in $\hat{a}$ into the original structural causal model, we end up with

[] \begin{align} &x \leftarrow \epsilon_x \\ &\hat{a} \leftarrow \hat{\psi} z + \epsilon''_a \label{eq:iv-hat-a} \\ &y \leftarrow \tilde{\alpha} \hat{a} + \beta x + \epsilon_y'. \end{align} []

We can now estimate $\tilde{\alpha}$ by minimizing

[] \begin{align} \label{eq:iv-2nd-ls} \sum_{n=1}^N \left( y_n - \tilde{\alpha} \hat{a}_n \right)^2, \end{align} []

assuming both $\epsilon_x$ and $\epsilon_y'$ are centered. If we assume we have $x$ as well, we get

[] \begin{align} & \sum_{n=1}^N \left( y_n - \tilde{\alpha} (a_n - \gamma x_n) \right)^2 \\ &= \sum_{n=1}^N \left( y_n - \alpha (a_n - \gamma x_n) + (\alpha - \tilde{\alpha}) (a_n - \gamma x_n) \right)^2 \\ &= \sum_{n=1}^N \left( \epsilon_{y,n} + (\alpha - \tilde{\alpha}) \epsilon_{a,n}' \right)^2 \\ &= \sum_{n=1}^N \left( \epsilon_{y,n}^2 + (\alpha - \tilde{\alpha})^2 (\epsilon_{a,n}')^2 + 2 (\alpha - \tilde{\alpha}) \epsilon_{y,n} \epsilon_{a,n}' \right) \\ &=_{n\to\infty} \mathbb{V}[\epsilon_y] + (\alpha - \tilde{\alpha})^2 \mathbb{V}[\epsilon_a']. \end{align} []

The first term is irreducible, and therefore we focus on the second term. The second term is the product of two things. The first one, $(\alpha - \tilde{\alpha})^2$, measures the difference between the correct $\alpha$ and the estimated effect. It tells us that minimizing this loss w.r.t. $\tilde{\alpha}$ is the right way to approximate the true causal effect $\alpha$. We can plug in $\hat{a}$ from Eq.\eqref{eq:iv-hat-a} instead:

[] \begin{align} & \sum_{n=1}^N \left( y_n - \tilde{\alpha} (\hat{\psi} z_n + \epsilon''_{a,n}) \right)^2 \\ &= \sum_{n=1}^N \left( (y_n - \tilde{\alpha} \hat{\psi} z_n) + \tilde{\alpha} \epsilon''_{a,n} \right)^2 \\ &= \sum_{n=1}^N \left( (y_n - \tilde{\alpha} \hat{\psi} z_n)^2 + \tilde{\alpha}^2 (\epsilon''_{a,n})^2 + 2 (y_n - \tilde{\alpha} \hat{\psi} z_n) \tilde{\alpha} \epsilon_{a,n}'' \right) \\ &=_{n\to\infty} \sum_{n=1}^N (y_n - \tilde{\alpha} \hat{\psi} z_n)^2 + \tilde{\alpha}^2 \mathbb{V}[\epsilon''_a]. \end{align} []

The first term is about how predictive the instrument $z$ is of $y$, which is a key consideration in choosing the instrument. If the instrument is not predictive of $y$, the instrument variable approach fails dramatically. The second term corresponds to the variance of the action not explained by the instrument, implying that the instrument must also be highly correlated with the action. In this procedure, we have solved least squares twice, \eqref{eq:iv-1st-ls} and \eqref{eq:iv-2nd-ls}, which is a widely used practice with instrument variables. We also saw the importance of the choice of the instrument variable.

An example: taxation One of the most typical example of an instrument is taxation. It is particularly in the United States of America (USA), due to the existence of different tax laws and rates across fifty states. For instance, imagine an example where the action is cigarette smoking, the outcome is the contraction of lung cancer and the confounder is an unknown genetic mutation that both affects the affinity to nicotine addiction and the incidence of a lung cancer. Because we do not know such a genetic mutation, we cannot easily draw a conclusion about the causal effect of cigarette smoking on lung cancer. There may be a spurious correlation arising from this unknown, and thereby unobserved, genetic mutation. Furthermore, it is definitely unethical to randomly force people to smoke cigarettes, which prevents us from running an RCT. We can instead use state-level taxation on tobacco as an instrument, assuming that lower tax on tobacco products would lead to a higher chance and also rate of smoking, and vice versa. First, we build a predictor of smoking from the state (or even county, if applicable) tax rate. The predicted amount of cigarettes smoked by a participant can now work as a proxy to the original action, that is the actual amount of cigarettes smoked. We then build a predictor of the incidence of lung cancer as well as the reverse predictor (action-to-instrument prediction). We can then use one of the two instrument variable estimators above to approximate the potential outcome of smoking on lung cancer.

## General references

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

## Notes

1. We can predict the marginal distribution over the action after marginalizing out $x$.