Skip to content

Commit 23c9c4d

Browse files
committed
use cox model via survival directly
* Use log10 to transform p-value
1 parent 9b49246 commit 23c9c4d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

R/FilterUnivariateCox.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#' association with the event of interest, typically in the context of clinical
1010
#' or biomedical research.
1111
#'
12-
#' This filter fits a [CoxPH][mlr3proba::LearnerSurvCoxPH()] learner using each
13-
#' feature independently and extracts the \eqn{p}-value that quantifies the
12+
#' This filter fits a [Cox Proportional Hazards][survival::coxph()] model using
13+
#' each feature independently and extracts the \eqn{p}-value that quantifies the
1414
#' significance of the feature's impact on survival. The filter value is
1515
#' `-log10(p)` where `p` is the \eqn{p}-value. This transformation is necessary
1616
#' to ensure numerical stability for very small \eqn{p}-values. Also higher
@@ -44,9 +44,9 @@
4444
#' # Use filter in a learner pipeline
4545
#' # Note: `filter.cutoff` is selected randomly and should be tuned.
4646
#' # The significance level of `0.05` serves as a conventional threshold.
47-
#' # The filter returns the `-log`-transformed scores so we transform
47+
#' # The filter returns the `-log10`-transformed scores so we transform
4848
#' # the cutoff as well:
49-
#' cutoff = -log(0.05) # ~2.99
49+
#' cutoff = -log10(0.05) # ~1.3
5050
#'
5151
#' graph =
5252
#' po("filter", filter = flt("univariatecox"), filter.cutoff = cutoff) %>>%
@@ -69,7 +69,7 @@ FilterUnivariateCox = R6Class("FilterUnivariateCox",
6969
initialize = function() {
7070
super$initialize(
7171
id = "surv.univariatecox",
72-
packages = c("mlr3proba"),
72+
packages = c("survival"),
7373
param_set = ps(),
7474
feature_types = c("integer", "numeric"),
7575
task_types = "surv",
@@ -83,13 +83,12 @@ FilterUnivariateCox = R6Class("FilterUnivariateCox",
8383
.calculate = function(task, nfeat) {
8484
t = task$clone()
8585
features = t$feature_names
86-
learner = lrn("surv.coxph")
8786

8887
scores = map_dbl(features, function(feature) {
8988
t$col_roles$feature = feature
90-
learner$train(t)
91-
pval = summary(learner$model)$coefficients[, "Pr(>|z|)"]
92-
-log(pval) # smaller p-values => larger scores
89+
model = invoke(survival::coxph, formula = t$formula(), data = t$data())
90+
pval = summary(model)$coefficients[, "Pr(>|z|)"]
91+
-log10(pval) # smaller p-values => larger scores
9392
})
9493

9594
set_names(scores, features)

0 commit comments

Comments
 (0)