therneau/survival

How variance be calculated in survdiff

Closed this issue · 3 comments

I am trying to find how survdiff calculates V for logrank test, especially at the last time point where only one group has subjects at risk.

Here is the example codes:
library(survival)
df <- data.frame(
treatment = c(0, 1)
, time = c(1, 2)
, event = c(1, 1)
)

survdiff(Surv(time, event) ~ treatment, data = df, rho = 0)

Here is the output from R:

Call:
survdiff(formula = Surv(time, event) ~ treatment, data = df,
rho = 0)

N Observed Expected (O-E)^2/E (O-E)^2/V
treatment=0 1 1 0.5 0.500 1
treatment=1 1 1 1.5 0.167 1

Chisq= 1 on 1 degrees of freedom, p= 0.3

At time 2, there is only one subject at risk and I just could not find a formula to get the Chisq squared statistic equals 1 in this case. Much appreciate for the help.

I wrote this function over 2 decades ago. I'll have to do the same thing that you could do -- go and read the source code. I try to leave lots of comments in my code (but never enough). I'm on holiday, though, so such things will wait for my return.

The variance is a sum over the event times. At any time point where all the remaining subjects are in a single group, the contribution to the variance at that time point is 0. There is not a 'variance at time 1'.

Thanks thernea for the explanation. I couldn't understand why at the time point where only one group members exist, the contribution to variance is zero, but it still contributes to the expected events?