我尝试使用伽玛分布拟合一个 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 的任何提示/建议/替代方案?