Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

r - "initial value in 'vmmin' is not finite" error in flexsurvspline call

When I run flexsurvspline, from the flexsurv package, on the attached dataset , I get the following error for any k>1:

flexsurvspline(Surv(time,dead)~1,data=input_df,k=2)

Error in optim(method = "BFGS", par = c(gamma0 = 0, gamma1 = 0, gamma2 = 0, :
initial value in 'vmmin' is not finite

From reading other posts with similar issues, I gather this is likely an issue with the inits parameter, and that I might have to generate my own inits function for this particular dataset. But I haven't found any guidance on how to do this for spline fits or what goes into that parameter. Am I correct that this is what's causing the error, and if so how should an inits function be determined?

input_df.xlsx

Thanks in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you use the debugger you can see what's going on inside the function. By specifying debugonce(flexsurvspline), and then running the function, you can step through and see what's happening on each step. (NB: capital Q gets you out of the debugging browser). When I did that, I found that the because more than 30% of the data is in the first time (2), which is also the left boundary know, the function is setting the knots at:

Browse[2]> knots
          33.33333% 66.66667%           
0.6931472 0.6931472 1.0986123 2.5649494 

Note that the first two knots are at the same value, which essentially breaks the function. You can fix this by specifying the interior knot values directly on the log-time scale.

flexsurvspline(Surv(time,dead)~1,data=input_df, knots=c(1.8,2.3))
# Call:
# flexsurvspline(formula = Surv(time, dead) ~ 1, data = input_df, 
#                  knots = c(1.8, 2.3))
# 
# Estimates: 
#           est      L95%     U95%     se     
# gamma0   -3.475   -3.783   -3.167    0.157
# gamma1    3.021    2.785    3.257    0.120
# gamma2    4.294    3.341    5.248    0.487
# gamma3   -7.908  -10.305   -5.510    1.223
# 
# N = 428,  Events: 428,  Censored: 0
# Total time at risk: 1401
# Log-likelihood = -725.7712, df = 4
# AIC = 1459.542

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...