ggforest() keeps giving "Error in `[.data.frame`(data, , var) : undefined columns selected"

995 Views Asked by At

So I've been trying to visualize my Cox model results in a forest plot, but keep getting the error Error in [.data.frame(data, , var) : undefined columns selected. This seems somehow odd to me. Defining the model and giving the summary it was printed as normal and nothing seemed to be an issue. Also the model contains neither strata() nor tt() objects. After some googling this seems to be an error that occurs from time to time but I couldn't find any satisfying, working solutions to how it can be managed. Given that all other functions work nicely I'm pretty sure that it's actually not a problem with the data itselft.

Alternatively I'm also very happy about any recommendations how to alternatively provide an informative overview on the results, especially as some of my other models contain stratas, which seems to be not supported by ggforest.

Edit: I found the problem: As soon as I specify the IDargument in the coxph function I get the undefined columns selected error.

duration_analysis_10 <- coxph(formula = Surv(start1, stop1, event) ~ Var1 + 
                                Var2 +  
                                log(Var3)+ 
                                Var4 + Var5 + 
                                Var6 +
                                Var7 + Var8 +
                                Var9 + Var10 +
                                var11 + Var12 + 
                                Var13,
                              ties = "efron", na.action = na.exclude,
                              id = CountryName,
                              data = df)

reproducible sample from the eha package:

oldmort <- arrange(oldmort, id)
oldmort$event <- ifelse(oldmort$event == "TRUE",
                        1, 0)

oldmort$sex <- ifelse(oldmort$sex == "female",
                      1, 0)

oldmort$id <- as.character(oldmort$id)


oldmorttest <- coxph(formula = Surv(enter, exit, event) ~ imr.birth + sex,
                              ties = "efron", na.action = na.exclude,
                              id = id,
                              data = oldmort)

summary(oldmorttest)


ggforest(oldmorttest, data = oldmort)
0

There are 0 best solutions below