
Image by Editor
Imagine a hot, sunny summer day. There is an ice cream truck in the park. The more intense the heat, the more you may crave a refreshing ice cream. Indeed, ice cream sales peak on the hottest days of summer. This is a correlation between two variables — temperature and ice cream sales. In other words, there is a positive statistical association between them: as one increases, so does the other.
But there is also causation: changes in one variable can cause changes in the other, as rising temperatures lead to more ice cream sales. Still, correlations between variables do not always imply causation. Take, for instance, a crowded beach. Hotter summer days might contribute to more crowded beaches, but many other factors—school holidays, weekend effects, special events—also influence how crowded a beach is. There is correlation, but not necessarily direct causation, between temperature and beach crowding.
In this article, we take a practical, experimental look at the difference between these two concepts using synthetic data. This article aims to reinforce the concepts from the related article, which explains both phenomena at a more theoretical, example-based level.
Experiment 1: Strong Correlation Without Causation
Let us suppose we have an unobserved variable Z that influences two other variables, X and Y. Suppose also there is no direct causal link between X and Y. Formally, we have:
- Z → X
- Z → Y
In a setting like this, any association between X and Y is entirely induced by Z. To show this, let’s generate random synthetic data in which both X and Y are causally related to Z:
import numpy as np import matplotlib.pyplot as plt np.random.seed(0) n = 500 Z = np.random.normal(0, 1, n) X = 2 * Z + np.random.normal(0, 0.5, n) Y = -3 * Z + np.random.normal(0, 0.5, n)
We now visualize and analyze the correlation between X and Y with a scatter plot:
plt.scatter(X, Y, alpha=0.6)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Strong Correlation Induced by a Hidden Confounder")
plt.show()
This scatter plot shows what looks like a strong, neat linear relationship. A routine correlation analysis would also report a high correlation coefficient, seemingly reinforcing the hypothesis of a causal relationship.
In fact, we must be cautious: changes in X do not imply direct changes in Y. If we condition our analysis on Z, the correlation between X and Y largely vanishes. This is the classic unobserved confounder problem: a crucial, unmeasured variable (Z) influences both the presumed cause (X) and the observed outcome (Y), creating a misleading association that can bias causal conclusions.
The bottom line: correlation can arise from shared dependence on a third variable, but this does not entail a causal relationship between the original pair.
Experiment 2: True Causation, Misleading Correlation
Now consider the opposite scenario — there is real causation, but correlation alone cannot reveal it.
Assume X causally determines Y, but the relationship is nonlinear:
Y = X2 + ε
This relationship is symmetric around zero; therefore, linear correlation is not a reliable diagnostic. Again, we generate synthetic data to model this relationship:
X = np.random.uniform(-3, 3, n) Y = X**2 + np.random.normal(0, 2, n)
We visualize the causal relationship between the two variables:
plt.scatter(X, Y, alpha=0.6)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Causal Relationship with Near-Zero Linear Correlation")
plt.show()
And now we check the correlation:
np.corrcoef(X, Y)[0, 1]
Result: -0.01765012044560265
Despite the clear causal relationship between X and Y, the Pearson correlation coefficient is very close to zero. This is a situation in which a classical correlation analysis might conclude there is no relationship between X and Y — even though modifying X unquestionably changes the distribution of Y.
Therefore, the absence of correlation does not always imply the absence of causation. Each measure captures a specific kind of dependency between variables, and they should not be conflated.
Final Thoughts
We presented two experiments that illustrate why correlation and causation are not the same. Two fundamental failure modes emerged: correlation can appear where causation does not exist, and it can disappear where causation is real.
From a practical perspective, it is important to remember that predictive models such as supervised machine learning classifiers and regressors exploit correlation. Meanwhile, decisions, policies, and interventions based on data analyses require causation.
