0

I have the following dataframe:

df <-read.table(header=TRUE, text="id time event
                1 90 1
                2 87 0
                3 50 1
                4 54 0
                5 30 0
                6 15 1
                7 20 1
                8 20 0
                9 12 0
                10 13 1")

I would like to create a new column in this dataframe with the probabilities of survival (simple kaplan-Meier function) for those individuals above an age threshold (i.g. 30) and who do not have the event. In the data above, it would be patients 2 and 4 only.

So far I have the following:

library(survival)


Censoring_time <- function(
  TIME = 30){
  km_fit <- survfit(Surv(end, event) ~ 1, data=df)
  if(time > TIME & event = 0){
    df$New_Event <- km_fit
  }
  else(df$New_Event <- df$event)
}
Economist_Ayahuasca
  • 1,648
  • 24
  • 33
  • 1
    There is no 'age' variable, and why would the answer not be 100%, since you didn't have an event then by definiton you survived. – IRTFM Aug 05 '21 at 04:03
  • 1
    Indeed, the model allows to estimate the survival probabilities for an individual taken at random in the population. That's all. See here for how to get the survival probabilities: https://stackoverflow.com/a/67300529/1100107 – Stéphane Laurent Aug 21 '21 at 18:30

0 Answers0