CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.35k stars 557 forks source link

weibull_aft.plot_survival_function: object has no attribute #1562

Open timscorbett opened 1 year ago

timscorbett commented 1 year ago

Is this a known issue? Is there a workaround?

Traceback (most recent call last): File "lifelines_example.py", line 31, in weibull_aft.plot_survival_function(ax=axes[0][0]) AttributeError: 'WeibullAFTFitter' object has no attribute 'plot_survival_function'

CamDavidsonPilon commented 1 year ago

What is the survival function of an AFT model? The AFT model is conditional (i.e requires covariates). Maybe you want predict_survival_function?

timscorbett commented 1 year ago

I see an example here on page 11-12 https://buildmedia.readthedocs.org/media/pdf/lifelines/latest/lifelines.pdf

CamDavidsonPilon commented 1 year ago

That's the WeibullFitter, not WeibullAFTFitter

timscorbett commented 1 year ago

Ah! thank you. How can I get the baseline curve alone? At this time, my only covariate is a continuous one. I will use the partial feature after augmenting the dataset.

On Thu, Sep 28, 2023 at 5:26 PM Cameron Davidson-Pilon < @.***> wrote:

That's the WeibullFitter, not WeibullAFTFitter

— Reply to this email directly, view it on GitHub https://github.com/CamDavidsonPilon/lifelines/issues/1562#issuecomment-1740154970, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQJMZPRCFFESSINWQOOPODX4YIT7ANCNFSM6AAAAAA5LPF4UI . You are receiving this because you authored the thread.Message ID: @.***>

CamDavidsonPilon commented 1 year ago

How can I get the baseline curve alone

There's not really a baseline curve for AFT models (terminology isn't used), but I think you just want to set the covariate to 0 in predict_survival_function.

timscorbett commented 1 year ago

Never mind, I added a relevant constant column T.

CamDavidsonPilon commented 1 year ago

The first three questions can be answered by checking out the docs: https://lifelines.readthedocs.io/en/latest/fitters/regression/WeibullAFTFitter.html?highlight=plot_partial_effects_on_outcome#lifelines.fitters.weibull_aft_fitter.WeibullAFTFitter.plot_partial_effects_on_outcome

I don't quite understand your 4th question, however

timscorbett commented 1 year ago

That helps. Thanks Cam!

I guess I can get the cumulative distribution function (CDF) as 1-survival from the plot collection of partials.

Is there a confidence interval band fill between for the survival plot? If not, how can I get it?

CamDavidsonPilon commented 1 year ago

Is there a confidence interval band fill between for the survival plot? If not, how can I get it?

Unfortunately, not

timscorbett commented 12 months ago

Under what conditions is the cumulative_hazard < hazard? My plots have t = 0 to 6. The Y for hazard rate goes up to 750 at t=6. THe Y for cumulative hazard goes only up to 450 at t=6 The survival plot looks as expected..

On Sat, Sep 30, 2023 at 3:15 PM Cameron Davidson-Pilon < @.***> wrote:

Is there a confidence interval band fill between for the survival plot? If not, how can I get it?

Unfortunately, not

— Reply to this email directly, view it on GitHub https://github.com/CamDavidsonPilon/lifelines/issues/1562#issuecomment-1741870723, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQJMZNT4D363SP4OXZKTPDX5CKWVANCNFSM6AAAAAA5LPF4UI . You are receiving this because you authored the thread.Message ID: @.***>

CamDavidsonPilon commented 12 months ago

cumulative hazard (t) = int_0^t hazard(s) ds

so it's possible for cumulative_hazard < hazard. Think about how a short spike in a function might affect its integral.

timscorbett commented 12 months ago

Thanks Cam. If my input data itself is in log10 and the shape is:

                         coef      exp(coef)

rho_ Intercept 2 9

Is it safe to say, my antilog(rho_) for interpretation is 10^(2) and not 10^(9)?

On Tue, Oct 3, 2023 at 2:19 PM Cameron Davidson-Pilon < @.***> wrote:

cumulative hazard (t) = int_0^t hazard(s) ds

so it's possible for cumulative_hazard < hazard. Think about how a short spike in a function might affect its integral.

— Reply to this email directly, view it on GitHub https://github.com/CamDavidsonPilon/lifelines/issues/1562#issuecomment-1745742074, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQJMZOHNEKIIZ4BQKY3MHDX5R6NDAVCNFSM6AAAAAA5LPF4UKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBVG42DEMBXGQ . You are receiving this because you authored the thread.Message ID: @.***>

CamDavidsonPilon commented 12 months ago

Sure, yea, but you should expect very small variation in your log10 variable as a consequence.

timscorbett commented 11 months ago

Is the plot_partial_effects_onoutcome same as a regular weibull(1.75,2.24) plot conditional on T? Here shape (rho) = 2.24 and scale (lambda) = 1.75; based on the results below My intent is to get upper and lower confidence interval curves for this partial effect based on the interval you provide for rho.

image

(By the way, there is some literature on confidence intervals for Cox PH survival with covariates. Not sure if those are conditional on a covariate. https://www.jstor.org/stable/2530904)

timscorbett commented 10 months ago

For WeibullAFT, why does not predict_survival_function have partial outcomes?

On Thu, Oct 5, 2023 at 3:51 PM Cameron Davidson-Pilon < @.***> wrote:

Sure, yea, but you should expect very small variation in your log10 variable as a consequence.

— Reply to this email directly, view it on GitHub https://github.com/CamDavidsonPilon/lifelines/issues/1562#issuecomment-1749761816, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQJMZOGANFWD5USMNRK67DX542WXAVCNFSM6AAAAAA5LPF4UKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBZG43DCOBRGY . You are receiving this because you authored the thread.Message ID: @.***>