causalis.scenarios.unconfoundedness.refutation.unconfoundedness.love_plot¶
Love plot for covariate balance before and after weighting.
Module Contents¶
Functions¶
Plot covariate balance before and after weighting implied by an estimate. |
Data¶
API¶
- causalis.scenarios.unconfoundedness.refutation.unconfoundedness.love_plot.love_plot(data: causalis.dgp.causaldata.CausalData, estimate: causalis.data_contracts.causal_estimate.CausalEstimate, *, threshold: float = 0.1, figsize: Optional[Tuple[float, float]] = None, dpi: int = 220, font_scale: float = 1.1, save: Optional[str] = None, save_dpi: Optional[int] = None, transparent: bool = False) matplotlib.pyplot.Figure¶
Plot covariate balance before and after weighting implied by an estimate.
Parameters
data : CausalData Dataset used to fit the estimator. estimate : CausalEstimate Effect estimate with diagnostic data needed for balance diagnostics. threshold : float, default 0.10 Reference threshold for absolute standardized mean differences. figsize : tuple, optional Figure size. Defaults to an auto-scaled height based on confounder count. 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.
Notes
The Love plot visualizes the Absolute Standardized Mean Difference (ASMD) for each confounder both before and after weighting. The ASMD for confounder :math:
X_jis defined as:.. math::
\mathrm{ASMD}_j = \frac{|\bar{X}_{j,1} - \bar{X}_{j,0}|}{\sqrt{(s_{j,1}^2 + s_{j,0}^2)/2}}where :math:
\bar{X}_{j,d}and :math:s_{j,d}^2are the weighted mean and variance of :math:X_jin treatment group :math:d. In the unweighted case, all weights are 1.Good balance is typically indicated by ASMD values below a threshold (e.g., 0.10) for all confounders after weighting.
Examples
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor from causalis.dgp import obs_linear_26_dataset from causalis.scenarios.unconfoundedness.model import IRM
1. Generate data
data = obs_linear_26_dataset(n=1000, seed=42, return_causal_data=True)
2. Fit model with diagnostics enabled
irm = IRM( … data=data, … ml_g=RandomForestRegressor(random_state=42), … ml_m=RandomForestClassifier(random_state=42), … store_diagnostics=True … ) estimate = irm.fit().estimate()
3. Generate Love plot
fig = love_plot(data, estimate, threshold=0.1) # doctest: +SKIP
- causalis.scenarios.unconfoundedness.refutation.unconfoundedness.love_plot.__all__¶
[‘love_plot’]