1

我想跑ggsurvplot_facet() 但跑不过去Error in model.frame.default(formula = surv_object2 ~ id, data = list( :variable lengths differ (found for 'id')。任何帮助将不胜感激。

我相信错误在survfit()/surv_fit()组件中,而不是在ggsurvplot_facet()组件中。

数据可以在这里找到。

我的代码如下:

library(survival); library(survminer)

read.csv(file = 'test.csv', header = TRUE)

surv_object <- Surv(time = test$Days_survived, event = test$Event1) 
fit <- survfit(surv_object ~ id, data = test)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# I have also tried, without success
fit <- survfit(Surv(join$Days_survived, join$Event1) ~ id, data = join) 
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# and
fit <- survfit(as.formula(paste("Surv(join$Days_survived, join$Event1) ~", id)), data = join)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# and
fit <- survfit(as.formula(paste('Surv(join$Days_survived, join$Event1) ~', id)), data = join)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# and
fit <- survfit(as.formula(Surv(join$Days_survived, join$Event1) ~ id), data=join)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

我还使用该surv_fit()功能尝试了上述所有组合。

我在这里这里发现了类似的问题,但我无法解决我的问题。

再次感谢。

4

1 回答 1

0

这对我有用:

lapply(c("survival", "survminer"), require, character.only=TRUE)
df <- read.csv(file = 'test.csv', header = TRUE)
fit <- survfit(Surv(time = Days_survived, event = Event1) ~ id, data=df)
ggsurvplot_facet(fit, facet.by = "method", pval = TRUE, data = df)

结果: 在此处输入图像描述

于 2020-01-30T02:36:40.443 回答