[R] survdiff for left-truncated data?

Terry Therneau therneau at mayo.edu
Tue Aug 4 17:46:53 CEST 2009

> Does anyone know if there is a function like survdiff which can also handle
> left-truncated and right-censored data? When I use it on left-truncated and
> right-censored data I get an error message saying Right censored data only.

 coxph(Surv(time1, time2, status) ~ factor(group), data=mydata)
 The 'score' test from a Cox model is identical to the logrank test. 

 (Well, almost identical - if there are two deaths on the same day the LR 
calculation uses an n-1 at one point where the Cox uses an n.  Neither is 
right/wrong, just the choice of the authors of the two different papers.  The 
difference is never of any consequence, usually several digits out in the test 
statistic: just enough to force addendums like this one.)
  To recreate the observed -expected columns
  fit0 <- coxph(Surv(time1, time2, status) ~ factor(group), data=mydata,
  		 iter=0, na.action=na.exclude)
  o.minus.e <- tapply(resid(fit0), mydata$group, sum)
  obs       <- tapply(mydata$status, mdata$group, sum)
  cbind(observed=obs, expected= obs- o.minus.e, "o-e"=o.minus.e)
   Terry Therneau

More information about the R-help mailing list