Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Survival analysis in PyMC 3

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?

like image 774
Marigold Avatar asked Feb 25 '14 13:02

Marigold


People also ask

How do you explain a survival analysis?

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.

What is survival analysis in data science?

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.

What for survival analysis is used?

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.

What is a parametric survival analysis?

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.


1 Answers

This is a tricky port, and requires three new concepts:

  1. Use of the theano tensor
  2. Use of the DensityDist
  3. Passing a 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:

enter image description here

like image 65
inversion Avatar answered Oct 14 '22 17:10

inversion