I am trying to run ggsurvplot_facet()
but cannot get past Error in model.frame.default(formula = surv_object2 ~ id, data = list( :variable lengths differ (found for 'id')
. Any help would be greatly appreciated.
I believe the error is in the survfit()
/surv_fit()
component and not in the ggsurvplot_facet()
component.
The data can be found here.
My code is as follows:
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)
I have also tried all the above combinations using the surv_fit()
function.
I have found similar questions here and here, but I have not been able to solve my problem.
Thanks again.