ggsurvfit::ggcuminc - 自定义统计数据与risktable_stats 不起作用

问题描述 投票:0回答:1

我正在尝试使用 ggsurvfit::ggcuminc 绘制竞争风险场景的累积发生率曲线。我想添加一个风险表,定制为在同一行(而不是不同行)中显示 n.risk 和 cum.event,如小插图中所述 https://www.danieldsjoberg.com/ggsurvfit/reference/ add_risktable.html#ref-examples(参见第三个示例)。

set.seed(1)
summary(time <- rnorm(200, 50, 10))
summary(event <- factor(sample(0:2, 200, replace = TRUE, prob = c(.4,.5,.1)), levels = 0:2, labels = c("censor", "event", "comp.event")))
table(female <- sample(0:1, 200, replace = TRUE), useNA = "ifany")
data <- tibble(time, event, female)

tidycmprsk::cuminc(Surv(time, event)~female, data=data) %>% 
  ggcuminc(outcome = "event") + add_risktable(risktable_stats = "{n.risk} ({cum.event})")

但是,我总是收到这个错误

match.arg(rev(risktable_stats), Choices = c("n.risk", "cum.censor", 中的错误: “arg”应该是“n.risk”、“cum.censor”、“cum.event”、“n.censor”、“n.event”之一

任何人都可以帮助理解为什么这不起作用,如小插图所示?

r ggsurvfit
1个回答
0
投票

感谢您提供可重现的示例。你的代码在我的机器上运行良好。将多个统计数据放在一行上是一项新功能,所以也许您只需要安装最新的 ggsurvfit ?在下面的例子中我使用的是 v1.0.0

library(tidyverse)
library(ggsurvfit)
packageVersion("ggsurvfit")
#> [1] '1.0.0'

set.seed(1)
summary(time <- rnorm(200, 50, 10))
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>   27.85   43.86   49.51   50.36   56.13   74.02
summary(event <- factor(sample(0:2, 200, replace = TRUE, prob = c(.4,.5,.1)), levels = 0:2, labels = c("censor", "event", "comp.event")))
#>     censor      event comp.event 
#>         78         97         25
table(female <- sample(0:1, 200, replace = TRUE), useNA = "ifany")
#> 
#>   0   1 
#>  99 101
data <- tibble(time, event, female)

tidycmprsk::cuminc(Surv(time, event)~female, data=data) %>% 
  ggcuminc(outcome = "event") + 
  add_risktable(risktable_stats = "{n.risk} ({cum.event})")
#> Warning: Removed 1 row containing missing values (`geom_step()`).

创建于 2024-02-12,使用 reprex v2.1.0

© www.soinside.com 2019 - 2024. All rights reserved.