我嘗試使用gamma分佈擬合倖存模型。定義生存分佈:: survreg()
繼?survreg.distributions
我定義我喜歡這個自定義分佈:
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')
)
但是我不能讓它運行:
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?
我看到兩種可能性。您可能會在停止呼叫時拋出錯誤,或者如果您將負數傳遞給log(),您會希望NaN的人知道,除非您提供數據? – 2013-04-09 03:44:09
@DWin:謝謝,我會嘗試調試C代碼並檢查輸入。我的例子是可重複的,肺數據與生存包一起提供。日誌(時間)很好,都是正面的。 – EDi 2013-04-09 08:52:48
在Markmail中進行一些搜索我發現,survreg旨在用於具有位置參數的分佈,並且該gamma不在該族中。 http://markmail.org/search/?q=list%3Aorg.r-project.r-help++survreg+gamma+therneau#query:list%3Aorg.r-project.r-help%20%20survreg% 20gamma%20therneau +頁面:3 +中:t2pcdpq6p2pimpvl +狀態:結果 – 2013-04-09 12:51:32