Fabian.m
Fabian.m

Reputation: 67

How to calculate the events per person-years at median follow-up?

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.

Upvotes: 1

Views: 676

Answers (1)

IRTFM
IRTFM

Reputation: 263352

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

Upvotes: 0

Related Questions