import greenwood as gw
lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
cox = gw.CoxPH().fit(y, lung[["age", "sex"]])
gw.plot_influence(cox)plot_influence()
Diagnostic scatter plots for identifying influential observations in a Cox model.
Usage
plot_influence(
cox,
*,
highlight=3,
panels=None,
title=None,
backend="altair",
width=240,
height=200,
)Produces a horizontal row of panels plotting key diagnostics against the linear predictor. The most influential observations (by likelihood displacement) are highlighted in red and labeled with their observation number.
Parameters
cox: Any-
A fitted CoxPH model.
highlight: int = 3-
Number of most influential observations to highlight and label (default
3). Set to0to disable highlighting. panels: tuple[str, …] | list[str] | None = None-
Which diagnostic panels to show. Each name is a column from influence_diagnostics(). The default is
("deviance", "leverage", "ld"). title: str | None = None-
Optional supertitle for the combined chart.
backend: Literal["altair", "plotnine"] = "altair"-
Plotting backend:
"altair"(default) or"plotnine". width: int = 240-
Width of each panel in pixels (Altair) or inches (plotnine).
height: int = 200- Height of each panel in pixels (Altair) or inches (plotnine).
Returns
alt.Chart or plotnine.ggplot-
A composite chart (Altair
HConcatChart) or a faceted plotnine plot.
Examples
Show only deviance residuals and leverage, highlighting the top 5:
gw.plot_influence(cox, panels=["deviance", "leverage"], highlight=5)Use the plotnine backend for a static ggplot object:
gw.plot_influence(cox, backend="plotnine")