# Determining number at risk: Three possible variants with different results

I try to figure out what the best way of determining the number at risk is. I came up with three options (see below). However, the numbers at risks vary between the options (#1 and #2 versus #3) and I do not know which one is correct and why they differ at all. I learned about option #3 from this question.

Example code:

library(survival)
data(colon)
d <- colon[, Cs(time, status, rx)]
rm(colon)

# option no. 1
(start <- table(d$rx)) a0 <- start - table(d[which(d$time == 0), ]$rx) a1 <- start - table(d[which(d$time <  365), ]$rx) a2 <- start - table(d[which(d$time <  2*365), ]$rx) a3 <- start - table(d[which(d$time <  3*365), ]$rx) a4 <- start - table(d[which(d$time <  4*365), ]$rx) a5 <- start - table(d[which(d$time <  5*365), ]\$rx)
data.frame(rbind(a0, a1, a2, a3, a4, a5))

# option no. 2
(b <- summary(survfit(formula = Surv(time, status) ~ rx, data = colon), times=c(0, 365, 2*365, 3*365, 4*365, 5*365)))

# option no. 3
risksets <- with(na.omit(colon[, Cs(time, status, rx)]), table(rx, cut(time, seq(0, max(time), by=365) ) ))
(c <- data.frame(sapply(1:3, function(i) Reduce("-",  risksets[i,], init=rowSums(risksets)[i], accumulate=TRUE))))


Result for option #1

Here I determined the number of patients with an event or censoring within one, two, ..., five years and substract the number from the baseline number of patients. This options gives the same results as option #2.

     Obs Lev Lev.5FU
year.0 630 620     608
year.1 519 502     531
year.2 417 406     453
year.3 360 348     420
year.4 318 319     391
year.5 288 299     361


Result for option #2

Here I used summary for survfit.

Call: survfit(formula = Surv(time, status) ~ rx, data = colon)

rx=Obs
time n.risk n.event survival std.err lower 95% CI upper 95% CI
0    630       0    1.000  0.0000        1.000        1.000
365    519     112    0.822  0.0152        0.793        0.853
730    417      96    0.669  0.0188        0.633        0.707
1095    360      54    0.582  0.0197        0.544        0.622
1460    318      39    0.519  0.0200        0.481        0.559
1825    288      19    0.487  0.0200        0.450        0.528

rx=Lev
time n.risk n.event survival std.err lower 95% CI upper 95% CI
0    620       0    1.000  0.0000        1.000        1.000
365    502     115    0.814  0.0157        0.784        0.845
730    406      95    0.659  0.0191        0.623        0.698
1095    348      56    0.568  0.0200        0.530        0.609
1460    319      28    0.522  0.0201        0.484        0.563
1825    299      15    0.498  0.0202        0.460        0.539

rx=Lev+5FU
time n.risk n.event survival std.err lower 95% CI upper 95% CI
0    608       0    1.000  0.0000        1.000        1.000
365    531      73    0.880  0.0132        0.854        0.906
730    453      77    0.752  0.0176        0.718        0.787
1095    420      31    0.700  0.0187        0.665        0.738
1460    391      25    0.658  0.0193        0.622        0.697
1825    361      20    0.624  0.0198        0.587        0.664


Result for option #3

I do not understand the code which I copied from the above mentioned question. However, it gives a different number at risk as option #1 and #2. Why? Is the result wrong? Or does it considered a condition/assumption which was not considered by option #1/2?

    X1  X2  X3
1  630 616 604
2  518 498 526
3  416 401 449
4  360 344 416
5  318 315 387
6  288 295 357
7  185 195 243
8   75  81  98
9   13   9  20
10   0   0   0

• I updated my question and hope it is now more convenient to read. – Gurkenhals Aug 18 '15 at 3:46
• It's an improvement, thank you. I believe a little more information would help even more, but at the least there's some explanation there. – Glen_b Aug 18 '15 at 4:13