Survival Analysis - example of the Cox semiparametric model

Example A.12. Example of the Cox semiparametric model

table "HIV" :
    format censor VARCHAR(1)
    
    censor age drug time concentration
    'N' 46 0 5 0.811748723853615
    'Y' 35 1 6 0.015173534085728
    'N' 30 1 8 0.493327751913236
    'N' 30 1 3 0.113596695845014
    'N' 36 0 22 0.855421638131177
    'Y' 32 1 1 0.394623703241156
    'N' 36 1 7 0.168112524943199
    'N' 31 1 9 0.46875098546796
    'N' 48 0 3 0.603496388904043
    'N' 47 0 12 0.16891728137059
    'Y' 28 1 2 0.421717122452813
    'N' 34 0 12 0.663503196607638
    'N' 44 1 1 0.671268260878897
    'N' 32 1 15 0.0141539777441757
    'N' 36 0 34 0.789775819895951
    'N' 36 0 1 0.694884853634573
    'N' 54 0 4 0.216336991176412
    'Y' 35 0 19 0.982258494934709
    'Y' 44 1 3 0.448634932813075
    'N' 38 0 2 0.07938957567418
    'Y' 40 0 2 0.338289432539189
    'N' 34 1 6 0.939584288754838
    'Y' 25 0 60 0.635092855450135
    'N' 32 0 11 0.283929942561103
    'Y' 42 1 2 0.0677404790251717
    'N' 47 0 5 0.529409289273455
    'Y' 30 0 4 0.326667569409013
    'N' 47 1 1 0.843534479992225
    'N' 41 0 13 0.423403382464959
    'N' 40 1 3 0.588029166575039
    'N' 43 0 2 0.00878618663324238
    'N' 41 0 1 0.261223541728549
    'N' 30 0 30 0.619854924567676
    'N' 37 0 7 0.218662468310517
    'N' 42 1 4 0.417737730931233
    'N' 31 1 8 0.207446195587778
    'N' 39 1 5 0.718716906777947
    'N' 32 0 10 0.470769228103452
    'N' 51 0 2 0.495904354192293
    'N' 36 0 9 0.863272015612685
    'N' 43 0 36 0.108071936253979
    'N' 39 0 3 0.100285354236586
    'N' 33 0 9 0.768938702095105
    'N' 45 1 3 0.237857180891372
    'N' 33 0 35 0.962505711978949
    'N' 28 0 8 0.725831700784151
    'N' 31 0 11 0.844340381481861
    'Y' 20 1 56 0.798282736215493
    'Y' 44 0 2 0.829288112595532
    'N' 39 1 3 0.147640031565768
    'N' 33 0 15 0.539909999723212
    'N' 31 0 1 0.429483007063639
    'N' 33 0 10 0.4032170052724
    'N' 50 1 1 0.336994115505951
    'N' 36 1 7 0.0904832267153981
    'N' 30 1 3 0.775137104352639
    'N' 42 1 3 0.333014982771767
    'N' 32 1 2 0.0125241988918545
    'N' 34 0 32 0.211842697016091
    'N' 38 1 3 0.261986522664288
    'Y' 33 0 10 0.629445709826652
    'N' 39 1 11 0.882696320113364
    'N' 39 1 3 0.679437150146322
    'N' 33 1 7 0.391626692873397
    'N' 34 1 5 0.227227933314141
    'N' 34 0 31 0.21939516571499
    'N' 46 1 5 0.79038852848299
    'N' 22 0 58 0.442276297487918
    'N' 44 1 1 0.029626603751292
    'Y' 37 0 3 0.0950355779623331
    'N' 25 0 43 0.0268087138584028
    'N' 38 0 1 0.245720806392297
    'N' 32 0 6 0.0320113768033048
    'N' 34 0 53 0.942898523083983
    'N' 29 0 14 0.465740142734142
    'N' 36 1 4 0.144922845316046
    'N' 21 0 54 0.0199795630015105
    'N' 26 1 1 0.670955426124088
    'N' 32 1 1 0.576402023146486
    'N' 42 0 8 0.756537488966428
    'N' 40 1 5 0.934294870273761
    'N' 37 1 1 0.483474690898518
    'N' 47 0 1 0.514237974783946
    'N' 32 1 2 0.160409678670361
    'Y' 41 1 7 0.100021386801223
    'Y' 46 1 1 0.29657782947316
    'N' 26 1 10 0.878072494946519
    'Y' 30 0 24 0.985694449581508
    'N' 32 1 7 0.396329916439793
    'Y' 31 1 12 0.826373338267123
    'N' 35 0 4 0.752278121376572
    'N' 36 0 57 0.23209242039464
    'N' 41 1 1 0.468317415068619
    'Y' 36 1 12 0.333539787189462
    'N' 35 1 7 0.751296192333622
    'N' 34 1 1 0.445774532456805
    'N' 28 0 5 0.755290059756637
    'Y' 29 0 60 0.243780283479632
    'Y' 35 1 2 0.997928774634948
    'N' 34 1 1 0.553819561391415    

pd = PhysicalData('HIV')
ld = LogicalData(pd)

#------ algorithm settings (Cox algorithm) ------
fs = SurvivalFunctionSettings()
as = CoxSettings()

oas = as.getOptimizationAlgorithmSettings()
oas.setConvergenceThreshold(0.1)
oas.setIterMax(10)
as.preselection = TRUE

vss = VariableSelectionSettings()
vss.variableSelectionMethod = VariableSelectionMethod.stepwise
vss.modelEntryLevel = 0.15
vss.modelLeaveLevel = 0.2

as.variableSelectionSettings = vss
fs.algorithmSettings = as


#------ survival function settings ------
fs.logicalData = ld
fs.targetAttributeName = 'time'
fs.censorName = 'censor'
fs.censoredCategory = 'Y'     # censor value for censored observation

save('hiv_pd', pd)
save('hiv_ld', ld)
save('cox_settings', fs)


#------ model building (Cox model) ------
bt = MiningBuildTask('hiv_pd', 'cox_settings', 'cox_model')

save('cox_build', bt)
execute('cox_build')
print "Build task for linear survival example was successfully executed"

#------ model testing ------
tt = SurvivalTestTask('hiv_pd', 'cox_model', 'hiv_out')
tt.testDataTargetAttributeName = 'time'
tt.censorName = 'censor'
tt.censoredCategory = 'Y'     # censor value for censored observation
tt.numberOfLiftQuantiles = 10

save('cox_test', tt)
execute('cox_test')

print "Test task for linear survival example was successfully executed"

#------ model application ------
pdout = PhysicalData('hiv_apply')
save('hiv_pd_apply', pdout)

at = MiningApplyTask()
at.modelName = 'cox_model'
at.sourceDataName = 'hiv_pd'
at.targetDataName = 'hiv_pd_apply'
at.replaceExistingData = TRUE

asi = ApplySourceItem()
asi.sourceName = 'time'
asi.destinationName = 'actual_time'
at.directMapping.add(asi)
asi = ApplySourceItem()
asi.sourceName = 'censor'
asi.destinationName = 'censor'
at.directMapping.add(asi)

ao = SurvivalApplyOutput()
ao.firstTimePoint = 0
ao.lastTimePoint = 15
ao.numberOfTimePoints = 12
at.applyOutput = ao

save('cox_apply', at)
execute('cox_apply')

print "Apply task for survival example was successfully executed"

Output

Build task for linear survival example was successfully executed
Test task for linear survival example was successfully executed
Apply task for survival example was successfully executed