0

I am trying to plot a cox proportional hazard ratio model calculated with survival's coxph() using forestmodel's forest_model function.

The covariates are factors, some of their name have a space in them ie. "Surgical Resection". When I enter these into the coxph model I refer to them with backticks so that R know to ignore the space:

  res.coxm <- coxph(Surv(Survival_Overall, Death == 1) ~ Age+`Surgical Resection`
               +`Intracranial BoD`+`Systemic BoD`+`Treatment prior to CNS involvement`+
                 `Systemic treatment after CNS involvlement`+`Brain-directed radiotherapy`, data = df)

The model runs fine. When I try to plot this model, I get an error:

  forest_model(res.coxm, format_options = list(color="black", text_size=4.5))

  Error in grouped_df_impl(data, unname(vars), drop) : Column `Surgical Resection` is unknown

Has anyone faced this issue?

The plot forms fine if: - I change the variable names to their "spaceless" versions, i.e. "surgical_resection" instead of "Surgical Resection" OR - If I change the variables from factors to integers, but keep the names with the spaces

I've tried to recode my original df with a variety of different column naming functions incl names(sd)

Any ideas? Thanks!!

Maya Harary
  • 417
  • 1
  • 4
  • 7

1 Answers1

0

It would seem to be the path of least resistance to rename your columns, so they don't have spaces. If that succeeds, then you could also send a feature request to the maintainer asking him/her to make the package conform to typical programming practice in R regression functions. If it doesn't succeed then you would still send a request with somewhat different content.

I'm also unable to reproduce the error with a simple test case:

test1 <- list(time=c(4,3,1,1,2,2,3), 
               status=c(1,1,1,0,1,1,0), 
               x=c(0,2,1,1,1,0,0), 
               'Sex m f'=c(0,0,0,0,1,1,1)) 

 f <- coxph(Surv(time, status) ~ x + `Sex m f`, test1)
 forestmodel::forest_model(f)

  # no error, plot as expected.
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thanks @42- Your code worked for me also but only because all the variables were numeric. The second I changed 'Sex m f' to a factor using: > test1$`Sex m f` <- factor(test1$`Sex m f`, levels = c(0,1), labels = c("M", "F")) It returned the same error as I had before. I would be amenable to changing the variable names, but I want to use this figure for an official publication so I need it looking proper...I can edit it after the fact in a photo editing software but that seems like a lot. – Maya Harary Jan 04 '18 at 01:22