0

I am trying to create Kaplan-Meier survival curves from data that is both left and right censored. I would like these curves to have associated confidence intervals if possible and to include a Log rank p-value on the figure. However, I am having difficulty getting the p-value and confidence intervals to show - any advice to resolve p-value and confidence interval issues would be appreciated?

I suspect the confidence intervals may not be working because there is very little variation in my data - all subjects within treatments died at the same time.

This is my data

library(survival)
library(ggsurvfit)

dat <- structure(list(Rabbit = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 
23L, 24L, 25L, 27L, 26L, 34L, 35L, 28L, 29L, 32L, 36L, 30L, 31L, 
33L, 37L, 38L, 39L, 40L, 41L, 42L), Treatment = structure(c(3L, 
3L, 4L, 4L, 2L, 2L, 1L, 1L, 5L, 3L, 3L, 4L, 4L, 2L, 2L, 1L, 1L, 
5L, 3L, 3L, 4L, 4L, 2L, 2L, 1L, 1L, 5L, 3L, 3L, 4L, 4L, 2L, 2L, 
1L, 1L, 5L, 4L, 4L, 5L, 4L, 4L, 5L), levels = c("Meat bait", 
"Soil spray", "Carrot bait", "Oat bait", "Control"), class = "factor"), 
    Survival.Time.Rabbit = c(68.5, 75, 51, 51, 99, 120, 240, 
    219, 336, 53, 29, 77, 77, 96, 149, 91.5, 77, 336, 336, 336, 
    77.67, 92.67, 336, 336, 336, 336, 336, 336, 336, 53.5, 73, 
    336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336), Status.Rabbit = c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Timepoint = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L), levels = c("1 Day post exposure", 
    "5 Days post exposure", "10 Days post exposure", "20 Days post exposure", 
    "40 Days post exposure", "60 Days post exposure"), class = "factor"), 
    Survival.Time.Bait1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 0L, NA, NA, 10L, 10L, NA, 
    NA, NA, NA, 0L, NA, NA, 20L, 20L, NA, NA, NA, NA, 0L, NA, 
    NA, 0L, NA, NA, 0L), Survival.Time.Bait2 = c(NA, NA, NA, 
    NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, NA, NA, 5L, 
    10L, 10L, NA, NA, 10L, 10L, 10L, 10L, 10L, 20L, 20L, NA, 
    NA, 20L, 20L, 20L, 20L, 20L, 40L, 40L, 40L, 60L, 60L, 60L
    )), row.names = c(NA, -42L), class = "data.frame")

This is what the figure should look like but with confidence intervals (if possible) and p-value. Code:

ggsurvfit(survfit.treatment.bait, linewidth = 1.5) + 
  labs(x = "Time to treatment expirary (days)",
       y = "Survival probability")

[Figure produced by above code] (https://i.stack.imgur.com/X6v0g.png)

When I try to add confidence intervals nothing happens and I get exactly the same figure as above.

ggsurvfit(survfit.treatment.bait, linewidth = 1.5) + 
  labs(x = "Time to treatment expirary (days)",
       y = "Survival probability") + 
  add_confidence_interval()

When I try to add p-value I get the below error, despite my data being of class integer (this error can be expected if even data are of class factor, see).

ggsurvfit(survfit.treatment.bait, linewidth = 1.5) + 
  labs(x = "Time to treatment expirary (days)",
       y = "Survival probability") + 
  add_confidence_interval() + 
  add_pvalue("annotation", caption = "Log-rank {p.value}", size = 4)

Error in `dplyr::case_when()`:
! Failed to evaluate the left-hand side of formula 1.
Caused by error in `survival::survdiff()`:
! Right censored data only
Run `rlang::last_error()` to see where the error occurred.
Pat Taggart
  • 321
  • 1
  • 9

0 Answers0