I'm running into an error when trying to add a p value to a cumulative incidence function plot using tidycmprsk and ggsurvfit, and I can't get around this error:
`add_pvalue()` works with objects created with `survfit2()` or `tidycmprsk::cuminc()`.
`add_pvalue()` has been ignored.
I can't share my data, but the issue is reproducable with this sample:
library(ggsurvfit)
library(tidycmprsk)
library(tidyverse)
df <- tibble(
time = rexp(100),
status = factor(sample(c("censor", "event", "death"), 100, replace = TRUE), levels=c("censor", "event", "death")),
group = sample(c("A", "B"), 100, replace = TRUE)
)
cif <- tidycmprsk::cuminc(Surv(time, status) ~ group, data = df)
cif %>%
ggcuminc(outcome = "event") +
add_pvalue() +
add_risktable()
If I change outcome to equal "death", a p-value is added just fine. So naturally I tried reordering the levels of "status":
tmp_df <- tibble(
time = rexp(100),
status = factor(sample(c("censor", "death", "event"), 100, replace = TRUE), levels=c("censor", "death", "event")),
group = sample(c("A", "B"), 100, replace = TRUE)
)
But trying to get a p-value for "event" still gives the samme issue. Hilariously - reordering so "censor" is the second factor lets me add a p-value for that, so only the "event" status seems to always be problematic no matter how I organize the factor levels?
This was due to a bug in ggsurvfit
. For details, see this GitHub issue. The developers are very active and - partly because you asked this question - it has been fixed. First, update to the latest dev version:
devtools::install_github("pharmaverse/ggsurvfit")
packageVersion("ggsurvfit") # should be >= ‘1.1.0.9002’
You will now be able to generate p-values for "event"
as well as "death"
outcomes:
cif |>
ggcuminc(outcome = "event") +
add_pvalue(location = "annotation", size = 14, color = "blue")
If you cannot update to the latest version, see this answer's edit history for how to patch the function.