"plt.title(\"Histogram of differences over 2000 simulations (analytic - estimate)\")\n",
"sns.kdeplot(diffs)\n",
"plt.axvline(x=0, c='r')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It can be observed that when there are no unobservables, the causal effect $$P(Y=0|do(R=r))=\\int_x P(Y=0|T=1, X=x)P(T=1|R=r, X=x)f_x(x)~dx$$ can be estimated without bias.\n",
"\n",
"Next we generate data and estimate the causal effect from a causal model with unobservables Z. \n",
"print(\"Std of differences:\", np.std(diffs))\n",
"plt.hist(diffs, bins=25)\n",
"plt.title(\"Histogram of differences over 2000 simulations (analytic - estimate)\")\n",
"sns.kdeplot(diffs)\n",
"plt.axvline(x=0, c='r')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now it is visible that the quantity $P(Y=0|do(R=r))$ is slightly biased when estimated with equation \\ref{int}.\n",
"\n",
"\n",
"According to [Pearl's Theorem 3](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2836213/): \"A *sufficient* condition for identifying the causal effect P(y|do(x)) is that every path between X and any of its children traces at least one arrow emanating from a measured variable.\""
It can be observed that when there are no unobservables, the causal effect $$P(Y=0|do(R=r))=\int_x P(Y=0|T=1, X=x)P(T=1|R=r, X=x)f_x(x)~dx$$ can be estimated without bias.
Next we generate data and estimate the causal effect from a causal model with unobservables Z.
Now it is visible that the quantity $P(Y=0|do(R=r))$ is slightly biased when estimated with equation \ref{int}.
According to [Pearl's Theorem 3](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2836213/): "A *sufficient* condition for identifying the causal effect P(y|do(x)) is that every path between X and any of its children traces at least one arrow emanating from a measured variable."