midlearn.plot_effect
- midlearn.plot_effect(estimator: MIDRegressor | MIDExplainer, term: str, style: Literal['effect', 'data'] = 'effect', theme: str | pt.color_theme | None = None, intercept: bool = False, main_effects: bool = False, data: pd.DataFrame | None = None, jitter: float = 0.3, resolution: int | tuple[int, int] = 100, **kwargs)[source]
Visualize the estimated main or interaction effect of a fitted MID model with plotnine. This is a porting function for the R function midr::ggmid.mid().
- Parameters:
estimator (MIDRegressor or MIDExplainer) – A fitted MIDRegressor or MIDExplainer object containing the model components.
term (str) – The name of the component function (main effect or interaction term) to plot.
style ({'effect', 'data'}, default 'effect') – The plotting style. ‘effect’ plots the estimated component function as a line or a surface. ‘data’ plots the specified data points (jittered for factor variables) with MID values represented by color.
theme (str or pt.color_theme or None, default None) – The color theme to use for the plot.
intercept (bool, default False) – If True, the global intercept term is added to the component function values.
main_effects (bool, default False) – If True, main effects are included when plotting two-way interaction terms. Ignored for single-term plots.
data (pandas.DataFrame or None, default None) – The data frame to plot. Required only if style=’data’.
jitter (float, default 0.3) – The amount of jitter to apply to factor variables when style=’data’ is used.
resolution (int or tuple[int, int], default 100) – The resolution (number of grid points) for calculating the effect. If a single integer, it is used for both axes of a 2D interaction plot. If a tuple (int, int), it specifies the resolution for the first and second predictor in an interaction, respectively.
**kwargs (dict) – Additional keyword arguments passed to the main layer of the plot.
- Returns:
A plotnine object representing the visualization of the component function.
- Return type:
plotnine.ggplot.ggplot