I tried to port simple survival model from here (the first one in introduction) form PyMC 2 to PyMC 3. However, I didn't find any equivalent to "observed" decorator and my attempt to write a new distribution failed. Could someone provide an example how is this done in PyMC 3?
Survival analysis is a collection of statistical procedures for data analysis where the outcome variable of interest is time until an event occurs. Because of censoring–the nonobservation of the event of interest after a period of follow-up–a proportion of the survival times of interest will often be unknown.
Survival analysis is a part of statistics where the expected duration of time for the occurrence of any event is analyzed. It is used for various purposes such as duration analysis in economics, event history analysis in sociology, etc.
Survival analysis uses conditional probability; that is, the probability of surviving up to time t, given that a subject was alive at the beginning of a specified time interval.
A parametric survival model is a well-recognized statistical technique for exploring the relationship between the survival of a patient, a parametric distribution and several explanatory variables. It allows us to estimate the parameters of the distribution.
This is a tricky port, and requires three new concepts:
theano
tensorDensityDist
dict
as observed
This code provides the equivalent model as the PyMC2 version you linked to above:
import pymc3 as pm
from pymc.examples import melanoma_data as data
import theano.tensor as t
times = data.t # not to be confused with the theano tensor t!
failure = (data.censored==0).astype(int)
with pm.Model() as model:
beta0 = pm.Normal('beta0', mu=0.0, tau=0.0001)
beta1 = pm.Normal('beta1', mu=0.0, tau=0.0001)
lam = t.exp(beta0 + beta1*data.treat)
def survival_like(failure, value):
return t.sum(failure * t.log(lam) - lam * value)
survive = pm.DensityDist('survive', survival_like,
observed={'failure': failure, 'value': times})
with model:
start = pm.find_MAP()
step = pm.NUTS(scaling=start)
trace = pm.sample(10000, step=step, start=start)
pm.traceplot(trace);
Output as follows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With