Skip to content
Prev 35976 / 63424 Next

survival package: Surv handles invalid intervals (start time > stop (PR#14221)

This is a multi-part message in MIME format.
--------------080605010703060205070700
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

In the latest version of the survival package (2.35-8), the Surv 
function handles invalid intervals (where start time is greater than 
stop time) by issuing a warning that NAs have been created and then 
setting the left endpoint of the offending intervals to NA. However, the 
code that sets the endpoint to NA subsets incorrectly, and in some 
circumstances an arbitrary selection of intervals will have an endpoint 
set to NA.

For example, for the interval/event data:

     interval    event
     (NA, 10]    1
     (1,   5]    1
     (6,   4]    1

the appropriate Surv call **should** result in a warning and the left 
endpoint of the third, invalid interval being set to NA, as here:
[1] (NA,10 ] ( 1, 5 ] (NA, 4 ]
Warning message:
In Surv(c(NA, 1, 6), c(10, 5, 4), c(1, 1, 1)) :
   Stop time must be>  start time, NA created
However, the Surv call **actually** results in:
[1] (NA,10 ] (NA, 5 ] ( 6, 4 ]
Warning message:
In Surv(c(NA, 1, 6), c(10, 5, 4), c(1, 1, 1)) :
   Stop time must be>  start time, NA created
Note that the endpoint of the valid, second interval has been set to NA 
in place of the invalid, third interval.

A similar problem exists for type="interval2" type data. The 
**expected** behavior is:
[1] 10-     [ 1, 5] [NA, 4]
Warning message:
In Surv(c(NA, 1, 6), c(10, 5, 4), type = "interval2") :
   Invalid interval: start>  stop, NA created
but the **actual** behavior is:
[1] 10-     [NA, 5] [ 6, 4]
Warning message:
In Surv(c(NA, 1, 6), c(10, 5, 4), type = "interval2") :
   Invalid interval: start>  stop, NA created
The attached patch fixes the problem.