This is a crosspost: https://stats.stackexchange.com/questions/403714/bayesian-survival-function
I have managed to estimate the posterior of the latent variables of my model which can be stated as follows (adapted from https://docs.pymc.io/notebooks/bayes_param_survival_pymc3.html):
where y_i\equiv \log T_i, is the log duration and,
Note that this can be equivalently stated that y_i\sim Gumbel(\beta^T x_i, s).
Therefore, the likelihood of the dataset for both censored and uncensored data is:
The question is regarding getting a Bayesian estimate of the survival function. The author of the above notebook, samples from the posterior predictive distribution of y using:
X_.set_value(np.array(x_test)[None,:])
cens_.set_value(np.array([False]))
Y_.set_value(np.zeros(1))
with weibull_model:
post_trace = pm.sample_posterior_predictive(trace, vars=[y_obs])
and uses the samples of y (converted back to time domain) to generate the survival function with the following logic (for time steps 1 to 200):
for t in range(1, 201):
frac = sum(t_samples > t) / len(t_samples)
survival_func[t] = frac
It makes logical sense to state that the fraction of samples greater than a particular time is the survival rate. However, this is a point estimate of the survival function.
There’s two ways I can think of getting a ‘Bayesian’ estimate of the Survival Function:
- Sample N number of traces (with say 1000 points) of the posterior predictive distribution and do:
for n in range(N):
for t in range(1, 201):
frac = sum(t_samples[n] > t) / len(t_samples[n])
survival_func[N, t] = frac
- We know the CDF of the gumbel distribution given the latent variables to be, \exp\left(-\exp\left(\left(\log T_i - X_i^T\beta\right)/s\right)\right). Hence we can let the j-th sample for the survival function for a given value of T to be 1 - \exp\left(-\exp\left(\left(\log T_i - X_i^T\beta^{(j)}\right)/s^{(j)}\right)\right) where \beta^{(j)}, s^{(j)} are the samples from the posterior of the latent variables.
Are the two methods equivalent? If not which method is the more correct way of getting a Bayesian sample of the Survival Function.
Edit
I feel like I should point out after @Gon_F’s answer that in method 2. What I am calculating is the expectation of \exp\left(-\exp\left(\left(\log T - X^T\beta\right)/s\right)\right) under the distribution p(\beta, s| \mathcal{D}_{train}) where \mathcal{D} is the training dataset. Whereas, the first method is looking directly at the distribution, p(T| \mathcal{D}_{train}) where, \beta, s has already been marginalised out. So I’m wondering if (1) is an approximation to (2) after all. Hopefully I’m not complicating things more.