Skip to content

Commit 6743050

Browse files
committed
update test
1 parent b6482d9 commit 6743050

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/testthat/test_FilterUnivariateCox.R

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@ skip_if_not_installed("mlr3proba")
22

33
test_that("FilterUnivariateCox", {
44
t = tsk("rats")
5+
t2 = t$clone()$select(c("rx", "litter"))
56
f = flt("univariatecox")
6-
f$calculate(t)
7+
f$calculate(t2)
78

8-
expect_filter(f, task = t)
9+
# simple testing of filter scores
10+
expect_filter(f, task = t2)
911
expect_true(all(f$scores >= 0))
1012

11-
# works with 2-level factors (but not 3-level ones)
12-
feature = "sex"
13-
expect_class(t$data(cols = feature)[[1]], "factor")
13+
# doesn't work with factors (feature: sex)
14+
expect_error(f$calculate(t), "unsupported feature types: factor")
1415

16+
# encode sex as numeric so filter can be used
17+
dt = t$data()
18+
dt[, sex := ifelse(dt[["sex"]] == 'm', 1, 0)]
19+
t3 = mlr3proba::as_task_surv(dt, target = "time", event = "status")
20+
f$calculate(t3)
21+
score = f$scores[["sex"]]
22+
23+
# get manually score on sex factor
1524
l = lrn("surv.coxph")
16-
t2 = t$clone()
17-
t2$col_roles$feature = feature
18-
l$train(t2)
25+
t$col_roles$feature = "sex"
26+
l$train(t)
27+
manual_score = -log(summary(l$model)$coefficients[,"Pr(>|z|)"])
1928

20-
expect_equal(-log(summary(l$model)$coefficients[,"Pr(>|z|)"]), f$scores[[feature]])
29+
# for 2-level factors, same result is returned if 0-1 encoded
30+
expect_equal(manual_score, score)
2131
})

0 commit comments

Comments
 (0)