0

I have run a Weibull AFT survival analysis in R using survreg, and am now trying to predict time until a given percentage survival. I have created a vector of cumulative failure rates using for the 1:98th quartile, and can call up the time to a given failure rates for any of the quartiles. However, when I try and call up the corresponding survival rates, for quartiles below 0.35 R returns numeric(0). Can anyone please explain why?

Below is some of my code, although not a reproducible example - sorry. I made a small dummy dataset but didn't encounter the same problem.

> pct <- (1:98)/100 
> survprobs<-predict(BtCatmodel1, newdata=data.frame(group="B"), type="quantile", p=pct)
> survprobs[(1-pct)==0.4]
[1] 12.39598   # 40% survival at 12.4 days
>survprobs[(1-pct)==0.3]
numeric(0)    # ???

When I run the corresponding percentiles for the failure rates, both work fine.

> survprobs[pct==0.6]
[1] 12.39598    # 60% deaths at 12.4 days
> survprobs[pct==0.7]
[1] 18.01726    # 70% deaths at 18 days 

This also works:

> (1-pct)[70]
[1] 0.3
> survprobs[(1-pct)==((1-pct)[70])]
[1] 18.01726

What is going on?

Hannah W
  • 1
  • 1
  • What's happening is floating point error: it's possible for `1 - 70 / 100` to be not **exactly** .3 (indeed, try `(1 - 70 / 100) == .3` and you'll see it's `FALSE`). As a solution you could index it directly as you do here – David Robinson May 18 '17 at 22:04
  • Ah, interesting, thank you. I see now that this question is a duplicate, but didn't understand enough about where the error was occuring to know that! – Hannah W May 18 '17 at 22:43

0 Answers0