0
$\begingroup$

When trying to perform a log-rank test using the Survival package in R I run into the following error:

Error in survdiff(Surv(tstart, tstop, event == 1) ~ group, data = df) : 
  Right censored data only

As an example with this dummy data set:

id <- c(rep("1", 10), rep("2", 10), rep("3", 10), rep("4", 10), rep("5", 10))
age <- c((15:24), (35:44), (45:54), (55:64), (40:49))
event <- c(rep("0", 10), 
           0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
           0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
           0, 0, 0, 2, 2, 2, 2, 2, 2, 2)
group <- c(rep("a", 14), rep("b", 4), rep("a", 6), rep("b", 3), "a", "b", "b", rep("a", 4), rep("c", 6), rep("d", 4), rep("a", 6))

df <- data.table(id, age, event, group)
df$tstart <- integer(0)
df$tstop <- df$age
df[, tstart := shift(tstop), by = id]
df$tstart <- ifelse(is.na(df$tstart), 14, df$tstart)

The following code works fine:

survdiff(Surv(tstop, event == 1) ~ group, data = df)

however this returns an error code:

survdiff(Surv(tstart, tstop, event == 1) ~ group, data = df)

I've been using the start/stop format for the kaplan meier curve and cox regression, and it's working fine; however the log-rank test code does not run as expected. Does anyone know how to deal with this error?

Thanks.

$\endgroup$

put on hold as off-topic by jbowman, Michael Chernick, Peter Flom 12 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ The error is telling you that only right censored data is allowed in this scenario, so no start and stop method for this log-rank test. Also using event==1 inside the formula is weird. $\endgroup$ – user2974951 Jan 8 at 14:00

Browse other questions tagged or ask your own question.