1

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!

haosin
  • 11
  • 2
  • Hi and welcome to Stackoverflow. Please provide a reproducible example using the [reprex](https://github.com/tidyverse/reprex) package so that we can help you. – pat-s Jan 24 '20 at 13:06
  • @pat-s Thank you for the guidance! I've edited my post and hopefully it's much better now. – haosin Jan 27 '20 at 07:05
  • I'm not familiar with survival models and hence `strata()` but did you read the section about stratified resampling in the [mlr-tutorial](https://mlr.mlr-org.com/articles/tutorial/resample.html#stratification-blocking-and-grouping)? If you are just getting started you might want to consider using mlr3 and [mlr3proba](https://github.com/mlr-org/mlr3proba) instead. – pat-s Jan 27 '20 at 12:57
  • @pat-s Unfortunately resampling only does stratification of the folds by censoring rates and not on the stratification variable itself. My advisor suggested making a brand new learner with stratification feature following the mlr [documentation to integrate another learner](https://mlr.mlr-org.com/articles/tutorial/create_learner.html). It seems that I need to somehow add `+strata(var)` into the formula of f into the new learner. Would you happen to have any insights or an easier to way go about this? – haosin Feb 04 '20 at 02:07
  • We don't support for formula interfaces easily in mlr. I would have expected that your use case for stratification already exists since no one asked so far about this feature not being available. You might want to double check this. In the end I really recommend to get started with mlr3 and not with mlr. Stratification is also possible there and you will get more responses when requesting this feature. – pat-s Feb 04 '20 at 06:26

0 Answers0