gpt4 book ai didi

pymc - PyMC 3 中的生存分析

转载 作者:行者123 更新时间:2023-12-04 15:11:34 26 4
gpt4 key购买 nike

我尝试移植简单的生存模型 from here (the first one in introduction)从 PyMC 2 到 PyMC 3。但是,我没有找到任何等效于“观察到”的装饰器,并且我尝试编写新的发行版失败了。有人可以提供一个例子,这是如何在 PyMC 3 中完成的?

最佳答案

这是一个棘手的移植,需要三个新概念:

  • theano的使用张量
  • DensityDist的使用
  • 传递一个 dictobserved

  • 此代码提供与您在上面链接的 PyMC2 版本等效的模型:

    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);

    输出如下:

    enter image description here

    关于pymc - PyMC 3 中的生存分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22015055/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com