lifelines icon indicating copy to clipboard operation
lifelines copied to clipboard

How can I set a a cumulative baseline hazard function when all covariates are equal to "zero"?

Open raphaelchaves opened this issue 2 years ago • 1 comments

The lifelines library computes a cumulative baseline hazard function at the mean of covariates by default. This will often not make sense, particularly for categorical covariates, where usually are created some dummy variables. In R language, the “basehaz” function computes a cumulative baseline hazard function when all covariates are equal to "0" just setting the option available in the package survival as “centered = FALSE”, aiming to cause it to estimate the cumulative hazard at B=0.

How can I accomplish the same results using the lifelines library?

I've used CoxTimeVaryingFitter in order to calculate a Cox Proportional Hazard model considering time-dependent covariates, for instance:

Create an instance of CoxTimeVaryingFitter

ctv = CoxTimeVaryingFitter()

Fit the Cox regression model

ctv.fit(base_df, event_col="default_flag", start_col='start', stop_col='end', id_col="contractid", show_progress=False,step_size=0.1,)

I was expecting a parameter like ctv = CoxTimeVaryingFitter(normalize=true) ?

Thanks in advance.

Rgs, Raphael

raphaelchaves avatar Jul 07 '23 11:07 raphaelchaves

There's no option to do this in lifelines. You may have to write an external function to achieve this.

CamDavidsonPilon avatar Jul 07 '23 13:07 CamDavidsonPilon