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_smooth_hr(cox.smooth_hr("age"))plot_smooth_hr()
Plot a smooth hazard ratio curve for a continuous covariate.
Usage
plot_smooth_hr(
result,
*,
scale="log_hr",
title=None,
xlab=None,
ylab=None,
backend="altair",
width=500,
height=300,
)Draws the estimated (log) hazard ratio as a smooth curve across the range of a continuous covariate, with a shaded pointwise confidence band. A horizontal reference line marks HR = 1 (log-HR = 0). The curve is produced by CoxPH.smooth_hr().
Parameters
result: Any-
A SmoothHRResult from CoxPH.smooth_hr().
scale: str = "log_hr"-
"log_hr"(default) plots the log hazard ratio."hr"plots the hazard ratio. title: str | None = None-
Optional title for the chart.
xlab: str | None = None-
Label for the x-axis. Defaults to the covariate name.
ylab: str | None = None-
Label for the y-axis. Defaults to
"Log hazard ratio"or"Hazard ratio". backend: Literal["altair", "plotnine"] = "altair"-
Plotting backend:
"altair"(default) or"plotnine". width: int = 500-
Width in pixels (Altair) or approximate inches (plotnine).
height: int = 300- Height in pixels (Altair) or approximate inches (plotnine).
Returns
alt.Chart or plotnine.ggplot
Examples
Plot on the hazard ratio scale instead:
gw.plot_smooth_hr(cox.smooth_hr("age"), scale="hr")