1

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)
  • 1
    A similar [question](https://stackoverflow.com/q/63821274/8449629) on the use of `ggforest()` for stratified models was asked (and answered) just two days ago. You may find it useful. We may not be able to give more specific advice without seeing a reproducible example of your problem. – Z.Lin Sep 12 '20 at 10:47
  • @Z.Lin thank you for the link to the question and your excellent answer to it! The dataset is pretty gigantic so I'm not sure if I can provide an actually reproducible sample, but I did some more digging and it turned out, that as soon as I specify the ID argument in the coxph function the error occurs. Do you know why this happens? Did I maybe specify it wrongly? I added the code to the question – philipp.kn_98 Sep 12 '20 at 12:49
  • What I *don't* know about Cox models can probably fill a book... Can you demonstrate the problem with an inbuilt dataset from the survival package? – Z.Lin Sep 12 '20 at 13:00
  • @Z.Lin same! just provided an example from the eha package resulting in the same problem. It appears to be the case, that the ID has to be numeric? – philipp.kn_98 Sep 12 '20 at 13:46
  • Yep, within `ggforest()`, there are different provisions for handling numeric vs. character / factor coefficients. It can be circumvented, but in order to get there, can you elaborate what does your desired plot look like? With numeric ID, `ggforest()` includes it as an additional row in the forest plot. Is that what you want? Or do you want to avoid showing ID completely? – Z.Lin Sep 13 '20 at 06:21
  • @Z.Lin if there is a convenient solution to omit the ID row that would be great! Apart from that it appears to work now as I have an additional numeric ID I can utilize in my dataset. – philipp.kn_98 Sep 13 '20 at 09:10

0 Answers0