1

I am currently doing survival analysis for a project and wanted to calculate the event rate (Number of events / Person-time) at the median follow-up time for a study population.

A snippet of my data would be:

library(survival)
dat1 <- structure(list(days2death = c(627, 577, 2, 73, 518, 711, 1, 3, 
1, 197, 7, 1492, 8, 374, 1), death = c(0, 0, 1, 1, 1, 0, 1, 1, 
1, 1, 1, 0, 1, 1, 1)), row.names = c(NA, -15L), class = c("tbl_df", 
"tbl", "data.frame"))

I am currently using the pyears() function from the survival library but this only gives me the number of events in observed person-years at the end of follow-up. I would like to calculate them at the median follow-up time.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
Fabian.m
  • 55
  • 5

1 Answers1

0

I'm wasn't sure this requires commentary, but I was wrong, so now adding the correction that appears in the comments. It would probably definitely be more correct to work on a copy and mark cases with times over the landmark as censored and set times to 73 and then calculate with my code. This is done so that the person-years at risk are recognized in the calculations.

median(dat1$days2death)
#[1] 73
sum(dat1$death[(dat1$days2death) <= 73])
#[1] 8
# work on a copy.
dat2 structure(list(days2death = c(627, 577, 2, 73, 518, 711, 1, 3, 

1, 197, 7, 1492, 8, 374, 1), death = c(0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1)), row.names = c(NA, -15L), class = c("tbl_df", "tbl", "data.frame")) # Now set all censoring indicators with times greater than the landmark and their times to 73

sum(dat2$days2death[(dat2$days2death) <= 73])
#[1] 584
8/584
#[1] 0.01369863  ; events/ day of observation
365.25* 8/96
#[1] 5.003425     ; events per year of observation.

And as a check I used @jpsmiths invocation of pyears:

> survival::pyears(days2death ~ death, dat2[dat2$days2death <= median(dat2$days2death),])
Call:
survival::pyears(formula = days2death ~ death, data = dat2[dat2$days2death <= 
    median(dat2$days2death), ])

Total number of person-years tabulated: 1.598905 
Total number of person-years off table: 0 
Observations in the data set: 8 

> 8/1.598905
[1] 5.003424
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Or using the OP's library: `survival::pyears(days2death ~ death, dat1[dat1$days2death <= median(dat1$days2death),])` – jpsmith Feb 27 '23 at 22:52
  • @IRTFM Maybe I am overthinking this problem. But doesn't: ```sum(dat1$days2death[(dat1$days2death) <= 73])``` exclude the observed patient-years of patients that had an event after the median follow-up-time but were still under observance before? – Fabian.m Feb 28 '23 at 22:51
  • Agree. Perhaps it is jpsmith and I who are under thinking it. It would probably be more correct to work on a copy and mark cases with times over the landmark as censored and set times to 73 and then calculate with my code. – IRTFM Feb 28 '23 at 23:07