2
$\begingroup$

I am working through the pymc3 Bayesian Survival Analysis example at the link below and I'm struggling to understand their use of pm.Potential:

https://docs.pymc.io/en/stable/pymc-examples/examples/survival_analysis/bayes_param_survival_pymc3.html

The heart of the example comes down to the following two snippets of code:

y_obs = pm.Gumbel("y_obs", η[~cens_], s, observed=y_std[~cens])
y_cens = pm.Potential("y_cens", gumbel_sf(y_std[cens], η[cens_], s))

Basically what is being done is they are modeling observed survival as a Gumbel distribution and censoring as a Gumbel survival function. In general that sort of makes sense to me. I do think I understand how observed deaths and observed censoring mathematically relate to these distributions. I just don't understand what pm.Potential is doing. In fact, if I take it out it doesn't appear to affect anything. Is it there to just calculate y_cens? If so, how do I access that value since I don't see it in the trace output. At this moment, I'm thinking the censored values are contributing nothing to this model and the fitted survival data is entirely based on a gumbel distribution fit of observed deaths. However, I also suspect, if I could figure out how to plot y_cens, it would also be able to give me a very similar estimate of survival trends.

Can anyone educate me on the function of pm.Potential in the above example?

$\endgroup$
3
  • $\begingroup$ More suitable to stackoverflow as it is about usage of a software package. $\endgroup$ Commented Mar 20, 2022 at 0:44
  • 1
    $\begingroup$ TBH I'm not sure this would be well-received on SO. It's in a bit of a gray area. $\endgroup$
    – tdy
    Commented Mar 20, 2022 at 1:52
  • 3
    $\begingroup$ The question belongs here. It has to do with likelihoods for censored observations in survival modeling. That the implementation is in Python is only secondary. $\endgroup$
    – EdM
    Commented Mar 20, 2022 at 2:28

1 Answer 1

2
$\begingroup$

Basically what is being done is they are modeling observed survival as a Gumbel distribution and censoring as a Gumbel survival function... I'm thinking the censored values are contributing nothing to this model and the fitted survival data is entirely based on a gumbel distribution fit of observed deaths.

That's not correct. A survival model has to incorporate the contributions of censored observations to the likelihood. Otherwise there is substantial risk of bias.

Location-scale survival modeling in this example is based on the form:

$$\log T = \eta + \sigma W ,$$

where $T$ is survival time, $\eta$ is a location parameter (the linear predictor as a function of covariate values), and $\sigma$ is a scale parameter (represented as s in your code, I think).

$W$ has a probability distribution corresponding to the underlying parametric model. For the Weibull model in your example, $W$ is standard minimum-extreme-value (one type of Gumbel).

The 2 lines of code that you rightly note to be the heart of the example describe the contributions to the likelihood separately for uncensored (first line) and right-censored (second line) survival times. This page summarizes contributions to likelihood for various types of censoring and truncation in survival analysis.

An uncensored observation contributes a factor proportional to the density of the lifetime distribution at its observation time. That's what your first line of code describes.

Provided that censoring isn't informative, a right-censored observation contributes a factor proportional to the survival function of the lifetime distribution at the (censored) observation time. (A right-censored observation provides information that an individual survived at least that long, which is the survival function of the distribution.) That's what your second line of code represents. In this case there is no modeling of censoring times, just an incorporation of likelihood contributions from censored observations into the model.

The Potential object provides a way to incorporate such likelihoods into the model without having to define an entire DensityDist. This page provides further information.

In this way both uncensored and right-censored observation times provide their contributions to the likelihood. As there is no modeling of the censoring times per se, your sampling from the posterior is simply based on the probability distribution of uncensored lifetimes. There is no need to sample censored observation times, which in this case are only used to construct the likelihood.

$\endgroup$
2
  • $\begingroup$ Super helpful. In other words I think what you're saying is that Potential is enforcing a constraint that the model be consistent with (in my case) a Gumbel Survival Function. But if that is the case, shouldn't the line have been: survival_function_constraint = pm.Potential("survival_function_constraint", gumbel_sf(y_std[all_data], η[all_data], s)) In other words doesn't the constraint apply to all points not just the censored points? $\endgroup$
    – Mike
    Commented Mar 20, 2022 at 16:23
  • $\begingroup$ @Mike the code in your question isn't a constraint of that form. Both those lines of code are based on the same Gumbel model parameterized by $\eta$ and s. That enforces the constraint you seek. The likelihood of the data given the parameters takes a different form, however, depending on whether the observation was an event or was a right-censored observation. The two lines of code in your question allow the model to make the correct choice for the likelihood, depending on whether an original observation was uncensored or censored. $\endgroup$
    – EdM
    Commented Mar 20, 2022 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.