SmoothHRResult

Smooth non-linear hazard ratio curve for a continuous covariate.

Usage

Source

SmoothHRResult(
    term,
    reference,
    grid,
    log_hr,
    hr,
    log_hr_lower,
    log_hr_upper,
    hr_lower,
    hr_upper,
    df,
    knots,
    adjustment,
)

Contains the estimated log-hazard ratio (and hazard ratio) as a function of a continuous covariate, computed by refitting the Cox model with a B-spline basis expansion. The curve shows how the covariate’s effect on the hazard varies across its range, relative to a reference value.

Attributes

term: str

Name of the covariate whose smooth effect is estimated.

reference: float

Reference value of the covariate. The log-HR is zero at this point.

grid: Array

Array of covariate values at which the curve is evaluated.

log_hr: Array

Log hazard ratio at each grid point (relative to reference).

hr: Array

Hazard ratio at each grid point (exp(log_hr)).

log_hr_lower: Array

Lower confidence bound on the log-HR.

log_hr_upper: Array

Upper confidence bound on the log-HR.

hr_lower: Array

Lower confidence bound on the HR (exp(log_hr_lower)).

hr_upper: Array

Upper confidence bound on the HR (exp(log_hr_upper)).

df: int

Degrees of freedom of the spline (number of basis functions).

knots: Array

Interior knot positions used for the B-spline basis.

adjustment: dict[str, float]
Dictionary of covariate names and the values they were held at.

Methods

Name Description
to_frame() Return the smooth curve as a DataFrame.

to_frame()

Return the smooth curve as a DataFrame.

Usage

Source

to_frame(
    *,
    scale="log_hr",
    format=None,
)

Parameters

scale: str = "log_hr"

"log_hr" (default) returns log hazard ratios and confidence bounds. "hr" returns hazard ratios (exponentiated).

format: str | None = None
Output format: None (default), "pandas", "polars", or "pyarrow".

Returns

pandas.DataFrame, polars.DataFrame, or pyarrow.Table