I have been trying to find a way to get p-value for 6 months, 12 months and 5 years.


fit <- survfit(Surv(futime, fustat) ~ rx,data=ovarian)

This produces: [1] "p = 0.3"

I would like the p-value however, to only reference a certain time period.

fittime <- summary(fit,times=c(182.5))

This also produces: [1] "p = 0.3"

The number remains the same no matter what time I try to use. I also tried it with different data where the curves are similar in the beginning yet completely different after a certain time, yet receive the same results.

Any suggestions on how I would go about getting a 'p-value' for a certain time period ?


1 Answer 1


Your problem is a common one and requires some insight into how the Kaplan-Meier statistic operates. Your code asks for the p-value of those with survival time less than 182.5 days. However, what you want is the p-value for all persons at-risk up to 182.5 days. This includes persons with survival time longer than 182.5 days. Your survival times and event status need to be recoded:


for (i in 1:length(ovarian$fustat)) {
  if (ovarian$futime[i] >= 182.5) {
    ovarian$trunc6[i] <- 182.5
    ovarian$stat6[i] <- 0
  } else {
    ovarian$trunc6[i] <- ovarian$futime[i]
    ovarian$stat6[i] <- ovarian$fustat[i]

Now, instead of curtailing the sample to only those patients with a survival time of less than 182.5 days, which is not the complete set of patients at risk (some lived longer), everyone at risk remains in the risk set. Then, reclassify those without an event at or beyond 182.5 days as free of the event while keeping those who suffered an event prior to 182.5 days as events with their usual survival time.

The call to surv_pvalue is then:

fit2 <- survfit(Surv(trunc6, stat6) ~ rx,data=ovarian)

and results in a p-value of 0.071.

Note that the surv_pvalue function is contained in the package survminer not survival.

  • 1
    $\begingroup$ Thank you so much and thank you for writing such a long explanation. I spent so long trying to figure this out and had already given up. $\endgroup$
    – camnesia
    Commented Aug 23, 2018 at 15:11
  • 1
    $\begingroup$ For anyone trying to do this in the future. You can also mutate the data-set this way: ovarian <- ovarian %>% mutate(trunc6 = case_when(futime >= 182.5 ~ 182.5, futime < 182.5 ~ futime), stat6 = case_when(futime >= 182.5 ~ 0, futime < 182.5 ~ fustat)) $\endgroup$
    – camnesia
    Commented Aug 29, 2018 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.