kogalur / randomForestSRC

DOCUMENTATION:
https://www.randomforestsrc.org/
GNU General Public License v3.0
113 stars 18 forks source link

Error: Survival formula incorrectly specified. #428

Open sfg opened 1 month ago

sfg commented 1 month ago

Hi all,

with version 3.2.3 I got the following error using example from help page:

data(veteran, package = "randomForestSRC")

v.obj <- rfsrc(Surv(time, status) ~ ., data = veteran, ntree = 10, block.size = 1) Error in parseFormula(formula, data, ytry) : Survival formula incorrectly specified.

Any ideas? Thanks, Sven

ishwaran commented 1 month ago

That doesn't create an error for us. Maybe you cut and pasted the code and there is a hidden character that was inserted?

Just try typing it directly and see if that solves the problem.

sfg commented 1 month ago

Thanks for pointing that out! Not sure what really the problem is, but it seems not to be a copy&paste problem. For me, in file "utilities.data.R", function "parseFormula" line 883 seems to return only ., probably a problem with as.character()`:

f <- Surv(time, status) ~ .

and line 883:

all.vars(formula(paste(as.character(f)[2], "~ .")), max.names = 1e7) [1] "."

but

all.vars(formula(paste(f[2], "~ .")), max.names = 1e7) [1] "time" "status" "."

what is correct. So, on my system the function as.character() seems to cause the error. Best, Sven

ishwaran commented 1 month ago

That's what I thought. Thanks for the feedback, we will take a closer look.