2

I am using survreg function and weibull distribution to predict the survival time for the last row of my data, But I got the error message.

My data is:

Train <- data.frame(Sum=c(2,2,2,2,2),
                    Days=c(21,21,21,21,21),
                    Status=c(1,1,1,1,1))
Test <- data.frame(Sum=2,
                   Days=21,
                   Status=1)

My code is:

FitWeibull <- survreg(Surv(Days,Status)~Sum,data=Train,dist='weibull')
PredictWeibull <- predict(FitWeibull,newdata=Test)

The error message is:

Error in coxph.wtest(t(x) %*% (wt * x), c((wt * eta + weights * deriv$dg) %*%  : 
  NA/NaN/Inf in foreign function call (arg 3)

This data is just a small part of my whole data. All the other data runs well except for this one. It looks like this is because all the Days and Sum are the same. I change the Train to:

Train <- data.frame(Sum=c(2,2,2,2,2),
                    Days=c(21,21,21,21,20),
                    Status=c(1,1,1,1,1))

Then it is fine. So, weibull might cannot deal with all the same values. But I do not understand why this error happens and how to fix it?

Feng Chen
  • 2,139
  • 4
  • 33
  • 62

0 Answers0