I'm unable to add strata() anywhere in the formula when training a Cox regression using mlr's surv.coxph
Here's a rough example using lung dataset from survival package. I've arbitrarily chosen sex
variable as my stratification variable:
library(survival)
#> Warning: package 'survival' was built under R version 3.6.1
library(mlr)
#> Warning: package 'mlr' was built under R version 3.6.1
#> Loading required package: ParamHelpers
###########Data Prep###############
#load data from survival package
data(lung)
#Prepare data for mlr
lung$status <- (lung$status == 2 )
#Convert Sex into factor
lung$sex <- factor(lung$sex, levels = 1:2, labels = c("Male","Female"))
#Remove all missing for example and filter only to time, status, ph.ecog, and sex
lung <- na.omit(lung[, c("time", "status", "ph.ecog", "sex")])
####### Without MLR ##############
#Perform stratification by sex
coxph(Surv(time, status) ~ ph.ecog + strata(sex), data=lung)
#> Call:
#> coxph(formula = Surv(time, status) ~ ph.ecog + strata(sex), data = lung)
#>
#> coef exp(coef) se(coef) z p
#> ph.ecog 0.4846 1.6236 0.1135 4.271 1.95e-05
#>
#> Likelihood ratio test=18.15 on 1 df, p=2.04e-05
#> n= 227, number of events= 164
####### WITH MLR #################
#Make Survival Learner
lnr_coxph <- makeLearner("surv.coxph", id = "Cox Regression", fix.factors.prediction = T, ties = "breslow")
#Make Survival Task
surv.task <- makeSurvTask(data = lung, target = c("time", "status"))
model <- train(lnr_coxph, surv.task)
getLearnerModel(model)
#> Call:
#> survival::coxph(formula = f, data = data, ties = "breslow")
#>
#> coef exp(coef) se(coef) z p
#> ph.ecog 0.4867 1.6269 0.1122 4.337 1.44e-05
#> sexFemale -0.5523 0.5756 0.1676 -3.296 0.00098
#>
#> Likelihood ratio test=28.97 on 2 df, p=5.126e-07
#> n= 227, number of events= 164
I can't seem to find a feature in mlr that allows me to add this strata() in the formula. Is there a way to replicate this stratification into mlr? If not, is it possible to use ordinary coxPH result and cast back as an mlr object?
For future, I would also like to utilize mlr's feature selection so it would be great to be able to incorporate cox stratification in mlr. Thank you!