I am using the ovarian dataset from the survival package using the following standard code:

ovarian$rx <- factor(ovarian$rx, levels = c("1", "2"), labels = c("A", "B"))
ovarian$resid.ds <- factor(ovarian$resid.ds, levels = c("1", "2"), labels = c("no", "yes"))
ovarian$ecog.ps <- factor(ovarian$ecog.ps, levels = c("1", "2"), labels = c("good", "bad"))

ovarian <- ovarian %>% mutate(age_group = ifelse(age >=50, "old", "young"))
ovarian$age_group <- factor(ovarian$age_group)

surv_object <- Surv(time = ovarian$futime, event = ovarian$fustat)

fit1 <- survfit(surv_object ~ rx, data = ovarian)
ggsurvplot(fit1, data = ovarian, pval = TRUE)

fit2 <- survfit(surv_object ~ resid.ds, data = ovarian)
ggsurvplot(fit2, data = ovarian, pval = TRUE)

fit.coxph <- coxph(surv_object ~ rx + resid.ds + age_group + ecog.ps, data = ovarian)
ggforest(fit.coxph, data = ovarian)

I'm able to plot the survival curves but for some reason I am getting the error below when trying to forest plot the cox hazard model with the 4 parameters

Error in `[.data.frame`(cbind(allTermsDF, coef[inds, ]), , c("var", "level",  : 
  undefined columns selected

Am I missing something? I got the code off the datacamp tutorial so it should be working. Would really appreciate any suggestions for a solution to this.

Thanks!

2

There are 2 best solutions below

0
mard On BEST ANSWER

It's likely due to broom version 0.7.0 which has been reported to cause that error with survminer ggforest, see here. Hopefully survminer will be updated soon to fix.

0
user13973112 On

I had the same problem which resolved when I installed an older version of R (R version 3.6.3) then installed an older version of Broom (0.5.6).