NikNakk / forestmodel

42 stars 13 forks source link

Error occurs when applying stratification on Cox models #4

Closed arazraw closed 8 years ago

arazraw commented 8 years ago

It is very common to apply stratification on Cox models. In the survival package, the "strata" argument is available in the "coxph" function. However, since the update of the package to CRAN, it returns an error when attempting to plot coxph objects which have utilized the strata function.

Example:

library(survival) library(forestmodel) data(lung) fit <- coxph(Surv(time, status)~ age + strata(sex), data=lung) forest_model(fit) Error: could not find function "strata"

Any suggestions how to solve this?

Best regards

NikNakk commented 8 years ago

This related to the use of non-standard evaluation by dplyr and the fact the the term name strata(sex) was interpreted as a call to a function strata on the variable sex. I've added in a as.name to fix this and have tidied the surrounding code a little. I've also changed it so that terms like strata which don't have a result in the final model get filtered out.