首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定义生存分布::survreg()

定义生存分布::survreg()
EN

Stack Overflow用户
提问于 2013-04-09 07:14:20
回答 1查看 3.5K关注 0票数 4

我尝试使用gamma分布来拟合survreg模型。

遵循?survreg.distributions,我像这样定义了我的自定义发行版:

代码语言:javascript
复制
gamma <- list(name = 'gamma',
          parms = c(2,2),
          init = function(x, weights, ...){
            c(median(x), mad(x))
          },
          density = function(x, parms){
            shape <- parms[1]
            scale <- parms[2]
            cbind(pgamma(x, shape=shape, scale=scale),
                  1-pgamma(x, shape=shape, scale=scale),
                  dgamma(x, shape=shape, scale=scale),
                  (shape-1)/x - 1/scale,
                  (shape-1)*(shape-2)/x^2 - 2*(shape-1)/(x*scale) + 1/scale^2)
          },
          quantile = function(p, parms) {
            qgamma(p, shape=parms[1], scale=parms[2])
          },
          deviance = function(...) stop('deviance residuals not defined')
)

然而,我不能让它运行:

代码语言:javascript
复制
require(survival)
survreg(Surv(log(time), status) ~ ph.ecog + sex, lung, dist=gamma)
#Error in coxph.wtest(t(x) %*% (wt * x), c((wt * eta + weights * deriv$dg) %*%  : 
#  NA/NaN/Inf in foreign function call (arg 3)

这个错误来自一些C代码,但我认为它是在更早的时候产生的……

对于survreg有什么提示/建议/替代方案吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-09 23:37:50

我找到了flexsurv包,它实现了一个广义伽马分布。

对于威布尔分布,survregflexsurvreg的估计值相似(但请注意不同的参数化:

代码语言:javascript
复制
require(survival)
summary(survreg(Surv(log(time), status) ~ ph.ecog + sex, data = lung, dist='weibull'))

Call:
survreg(formula = Surv(log(time), status) ~ ph.ecog + sex, data = lung, 
    dist = "weibull")
              Value Std. Error      z         p
(Intercept)  1.7504     0.0364  48.13  0.00e+00
ph.ecog     -0.0660     0.0158  -4.17  3.10e-05
sex          0.0763     0.0237   3.22  1.27e-03
Log(scale)  -1.9670     0.0639 -30.77 6.36e-208

Scale= 0.14 

Weibull distribution
Loglik(model)= -270.5   Loglik(intercept only)= -284.3
    Chisq= 27.62 on 2 degrees of freedom, p= 1e-06 
Number of Newton-Raphson Iterations: 6 
n=227 (1 observation deleted due to missingness)


require(flexsurv)
flexsurvreg(Surv(log(time), status) ~ ph.ecog + sex, data = lung, dist='weibull')

Call:
flexsurvreg(formula = Surv(log(time), status) ~ ph.ecog + sex,     data = lung, dist = "weibull")

Maximum likelihood estimates: 
            est    L95%    U95%
shape    7.1500  6.3100  8.1000
scale    5.7600  5.3600  6.1800
ph.ecog -0.0660 -0.0970 -0.0349
sex      0.0763  0.0299  0.1230

N = 227,  Events: 164,  Censored: 63
Total time at risk: 1232.1
Log-likelihood = -270.5, df = 4
AIC = 549

使用flexsurvreg,我们可以将广义伽马分布拟合到此数据:

代码语言:javascript
复制
flexsurvreg(Surv(log(time), status) ~ ph.ecog + sex, data = lung, dist='gengamma')

Call:
flexsurvreg(formula = Surv(log(time), status) ~ ph.ecog + sex,     data = lung, dist = "gengamma")

Maximum likelihood estimates: 
            est    L95%    U95%
mu       1.7800  1.7100  1.8600
sigma    0.1180  0.0971  0.1440
Q        1.4600  1.0200  1.9100
ph.ecog -0.0559 -0.0853 -0.0266
sex      0.0621  0.0178  0.1060

N = 227,  Events: 164,  Censored: 63
Total time at risk: 1232.1
Log-likelihood = -267.57, df = 5
AIC = 545.15

loglogistic分布(与survreg相反)不是内置的,但可以很容易地定制(参见flexsurvreg的示例)。

我没有对它进行过多的测试,但flexsurv似乎是survival的一个很好的替代品。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15890688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档