|
89 | 89 | }, |
90 | 90 | { |
91 | 91 | "cell_type": "code", |
92 | | - "execution_count": 2, |
| 92 | + "execution_count": null, |
93 | 93 | "metadata": {}, |
94 | 94 | "outputs": [], |
95 | 95 | "source": [ |
|
110 | 110 | "\n", |
111 | 111 | "def simulate_data(n=2500, alpha_true=3.0, rho=0.6, cate_estimation=False):\n", |
112 | 112 | " # Exclusion restrictions:\n", |
113 | | - " # X[0], X[1] affect both Y and D (confounders)\n", |
114 | | - " # X[2], X[3] affect ONLY D (instruments for D)\n", |
| 113 | + " # X[0], X[1] affect both Y and T (confounders)\n", |
| 114 | + " # X[2], X[3] affect ONLY T (instruments for T)\n", |
115 | 115 | " # X[4] affects ONLY Y (predictor of Y only)\n", |
116 | 116 | "\n", |
117 | 117 | " betaY = np.array([0.5, -0.3, 0.0, 0.0, 0.4, 0, 0, 0, 0]) # X[2], X[3] excluded\n", |
|
1608 | 1608 | "\n", |
1609 | 1609 | "#### Comparing Treatment Estimates\n", |
1610 | 1610 | "\n", |
1611 | | - "The comparison of models is a form of robustness checks. We want to inspect how consistent our parameter estimates are across different model specifications. " |
| 1611 | + "The comparison of models is a form of robustness checks. We want to inspect how consistent our parameter estimates are across different model specifications. Here we see how the strongly informative priors on $\\rho$ bias the treatment effect estimate. " |
1612 | 1612 | ] |
1613 | 1613 | }, |
1614 | 1614 | { |
|
1664 | 1664 | "cell_type": "markdown", |
1665 | 1665 | "metadata": {}, |
1666 | 1666 | "source": [ |
1667 | | - "In the plot we can see that the majority of models accurately estimate the true treatment effect $\\alpha$ except in the cases where we have explicitly placed an opinionated prior on the $\\rho$ parameter in the model. These priors pull the $\\alpha$ estimate away from the true data generating process. " |
1668 | | - ] |
1669 | | - }, |
1670 | | - { |
1671 | | - "cell_type": "markdown", |
1672 | | - "metadata": {}, |
1673 | | - "source": [ |
1674 | | - "Our Bayesian setup here is intentionally structural. We specify how both treatment and outcome arise from common covariates and latent confounding structures. However, the boundary between structural and reduced-form reasoning becomes fluid when we begin to treat latent variables or exclusion restrictions as data-driven “instruments.” In that sense, the structural Bayesian approach can emulate reduced-form logic within a generative model — an idea we’ll develop when we move from unconfounded to confounded data and later when we impute potential outcomes directly. But for now let's continue to examine the relationships between these structural parameters. " |
| 1667 | + "In the plot we can see that the majority of models accurately estimate the true treatment effect $\\alpha$ except in the cases where we have explicitly placed an opinionated prior on the $\\rho$ parameter in the model. These priors pull the $\\alpha$ estimate away from the true data generating process. The variable selection priors considerably shrink the uncertainty in the treatment estimates seemingly picking out the implict instrument structure aping the application of instrumental variables. \n", |
| 1668 | + "\n", |
| 1669 | + "Our Bayesian setup here is intentionally structural. We specify how both treatment and outcome arise from common covariates and latent confounding structures. However, the boundary between structural and reduced-form reasoning becomes fluid when we begin to treat latent variables or exclusion restrictions as data-driven “instruments.” In that sense, the structural Bayesian approach can emulate reduced-form logic within a generative model — an idea we’ll develop further when we move from unconfounded to confounded data and later when we impute potential outcomes directly. \n", |
| 1670 | + "\n", |
| 1671 | + "But for now let's continue to examine the relationships between these structural parameters." |
1675 | 1672 | ] |
1676 | 1673 | }, |
1677 | 1674 | { |
|
2776 | 2773 | "#### Comparing Treatment Estimates\n", |
2777 | 2774 | "\n", |
2778 | 2775 | "The forest plot below compares posterior estimates of the treatment effect ($\\alpha$) and the confounding correlation ($\\rho$) across model specifications when \n", |
2779 | | - "$\\rho = .6$ in the data-generating process. The baseline normal model (which places diffuse priors on all parameters) clearly reflects the presence of endogeneity. Its posterior mean for $\\alpha$ is biased upward relative to the true value of 3, and the estimated $\\rho$ is positive, confirming that the model detects correlation between treatment and outcome disturbances. This behaviour mirrors the familiar bias of OLS under confounding: without structural constraints or informative priors, the model attributes part of the outcome variation caused by unobserved factors to the treatment itself. This inflates and corrupts our treatment effect estimate. \n", |
2780 | | - "\n", |
2781 | | - "By contrast, models that introduce structure through priors—either by tightening the prior range on $\\rho$ or imposing shrinkage on the regression coefficients—perform noticeably better. The tight-$\\rho$ models regularize the latent correlation, effectively limiting the extent to which endogeneity can distort inference, while spike-and-slab and horseshoe priors perform selective shrinkage on the covariates, allowing the model to emphasize variables that genuinely predict the treatment. This helps isolate more valid “instrument-like” components of variation, pulling the posterior of $\\alpha$ closer to the true causal effect. \n", |
2782 | | - "\n", |
2783 | | - "The exclusion-restriction specification, which enforces prior beliefs about which covariates affect only the treatment or only the outcome, performs well too. The imposed restrictions recover both the correct treatment effect and a tight estimate of residual correlation. It may be wishful thinking that this precise instrument structure is available to an analyst in the applied setting, but instrument variable designs and their imposed exclusion restrictions should be motivated by theory. Where that theory is plausible we can hope for such precise estimates.\n", |
2784 | | - "\n", |
2785 | | - "Together, these results illustrate the power of Bayesian joint modelling: even in the presence of confounding, appropriate prior structure enables partial recovery of causal effects. Importantly, the priors do not simply “fix” the bias—they make explicit the trade-offs between flexibility and identification. This transparency is one of the key advantages of Bayesian causal inference over traditional reduced-form methods." |
| 2776 | + "$\\rho = .6$ in the data-generating process. The baseline normal model (which places diffuse priors on all parameters) clearly reflects the presence of endogeneity. Its posterior mean for $\\alpha$ is biased upward relative to the true value of 3, and the estimated $\\rho$ is positive, confirming that the model detects correlation between treatment and outcome disturbances. This behaviour mirrors the familiar bias of OLS under confounding: without structural constraints or informative priors, the model attributes part of the outcome variation caused by unobserved factors to the treatment itself. This inflates and corrupts our treatment effect estimate. " |
2786 | 2777 | ] |
2787 | 2778 | }, |
2788 | 2779 | { |
|
2838 | 2829 | "cell_type": "markdown", |
2839 | 2830 | "metadata": {}, |
2840 | 2831 | "source": [ |
| 2832 | + "By contrast, models that introduce structure through priors—either by tightening the prior range on $\\rho$ or imposing shrinkage on the regression coefficients—perform noticeably better. The tight-$\\rho$ models regularize the latent correlation, effectively limiting the extent to which endogeneity can distort inference, while spike-and-slab and horseshoe priors perform selective shrinkage on the covariates, allowing the model to emphasize variables that genuinely predict the treatment. This helps isolate more valid “instrument-like” components of variation, pulling the posterior of $\\alpha$ closer to the true causal effect. \n", |
| 2833 | + "\n", |
| 2834 | + "The exclusion-restriction specification, which enforces prior beliefs about which covariates affect only the treatment or only the outcome, performs well too. The imposed restrictions recover both the correct treatment effect and a tight estimate of residual correlation. It may be wishful thinking that this precise instrument structure is available to an analyst in the applied setting, but instrument variable designs and their imposed exclusion restrictions should be motivated by theory. Where that theory is plausible we can hope for such precise estimates.\n", |
| 2835 | + "\n", |
| 2836 | + "Together, these results illustrate the power of Bayesian joint modelling: even in the presence of confounding, appropriate prior structure enables partial recovery of causal effects. Importantly, the priors do not simply “fix” the bias—they make explicit the trade-offs between flexibility and identification. This transparency is one of the key advantages of Bayesian causal inference over traditional reduced-form methods.\n", |
| 2837 | + "\n", |
2841 | 2838 | "We can see similar patterns in the below pair plots" |
2842 | 2839 | ] |
2843 | 2840 | }, |
|
5573 | 5570 | ":::{admonition} Advice for the Practitioner\n", |
5574 | 5571 | ":class: tip\n", |
5575 | 5572 | "\n", |
5576 | | - "We have seen a number of ways in which to model the structural relationships between treatment and outcome for causal inference. In `CausalPy` we will add a flexible API to capture some of these options, but no API can be fully robust for each and every niche problem. You may wish to prioritise one or more of these components in your own modelling. Our main advice here is to model the parameters that matter - the ones that give insight into the structure of your problem. Use them to diagnose the degree of confounding. Use variable selection priors with care as a diagnostic aid for theoretical instruments. Assess your model in context with a range of reasonable alternatives and report the variation honestly. This process, the careful craft of statistical modelling, underwrites contemporary Bayesian workflow and sound causal inference.\n", |
| 5573 | + "We have seen a number of ways in which to model the structural relationships between treatment and outcome for causal inference. In `CausalPy` we will add a flexible API to capture some of these options, but no API can be fully robust for each and every niche problem. You may wish to prioritise one or more of these components in your own modelling. Our main advice here is to model the parameters that matter - the ones that give insight into _the structure of your problem_. Use the structural parameters to diagnose the degree of confounding. Use variable selection priors with care as a diagnostic aid for theoretical instruments. Assess your model in context with a range of reasonable alternatives and report the variation honestly. This process, the careful craft of statistical modelling, underwrites contemporary Bayesian workflow and sound causal inference.\n", |
5577 | 5574 | "\n", |
5578 | 5575 | ":::" |
5579 | 5576 | ] |
|
0 commit comments