harrelfe / rms

Regression Modeling Strategies
https://hbiostat.org/R/rms
Other
170 stars 48 forks source link

program logic error: variables vary in length but subset= was not given when event is not a logical #125

Closed frankcoumans closed 1 year ago

frankcoumans commented 1 year ago

I have a tibble "dat" with possible predictors, a survival time, an event indicator (0, 1). However, running the below gives an error:

dd <- datadist(dat) options(datadist="dd") rms <- cph(Surv(survival_time, survival_event) ~ predictor_var, data=dat)

Error in processdata(formula, data) : program logic error: variables vary in length but subset= was not given

The problem is fixed by changing the dtype of the event variable to a logical before the three lines above: dat$surv_event <- as.logical(dat$surv_event).

It seems that the Surv function allows for use of either logical or (0, 1) for event. Maybe it would help to cast the event to a logical in rms? I'm a beginner in R, so maybe I need to improve my skills.

frankcoumans commented 1 year ago

Sorry, predictor_var was a string, not the variable name.