# Categorical variables must be converted to factor before the fit.
require(survival)
# Wrong way of doing
set.seed(1)
mod <- survival_ln_mixture(Surv(time, status == 2) ~ factor(sex), lung, intercept = TRUE)
if (FALSE) {
# this piece of code will throw error
predict(mod, data.frame(sex = 1), type = "survival", eval_time = 100)
}
# Correct way
lung$sex <- factor(lung$sex) # converting to factor before
set.seed(1)
mod2 <- survival_ln_mixture(Surv(time, status == 2) ~ sex, lung, intercept = TRUE)
# Note: the categorical predictors must be a character.
predict(mod2, data.frame(sex = "1"), type = "survival", eval_time = 100)
Run the code above in your browser using DataLab