causalis.scenarios.unconfoundedness.refutation.score.residual_plots¶
Residual diagnostic plots for nuisance models g0/g1 and m.
Module Contents¶
Functions¶
Plot residual diagnostics for nuisance models. |
Data¶
API¶
- causalis.scenarios.unconfoundedness.refutation.score.residual_plots.plot_residual_diagnostics(estimate: causalis.data_contracts.causal_estimate.CausalEstimate, data: Optional[causalis.dgp.causaldata.CausalData] = None, *, clip_propensity: float = 1e-06, n_bins: int = 20, marker_size: float = 12.0, alpha: float = 0.35, max_scatter_points: Optional[int] = None, random_state: Optional[int] = None, figsize: Tuple[float, float] = (14.0, 4.8), dpi: int = 220, font_scale: float = 1.1, save: Optional[str] = None, save_dpi: Optional[int] = None, transparent: bool = False) matplotlib.pyplot.Figure¶
Plot residual diagnostics for nuisance models.
Panels
Treated-only:
u1 = y - g1vsg1.Control-only:
u0 = y - g0vsg0.Binned calibration error:
E[d - m | m in bin]vs binnedm.
Notes
These plots check the nuisance pieces directly:
outcome residuals :math:
u_1 = Y - \hat g_1(X)and :math:u_0 = Y - \hat g_0(X)should look roughly centered around zero without strong patterns against fitted values,treatment residuals :math:
D - \hat m(X)should average near zero within propensity bins.
Clear trends usually mean the nuisance models still leave structure in the data, which can show up later as unstable score diagnostics.
Parameters
estimate : CausalEstimate Estimate with diagnostic data (
m_hat,g0_hat; optionallyg1_hat,y,d). data : CausalData, optional Optional fallback source foryanddwhen missing in diagnostic data. clip_propensity : float, default 1e-6 Clipping epsilon for propensity values in the treatment-residual panel. n_bins : int, default 20 Number of quantile bins for the binned-mean trend overlays. marker_size : float, default 12.0 Scatter marker size. alpha : float, default 0.35 Scatter opacity. max_scatter_points : int, optional Maximum number of points drawn in each residual scatter panel. When set, scatter points are sampled uniformly without replacement, while the binned-mean overlays and calibration panel still use all observations. random_state : int, optional Random seed used whenmax_scatter_pointstriggers scatter sampling. figsize : tuple, default (14.0, 4.8) Figure size. dpi : int, default 220 Dots per inch. font_scale : float, default 1.10 Font scaling factor. save : str, optional Path to save the figure. save_dpi : int, optional DPI for saving. transparent : bool, default False Whether to save with transparency.Returns
matplotlib.figure.Figure The generated figure.
Examples
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor from causalis.dgp import obs_linear_26_dataset from causalis.scenarios.unconfoundedness.model import IRM data = obs_linear_26_dataset( … n=1000, … seed=3141, … include_oracle=False, … return_causal_data=True, … ) irm = IRM( … data=data, … ml_g=RandomForestRegressor( … n_estimators=200, … max_depth=6, … min_samples_leaf=5, … random_state=3141, … ), … ml_m=RandomForestClassifier( … n_estimators=200, … max_depth=6, … min_samples_leaf=5, … random_state=3141, … ), … n_folds=3, … random_state=3141, … ) estimate = irm.fit().estimate(score=”ATE”) fig = plot_residual_diagnostics(estimate, data=data) # doctest: +SKIP
- causalis.scenarios.unconfoundedness.refutation.score.residual_plots.__all__¶
[‘plot_residual_diagnostics’]