gpt4 book ai didi

r - 错误变量的长度不同ggsurvplot_facet

转载 作者:行者123 更新时间:2023-12-03 07:57:03 30 4
gpt4 key购买 nike

我正在尝试运行ggsurvplot_facet(),但无法通过Error in model.frame.default(formula = surv_object2 ~ id, data = list( :variable lengths differ (found for 'id')。任何帮助将不胜感激。

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

可以找到数据here

我的代码如下:

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()函数尝试了所有上述组合。

我发现了类似的问题 herehere,但是我无法解决我的问题。

再次感谢。

最佳答案

这对我有用:

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)

结果:
enter image description here

关于r - 错误变量的长度不同ggsurvplot_facet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59977238/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com