mclements / rstpm2

An R package for generalised survival models
28 stars 11 forks source link

Errors when specifying delayed entry for function aft() #31

Closed alexploner closed 1 month ago

alexploner commented 1 year ago

Hi Mark,

I really appreciate your implementation of the generalized spline-based AFT models in your package, however, I run into errors when trying to run aft with delayed entry:

Starting with a corner case, setting the starting time to zero in the ?aft-example leads to an unexpected error message:

> library(rstpm2)
> brcancer$start <- 0
> fit <- aft(Surv(start, rectime,censrec==1)~hormon,data=brcancer,df=4)
Error in survival::survreg(formula, data) : 
  start-stop type Surv objects are not supported

Now starting at zero when event times are logged is of course weird, but I would have expected a different error here, not exactly the same as you would get from survival::survreg when specifying delayed entry.

More seriously, specifying a non-zero starting interval actually crashes my R session (big smoking bomb):

> brcancer$start <- 1
> fit <- aft(Surv(start, rectime,censrec==1)~hormon,data=brcancer,df=4)

(Also, specifying argument timveVar0= does not seem to do anything, but I have not explored this properly, so this is a comment rather than properly part of the issue.)

System info:

> packageVersion("rstpm2")
[1] ‘1.6.2’
> R.version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          3.1                         
year           2023                        
month          06                          
day            16                          
svn rev        84548                       
language       R                           
version.string R version 4.3.1 (2023-06-16)
nickname       Beagle Scouts               
mclements commented 1 year ago

Alex: Birzhan and I have been developing the AFT model and may already have fixed this bug. Note that left truncation with AFT models requires an ID, which we may not yet have implemented. These models also require untestable assumptions about the preceding exposures for delayed entry with incomplete history to the time origin. Let's discuss this further when I am back at MEB. Kindly, Mark.

mclements commented 1 month ago

Alex: belatedly, I have fixed a bug in the aft() code. The simple case of delayed entry with constant exposure assumed before the delayed entry should now work. This does not currently allow for a change of exposure in a subject.

Thank you for this bug report and apologies for the late response.

Sincerely, Mark.