diff_diff.plot_sensitivity#

diff_diff.plot_sensitivity(sensitivity_results, *, show_bounds=True, show_ci=True, breakdown_line=True, figsize=(10, 6), title='Honest DiD Sensitivity Analysis', xlabel='M (restriction parameter)', ylabel='Treatment Effect', bounds_color='#2563eb', bounds_alpha=0.3, ci_color='#2563eb', ci_linewidth=1.5, breakdown_color='#dc2626', original_color='#1f2937', ax=None, show=True, backend='matplotlib')[source]

Plot sensitivity analysis results from Honest DiD.

Shows how treatment effect bounds and confidence intervals change as the restriction parameter M varies.

Parameters:
  • sensitivity_results (SensitivityResults) – Results from HonestDiD.sensitivity_analysis().

  • show_bounds (bool, default=True) – Whether to show the identified set bounds as shaded region.

  • show_ci (bool, default=True) – Whether to show robust confidence interval lines.

  • breakdown_line (bool, default=True) – Whether to show vertical line at breakdown value.

  • figsize (tuple, default=(10, 6)) – Figure size (width, height) in inches.

  • title (str) – Plot title.

  • xlabel (str) – X-axis label.

  • ylabel (str) – Y-axis label.

  • bounds_color (str) – Color for identified set shading.

  • bounds_alpha (float) – Transparency for identified set shading.

  • ci_color (str) – Color for confidence interval lines.

  • ci_linewidth (float) – Line width for CI lines.

  • breakdown_color (str) – Color for breakdown value line.

  • original_color (str) – Color for original estimate line.

  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates new figure.

  • show (bool, default=True) – Whether to call plt.show().

  • backend (str, default="matplotlib") – Plotting backend: "matplotlib" or "plotly".

Returns:

The axes object (matplotlib) or figure (plotly).

Return type:

matplotlib.axes.Axes or plotly.graph_objects.Figure

Examples

>>> from diff_diff import MultiPeriodDiD
>>> from diff_diff.honest_did import HonestDiD
>>> from diff_diff.visualization import plot_sensitivity
>>>
>>> # Fit event study and run sensitivity analysis
>>> results = MultiPeriodDiD().fit(data, ...)
>>> honest = HonestDiD(method='relative_magnitude')
>>> sensitivity = honest.sensitivity_analysis(results)
>>>
>>> # Create sensitivity plot
>>> plot_sensitivity(sensitivity)