causalis.scenarios.did.refutation.post_inference_plots

Module Contents

Functions

plot_did_post_inference_event_study

Plot the fitted CS event-study estimates with confidence intervals.

plot_did_influence_concentration

Plot top unit-level influence shares for the simple overall ATT.

Data

__all__

API

causalis.scenarios.did.refutation.post_inference_plots.plot_did_post_inference_event_study(data_or_estimate: causalis.data_contracts.PanelDataDID | causalis.data_contracts.panel_did_estimate.CallawaySantAnnaDIDEstimate, estimate: Optional[causalis.data_contracts.panel_did_estimate.CallawaySantAnnaDIDEstimate] = None, *, show_simultaneous: bool = True, figsize: Tuple[float, float] = (9.0, 5.2), dpi: int = 220, font_scale: float = 1.05) matplotlib.pyplot.Figure

Plot the fitted CS event-study estimates with confidence intervals.

This function visualizes the dynamic effects of treatment over time relative to the start of treatment (event time). It displays the event-study aggregation of the group-time average treatment effects :math:ATT(g,t).

Parameters

data_or_estimate : PanelDataDID or CallawaySantAnnaDIDEstimate Either the validated panel data or the fitted estimate object. If data is passed, the estimate parameter must also be provided. estimate : CallawaySantAnnaDIDEstimate, optional The fitted model results. Required if data_or_estimate is a PanelDataDID. show_simultaneous : bool, default True Whether to show the simultaneous confidence bands if available in the estimate. figsize : tuple of float, default (9.0, 5.2) The size of the figure in inches (width, height). dpi : int, default 220 The resolution of the figure. font_scale : float, default 1.05 Scale factor for font sizes in the plot.

Returns

matplotlib.figure.Figure The resulting event-study plot.

Examples

from causalis.scenarios.did.dgp import generate_did_gamma_26 from causalis.scenarios.did.model import CallawaySantAnnaDID from causalis.scenarios.did.refutation import plot_did_post_inference_event_study

Fit the model

data = generate_did_gamma_26(n_treated_units=30, n_control_units=60, seed=1) model = CallawaySantAnnaDID().fit(data) results = model.estimate(bootstrap_replications=100)

Generate the plot

fig = plot_did_post_inference_event_study(results)

fig.show()

Notes

The event-study aggregation at event time :math:e is defined as:

.. math::

ATT_{event}(e) = \sum_{g} w(g, e) ATT(g, g+e)

where :math:w(g, e) are weights based on the sample size of each group at that event time. Pointwise confidence intervals are shown by default. If the model was estimated using the multiplier bootstrap, simultaneous confidence bands can also be displayed to account for multiple testing across event times.

causalis.scenarios.did.refutation.post_inference_plots.plot_did_influence_concentration(data_or_estimate: causalis.data_contracts.PanelDataDID | causalis.data_contracts.panel_did_estimate.CallawaySantAnnaDIDEstimate, estimate: Optional[causalis.data_contracts.panel_did_estimate.CallawaySantAnnaDIDEstimate] = None, *, top_n: int = 15, figsize: Tuple[float, float] = (9.5, 5.2), dpi: int = 220, font_scale: float = 1.05) matplotlib.pyplot.Figure

Plot top unit-level influence shares for the simple overall ATT.

This plot helps identify outlier units that disproportionately affect the overall average treatment effect estimate. Large influence shares may indicate lack of overlap or extreme outcomes.

Parameters

data_or_estimate : PanelDataDID or CallawaySantAnnaDIDEstimate Either the validated panel data or the fitted estimate object. estimate : CallawaySantAnnaDIDEstimate, optional The fitted model results. Required if data_or_estimate is a PanelDataDID. top_n : int, default 15 The number of top influential units to display. figsize : tuple of float, default (9.5, 5.2) The size of the figure in inches (width, height). dpi : int, default 220 The resolution of the figure. font_scale : float, default 1.05 Scale factor for font sizes in the plot.

Returns

matplotlib.figure.Figure The resulting influence concentration bar plot.

Examples

from causalis.scenarios.did.dgp import generate_did_gamma_26 from causalis.scenarios.did.model import CallawaySantAnnaDID from causalis.scenarios.did.refutation import plot_did_influence_concentration

Fit the model

data = generate_did_gamma_26(n_treated_units=30, n_control_units=60, seed=1) results = CallawaySantAnnaDID().fit(data).estimate()

Generate the plot

fig = plot_did_influence_concentration(results, top_n=10)

fig.show()

Notes

The influence share for unit :math:i is calculated based on its contribution to the simple aggregated ATT influence function :math:\psi. The absolute influence share is defined as:

.. math::

Share_i = \frac{|\psi_i|}{\sum_{j=1}^n |\psi_j|}

where :math:\psi_i is the value of the influence function for unit :math:i on the overall ATT estimate :math:\hat{\theta}.

causalis.scenarios.did.refutation.post_inference_plots.__all__

[‘plot_did_post_inference_event_study’, ‘plot_did_influence_concentration’]