# A Basic Setup

## Correlation, Independence and Causation

Two random variables, $u$ and $v$, are independent if and only if

[] \begin{align} p(u, v) = p(u) p(v). \end{align} []

That is, the probability of $u$ taking a certain value is not affected by that of $v$ taking another value. We say $u$ and $v$ are dependent upon each other when the condition above does not hold. In everyday life, we often confuse dependence with correlation, where two variables are correlated if and only if

[] \begin{align} \mathrm{cov}(u,v) = \mathbb{E}\left[ (u - \mu_u) (v - \mu_v) \right] \gt 0, \end{align} []

where $\mu_u = \mathbb{E}[u]$ and $\mu_v = \mathbb{E}[v]$. When this covariance is $0$, we say these two variables are uncorrelated. Despite our everyday confusion, these two quantities are only related and not equivalent. When two variables are independent, they are also uncorrelated, but when two variables are uncorrelated, they may not be independent. Furthermore, it turned out these two quantities are also only remotely related to the existence/lack of causation between two variables. You must have heard of the statement “correlation does not imply causation.” There are two sides to this statement. First, the existence of correlation between two variables does not imply that there exists a causal relationship between these two variables. An extreme example of this is tautology; if the relationship between $u$ and $v$ is identity, there is no causal relationship but the correlation between these two is maximal. Second, the lack of correlation does not imply the lack of causation. This is the more important aspect of this statement. Even if there is no correlation between two variables, there could be a causal mechanism behind these two variables. Although it is a degenerate case, consider the following structural causal model:

[] \begin{align} &a \leftarrow -u + \epsilon_a \\ &b \leftarrow +u + \epsilon_b \\ &v \leftarrow a + b + \epsilon_v. \end{align} []

The value of $v$ is caused by $u$ via two paths; $u \to a \to v$ and $u \to b \to v$, but these paths cancel each other. If we only observe $(u,v)$ pairs, it is easy to see that they are uncorrelated, since $v$ is constant. We will have more discussion later in the semester, but it is good time for you to pause and think whether these two paths matter, since they cancel each other. Consider as another example the following structural causal model:

[] \begin{align} &z \leftarrow \epsilon_z \\ &u \leftarrow 0.2 z + \sqrt{1.04} \epsilon_u \\ &v \leftarrow 0.1 u - 0.5 z + 0.1 \epsilon_v, \end{align} []

where $\epsilon_z$, $\epsilon_u$ and $\epsilon_v$ are all standard Normal variables. Again, the structural causal model clearly indicates that $u$ causally affects $v$ via $0.1 u$, but the correlation between $u$ and $v$ is $0$ when we consider those two variables alone (that is, after marginalizing out $z$). This second observation applies equally to independence. That is, the independence between two variables does not imply the lack of a causal mechanism between two variables. The examples above apply here equally, as two uncorrelated Normal variables are also independent. This observation connects to an earlier observation that there are potentially many data generating processes that give rise to the same conditional distribution between two sets of variables. Here as well, the independence or correlatedness of two variables may map to many different generating processes that encode different causal mechanisms behind these variables. In other words, we cannot determine the causal relationship between two variables (without loss of generality) without predefining the underlying generating process (in terms of either the probabilistic graphical model or equivalently the structural causal model.)[Notes 1] In other words, we must consider both variables of interest and the associated data generating model in order to determine whether there exists a causal relationship between these variables and what that relationship is.

## Confounders, Colliders and Mediators

Let us consider a simple scenario where there are only three variables; $u$, $v$ and $w$. We are primarily interested in the relationship between the first two variables; $u$ and $v$. We will consider various ways in which these three variables are connected with each other and how such wiring affects the relationship between $u$ and $v$.

Directly connected. Consider the following probabilistic graphical model.

$w$ does not affect either $u$ nor $v$, while $u$ directly causes $v$. In this case, the causal relationship between $u$ and $v$ is clear. If we perturb $u$, it will affect $v$, according to the conditional distribution $p_v(v | u)$. This tells us that we can ignore any node in a probabilistic graphical model that is not connected to any variable of interest.

An observed confounder. Consider the following probabilistic graphical model, where $w$ is shaded, which indicates that $w$ is observed.

In this graph, the value/distribution of $u$ and that of $v$ are both determined individually already because we have observed $w$. This corresponds to the definition of conditional independence;

[] \begin{align} p(u,v |w) = p(u|w) p(v|w). \end{align} []

Because the edge is directed from $w$ to $u$, perturbing $u$ does not change the observed value of $w$. The same applies to $v$ as well, since perturbing $v$ does not affect $u$, since this path between $u$ and $v$ via $w$ is blocked by observing $w$.

An unobserved confounder. Consider the case where $w$ was not observed.

We first notice that in general

[] \begin{align} p(u,v) = \int_w p(u|w)p(v|w)p(w) \mathrm{d}w \neq q(u)q(v), \end{align} []

implying that $u$ and $v$ are not independent, unlike when $w$ was not observed. In other words, $u$ and $v$ are not conditionally independent given $w$. Perturbing $u$ however still does not affect $v$, since the value of $w$ is not determined by the value of $u$ according to the corresponding causal structural model. That is, $u$ does not affect $v$ causally (and vice versa.) This is the case where the independence and causality start to deviate from each other; $u$ and $v$ are not independent but each is not the cause of the other. Analogous to the former case of the observed $w$, where we say the path $u \leftarrow w \to v$ was closed, we say that the same path is open in this latter case. Because of this effect $w$ has, we call it a confounder. The existence of a confounder $w$ makes it difficult to tell whether the dependence between two variables we see is due to a causal relationship between these variables. $w$ confounds this analysis.

An observed collider. Consider the following graph where the arrows are flipped.

In general,

[] \begin{align} p(u,v | w) = \frac{p(w|u, v) p(u) p(v)} {\int \int p(w|u, v) p(u) p(v) \mathrm{d}u \mathrm{d}v} \neq q(u) q(v), \end{align} []

which means that $u$ and $v$ are not independent conditioned on $w$. This is sometimes called the explaining-away effect, because observing $w$ explains away one of two potential causes behind $w$. Although $u$ and $v$ are not independent in this case, there is no causal relationship between $u$ and $v$. $w$ is where the causal effects of $u$ and $v$ collide with each other (hence, $w$ is a collider) and does not pass along the causal effect between $u$ and $v$. Similarly to the case of an unobserved confounder above, this is one of those cases where independence does not imply causation. We say that the path $u \to w \leftarrow v$ is open.

An unobserved collider. Consider the case where the collider $w$ is not observed.

By construction, $u$ and $v$ are independent, as

[] \begin{align} p(u,v) = \int p(u) p(v) p(w|u,v) \mathrm{d}w = p(u) p(v) \int p(w | u, v) \mathrm{d}w = p(u) p(v). \end{align} []

Just like before, neither $u$ or $v$ is the cause of the other. This path is closed.

An observed mediator. Consider the case where there is an intermediate variable between $u$ and $v$:

Because

[] \begin{align} p(u,v | w) = p(u) p(w|u) p(v|w) = q(u|w) q(v|w) \end{align} []

$u$ and $v$ are independent conditioned on $w$. However, perturbing $u$ does not affect $v$, since the value of $w$ is observed (that is, fixed.) We say that $u \to w \to v$ is closed in this case, and independence implies the lack of causality.

An unobserved mediator. What if $w$ is not observed, as below?

It is then clear that $u$ and $v$ are not independent, since

[] \begin{align} p(u,v) = \int p(u) p(w|u) p(v|w) \mathrm{d} w = p(u) \int p(w|u) p(v|w) \mathrm{d} w = p(u) q(v|u). \end{align} []

Perturbing $u$ will change the distribution/value of $w$ which will consequently affect that of $v$, meaning that $u$ causally affects $v$. This effect is mediated by $w$, and hence we call $w$ a mediator.

## Dependence and Causation

We can chain the rules that were defined between three variables; $u$, $v$ and $w$, in order to determine the dependence between two nodes, $u$ and $v$, within any arbitrary probabilistic graphical model given a set $Z$ of observed nodes. This procedure is called D-separation, and it tells us two things. First, we can check whether

[] \begin{align} u \indep_Z v. \end{align} []

More importantly, however, we get all open paths between $u$ and $v$. These open paths are conduits that carry statistical dependence between $u$ and $v$ regardless of whether there is a causal path between $u$ and $v$, where we define a causal path as an open directed path between $u$ and $v$.[Notes 2] Dependencies arising from open, non-causal paths are often casually referred to as ‘spurious correlation’ or ‘spurious dependency’. When we are performing causal inference for the purpose of designing a causal intervention in the future, it is imperative to dissect out these spurious correlations and identify true causal relationship between $u$ and $v$. It is however unclear whether we want to remove all spurious dependencies or whether we should only remove spurious dependencies that are unstable, when it comes to prediction in machine learning. We will discuss more about this contention later in the course. In this course, we do not go deeper into D-separation. We instead stick to a simple setting where there are only three or four variables, so that we can readily identify all open paths and determine which are causal and which others are spurious.

## Causal Effects

We have so far avoided defining more carefully what it means for a node $u$ to effect another node $v$ causally. Instead, we simply said $u$ effects $v$ causally if there is a directed path from $u$ to $v$ under the underlying data generating process. This is however unsatisfactory, as there are loopholes in this approach. The most obvious one is that some of those directed edges may correspond to a constant function. For instance, an extreme case is where the structural causal model is

[] \begin{align} &a \leftarrow f_a(u, \epsilon_a) \\ &v \leftarrow f_v(a, \epsilon_v), \end{align} []

where $f_a(\cdot) = 0$. In this case, the edge from $u$ to $a$ is effectively non-existent, although we wrote it as if it existed. Rather, we want to define a causal effect of $u$ on $v$ by thinking of how perturbation on $u$ propagates over the data generating process and arrives at $v$. More specifically, we consider forcefully setting the variable $u$ (the cause variable) to an arbitrary value $\hat{u}$. This corresponds to replacing the following line in the structural causal model $G=(V,F,U)$

[] \begin{align} u \leftarrow f_u(\mathrm{pa}(u), \epsilon_u) \end{align} []

with

[] \begin{align} u \leftarrow \hat{u}. \end{align} []

$\hat{u}$ can be a constant or can also be a random variable as long as it is not dependent on any other variables in the structural causal model. Once this replacement is done, we run this modified structural causal model $\overline{G}(\hat{u})=(\overline{V},\overline{F},U)$ in order to compute the following expected outcome:

[] \begin{align} \mathbb{E}_{U}[v_{\overline{\mathcal{G}}(\hat{u})}], \end{align} []

where $U$ is a set of exogenous factors (e.g. noise.) If $u$ does not affect $v$ causally, this expected outcome would not change (much) regardless of the choice of $\hat{u}$. As an example, assume $u$ can take either $0$ or $1$, as in treated or placebo. We then check the expected treatment effect on the outcome $v$ by

[] \begin{align} \mathbb{E}_{U}[v_{\overline{\mathcal{G}}(\hat{u}=1)}] - \mathbb{E}_{U}[v_{\overline{\mathcal{G}}(\hat{u}=0)}]. \end{align} []

We would want this quantity to be positive and large to know that the treatment has a positive causal effect on the outcome. This procedure of forcefully setting a variable to a particular value is called a $\mathrm{do}$ operator. The impact of $\mathrm{do}$ is more starkly demonstrated if we consider a probabilistic graphical model rather than a structural causal model. Let $p_u(u | \mathrm{pa}(u))$ be the conditional distribution over $u$ in a probabilistic graphical model $G=(V,E,P)$. We construct a so-called interventional distribution as

[] \begin{align} p(v | \mathrm{do}(u = \hat{u})), \end{align} []

which states that we are now forcefully setting $u$ to $\hat{u}$ instead of letting it be a sample drawn from the conditional distribution $p_u(u | \mathrm{pa}(u))$. That is, instead of

[] \begin{align} u \sim u | \mathrm{pa}(u), \end{align} []

we do

[] \begin{align} u \leftarrow \hat{u}. \end{align} []

In other words, we replace the conditional probability $p_u(u | \mathrm{pa}(u))$ with

[] \begin{align} p_u(u | \mathrm{pa}(u)) = \delta(u - \hat{u}), \end{align} []

where $\delta$ is a Dirac measure, or replace all occurrences of $u$ in the conditional probabilities of $\mathrm{child}(u)$ with a constant $\hat{u}$, where

[] \begin{align} \mathrm{child}(u) = \left\{ u' \in V | (u, v') \in E \right\}. \end{align} []

As a consequence, in the new modified graph $\overline{G}$, there is no edge coming into $u$ (or $\hat{u}$) anymore, i.e., $\mathrm{pa}(u) = \emptyset$. $u$ is now independent of all the other nodes a priori. Because $\mathrm{do}$ modifies the underlying data generating process, $p(v|u=\hat{u}; G)$ and $p(v|\mathrm{do}(u=\hat{u}); G) = p(v|u=\hat{u}; \overline{G})$ differ from each other. This difference signifies the separation between statistical and causal quantities. We consider this separation in some minimal cases.

## Case Studies

An unobserved confounder and a direct connection. Consider the case where $w$ was not observed.

Under this graph $G$,

[] \begin{align} p_G(v|u=\hat{u}) = \frac{\sum_{w} p(w) p(\hat{u}|w) p(v|\hat{u},w)}{p(\hat{u})} = \mathbb{E}_w \left[ \frac{p(\hat{u}|w)}{p(\hat{u})} p(v| \hat{u}, w) \right], \end{align} []

from which we see that there are two open paths between $v$ and $u$:

• $u \to v$: a direct path;
• $u \leftarrow w \to v$: an indirect path via the unobserved confounder.

The statistical dependence between[Notes 3] $u$ and $v$ flows through both of these paths, while the causal effect of $u$ and $v$ only flows through the direct path $u \to v$. The application of $\mathrm{do}(u = \hat{u})$ in this case would severe the edge from $w$ to $u$, as in

Under this modified graph $\overline{G}$,

[] \begin{align} p_G(v | \mathrm{do}(u = \hat{u})) &= p_{\tilde{G}}(v | u=\hat{u}) = \frac{1}{q(\hat{u})}\sum_w p(w) q(\hat{u}) p(v | \hat{u}, w) \\ &= \sum_w p(w) p(v | \hat{u}, w) = \mathbb{E}_w \left[ p(v | \hat{u}, w) \right] , \end{align} []

where we use $q(\hat{u})$ to signify that this is not the same as $p(\hat{u})$ above. The first one $p_G(v | u = \hat{u})$ is a statistical quantity, and we call it a conditional probability. The latter $p_G(v | \mathrm{do}(u = \hat{u}))$ is instead a causal quantity, and we call it an interventional probability. Comparing these two quantities, $p_G(v | u = \hat{u})$ and $p_G(v | \mathrm{do}(u = \hat{u}))$, the main difference is the multiplicative factor $\frac{p(\hat{u}|w)}{p(\hat{u})}$ inside the expectation. The numerator $p(\hat{u}|w)$ tells us how likely this treatment $\hat{u}$ was given under $w$, while the denominator $p(\hat{u})$ tells us how likely the treatment $\hat{u}$ was given overall. In other words, we upweight the impact of $\hat{u}$ and $w$ if $\hat{u}$ was more probable under $w$ than overall. This observation will allow us to convert between these two quantities later.

An observed collider and a direct connection. Let us flip the edges from $w$ so that those edges are directed toward $w$. We further assume that we always observe $w$ to be a constant ($1$).

The $\mathrm{do}$ operator on $u$ does not alter the graph above. This means that the conditional probability and interventional probability coincide with each other in this case, conditioned on observing $w=1$. This however does not mean that the conditional probability $p(v|u=\hat{u},w=1)$, or equivalently the interventional probability $p(v|\mathrm{do}(u=\hat{u}),w=1)$, measures the causal effect of $u$ on $v$ alone. As we saw before and also can see below, there are two open paths, $u \to v$ and $u \leftarrow w \to v$, between $u$ and $v$ through which the dependence between $u$ and $v$ flows:

[] \begin{align} p(v | u, w=1) = \frac{\cancel{p(u)} p(v | u) p(w=1|u, v)}{\sum_{v'} \cancel{p(u)} p(v'| u) p(w=1|u, v')}. \end{align} []

We must then wonder whether we can separate out these two paths from each other. It turned out unfortunately that this is not possible in this scenario, because we need the cases of $w \neq 1$ (e.g. $w=0$) for this separation. If you recall how we can draw samples from a probabilistic graphical model while conditioning some variables to take particular values, it was all about selecting a subset of samples drawn from the same graph without any observed variables. This selection effectively prevents us from figuring out the effect of $u$ on $v$ via $w$. We will have more discussion on this topic later in the semester in the context of invariant prediction. Because of this inherent challenge, that may not even be addressable in many cases, we will largely stick to the case of having a confounder in this semester.

## Summary

In this chapter, we have learned about the following topics:

• How to represent a data generating process: a probabilistic graphical model vs. a structural causal model;
• How to read out various distributions from a data generating process: ancestral sampling and Bayes' rule;
• The effect of confounders, colliders and mediators on independence;
• Causal dependency vs. spurious dependency;
• The $\mathrm{do}$ operator.

## General references

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

## Notes

1. There are algorithms to discover an underlying structural causal model from data, but these algorithms also require some assumptions such as the definition of the goodness of a structural causal model. This is necessary, since these algorithms all work by effectively enumerating all structural causal models that can produce data faithfully and choosing the best one among these.
2. Unlike a usual path, in a direct path, the directions of all edges must agree with each other, i.e., pointing to the same direction.
3. We do not need to specify the direction of statistical dependence, since the Bayes' rule allows us to flip the direction.