在flexsurv中使用广义伽马函数估计生存失败

时间:2017-11-03 16:15:03

标签: r survival-analysis

我有患者的生存数据。其中一些被审查。我希望使用R中的flexsruv包将广义gamma 函数拟合到经验数据中。而我想要拟合的所有其他函数(例如指数 weibull 等)工作正常,我得到dist = "gengamma"的以下错误代码:

Error in optim(method = "BFGS", par = c(5.02274354115438, -0.0670900421918298,  : 
  non-finite finite-difference value [2]

以下是我的数据:

db.survival <- data.frame(time =  c(101, 111, 185, 707, 85, 58, 427, 672, 90,
                                1452, 608, 99, 556, 62, 60, 1445, 563, 246,
                                163, 276, 216, 64, 61, 66, 67, 68, 81, 83,
                                99, 100, 100, 100, 100, 100, 100, 100, 100),
                      status = c(1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
                                 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1,
                                 0, 0, 0, 0, 0, 0, 0, 0, 0))

我收到错误代码:

library(flexsurv)
flexsurvreg(Surv(time, status) ~ 1, data = db.survival, dist="gengamma")

但是,当我选择方法"CG""SANN"时,我会得到结果(但它们不同)。

我的问题是:为什么我首先会收到错误?我的代码是错误的吗?

非常感谢您提供任何帮助!

1 个答案:

答案 0 :(得分:1)

我认为您的代码没有问题。该错误来自optim使用的flexsurvreg。默认情况下,optim使用渐变的有限差分近似值,如help("optim")

中所述
  

gr一个函数,用于返回"BFGS""CG""L-BFGS-B"的渐变   NULL方法。如果是"SANN",则是有限差分近似   将会被使用。对于> options(error = recover) > flexsurvreg(Surv(time, status) ~ 1, data = db.survival, dist="gengamma", control = list(trace = 100)) initial value 144.298116 iter 10 value 131.067771 iter 20 value 128.013812 iter 30 value 127.761461 iter 40 value 127.753269 Error in optim(control = list(trace = 100), method = "BFGS", par = c(5.02274354115438, : non-finite finite-difference value [2] Enter a frame number, or 0 to exit 1: flexsurvreg(Surv(time, status) ~ 1, data = db.survival, dist = "gengamma", control = list(trace = 100)) 2: do.call("optim", optim.args) 3: optim(control = list(trace = 100), method = "BFGS", par = c(5.02274354115438, -0.0670900421918298, 0), fn = function (optpars, . Selection: 3 方法,它指定了一个函数   生成一个新的候选点。如果它是NULL,则默认为高斯   使用马尔可夫内核。

您可以通过以下调用

查看代码失败的位置
optim

之后,您会看到flexsurv确实运行了几次迭代,但在某些C代码中失败了。此外,您可以看到lower未向upper提供可以与方法optim一起使用的"L-BFGS-B"LoadProducts个参数。您可以在this vignette中看到其中一个参数限制了支持,以便对您有所帮助。