@@ -2,20 +2,30 @@ skip_if_not_installed("mlr3proba")
2
2
3
3
test_that(" FilterUnivariateCox" , {
4
4
t = tsk(" rats" )
5
+ t2 = t $ clone()$ select(c(" rx" , " litter" ))
5
6
f = flt(" univariatecox" )
6
- f $ calculate(t )
7
+ f $ calculate(t2 )
7
8
8
- expect_filter(f , task = t )
9
+ # simple testing of filter scores
10
+ expect_filter(f , task = t2 )
9
11
expect_true(all(f $ scores > = 0 ))
10
12
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" )
14
15
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
15
24
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|) " ] )
19
28
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 )
21
31
})
0 commit comments