# plot_influence()


Diagnostic scatter plots for identifying influential observations in a Cox model.


Usage

``` python
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](CoxPH.md#greenwood.CoxPH) model.

`highlight: int = ``3`  
Number of most influential observations to highlight and label (default `3`). Set to `0` to disable highlighting.

`panels: tuple[str, …] | list[str] | None = None`  
Which diagnostic panels to show. Each name is a column from [influence_diagnostics()](CoxPH.md#greenwood.CoxPH.influence_diagnostics). The default is `("deviance", "leverage", "ld")`.

`title: str | None = None`  
Optional supertitle for the combined chart.

`backend: Literal[``"altair", `<span class="st">`"plotnine"``]`</span>` = ``"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


``` python
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)
```


<style>
  #altair-viz-9e0aecc3bba844048f8bc8b35d96f843.vega-embed {
    width: 100%;
    display: flex;
  }

  #altair-viz-9e0aecc3bba844048f8bc8b35d96f843.vega-embed details,
  #altair-viz-9e0aecc3bba844048f8bc8b35d96f843.vega-embed details summary {
    position: relative;
  }
</style>


Show only deviance residuals and leverage, highlighting the top 5:


``` python
gw.plot_influence(cox, panels=["deviance", "leverage"], highlight=5)
```


<style>
  #altair-viz-78c4f449d6374f8f8da8199a7fccc6c6.vega-embed {
    width: 100%;
    display: flex;
  }

  #altair-viz-78c4f449d6374f8f8da8199a7fccc6c6.vega-embed details,
  #altair-viz-78c4f449d6374f8f8da8199a7fccc6c6.vega-embed details summary {
    position: relative;
  }
</style>


Use the plotnine backend for a static ggplot object:


``` python
gw.plot_influence(cox, backend="plotnine")
```


<figure class="figure">
<p><img src="plot_influence_files/figure-html/cell-4-output-1.png" class="figure-img" width="672" height="480" /></p>
</figure>
