reconnect moved files to git repo
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,138 @@
|
||||
Group,T,Status
|
||||
ALL,2081,0
|
||||
ALL,1602,0
|
||||
ALL,1496,0
|
||||
ALL,1462,0
|
||||
ALL,1433,0
|
||||
ALL,1377,0
|
||||
ALL,1330,0
|
||||
ALL,996,0
|
||||
ALL,226,0
|
||||
ALL,1199,0
|
||||
ALL,1111,0
|
||||
ALL,530,0
|
||||
ALL,1182,0
|
||||
ALL,1167,0
|
||||
ALL,418,1
|
||||
ALL,383,1
|
||||
ALL,276,1
|
||||
ALL,104,1
|
||||
ALL,609,1
|
||||
ALL,172,1
|
||||
ALL,487,1
|
||||
ALL,662,1
|
||||
ALL,194,1
|
||||
ALL,230,1
|
||||
ALL,526,1
|
||||
ALL,122,1
|
||||
ALL,129,1
|
||||
ALL,74,1
|
||||
ALL,122,1
|
||||
ALL,86,1
|
||||
ALL,466,1
|
||||
ALL,192,1
|
||||
ALL,109,1
|
||||
ALL,55,1
|
||||
ALL,1,1
|
||||
ALL,107,1
|
||||
ALL,110,1
|
||||
ALL,332,1
|
||||
AML-Low Risk,2569,0
|
||||
AML-Low Risk,2506,0
|
||||
AML-Low Risk,2409,0
|
||||
AML-Low Risk,2218,0
|
||||
AML-Low Risk,1857,0
|
||||
AML-Low Risk,1829,0
|
||||
AML-Low Risk,1562,0
|
||||
AML-Low Risk,1470,0
|
||||
AML-Low Risk,1363,0
|
||||
AML-Low Risk,1030,0
|
||||
AML-Low Risk,860,0
|
||||
AML-Low Risk,1258,0
|
||||
AML-Low Risk,2246,0
|
||||
AML-Low Risk,1870,0
|
||||
AML-Low Risk,1799,0
|
||||
AML-Low Risk,1709,0
|
||||
AML-Low Risk,1674,0
|
||||
AML-Low Risk,1568,0
|
||||
AML-Low Risk,1527,0
|
||||
AML-Low Risk,1324,0
|
||||
AML-Low Risk,957,0
|
||||
AML-Low Risk,932,0
|
||||
AML-Low Risk,847,0
|
||||
AML-Low Risk,848,0
|
||||
AML-Low Risk,1850,0
|
||||
AML-Low Risk,1843,0
|
||||
AML-Low Risk,1535,0
|
||||
AML-Low Risk,1447,0
|
||||
AML-Low Risk,1384,0
|
||||
AML-Low Risk,414,1
|
||||
AML-Low Risk,2204,1
|
||||
AML-Low Risk,1063,1
|
||||
AML-Low Risk,481,1
|
||||
AML-Low Risk,105,1
|
||||
AML-Low Risk,641,1
|
||||
AML-Low Risk,390,1
|
||||
AML-Low Risk,288,1
|
||||
AML-Low Risk,421,1
|
||||
AML-Low Risk,79,1
|
||||
AML-Low Risk,748,1
|
||||
AML-Low Risk,486,1
|
||||
AML-Low Risk,48,1
|
||||
AML-Low Risk,272,1
|
||||
AML-Low Risk,1074,1
|
||||
AML-Low Risk,381,1
|
||||
AML-Low Risk,10,1
|
||||
AML-Low Risk,53,1
|
||||
AML-Low Risk,80,1
|
||||
AML-Low Risk,35,1
|
||||
AML-Low Risk,248,1
|
||||
AML-Low Risk,704,1
|
||||
AML-Low Risk,211,1
|
||||
AML-Low Risk,219,1
|
||||
AML-Low Risk,606,1
|
||||
AML-High Risk,2640,0
|
||||
AML-High Risk,2430,0
|
||||
AML-High Risk,2252,0
|
||||
AML-High Risk,2140,0
|
||||
AML-High Risk,2133,0
|
||||
AML-High Risk,1238,0
|
||||
AML-High Risk,1631,0
|
||||
AML-High Risk,2024,0
|
||||
AML-High Risk,1345,0
|
||||
AML-High Risk,1136,0
|
||||
AML-High Risk,845,0
|
||||
AML-High Risk,422,1
|
||||
AML-High Risk,162,1
|
||||
AML-High Risk,84,1
|
||||
AML-High Risk,100,1
|
||||
AML-High Risk,2,1
|
||||
AML-High Risk,47,1
|
||||
AML-High Risk,242,1
|
||||
AML-High Risk,456,1
|
||||
AML-High Risk,268,1
|
||||
AML-High Risk,318,1
|
||||
AML-High Risk,32,1
|
||||
AML-High Risk,467,1
|
||||
AML-High Risk,47,1
|
||||
AML-High Risk,390,1
|
||||
AML-High Risk,183,1
|
||||
AML-High Risk,105,1
|
||||
AML-High Risk,115,1
|
||||
AML-High Risk,164,1
|
||||
AML-High Risk,93,1
|
||||
AML-High Risk,120,1
|
||||
AML-High Risk,80,1
|
||||
AML-High Risk,677,1
|
||||
AML-High Risk,64,1
|
||||
AML-High Risk,168,1
|
||||
AML-High Risk,74,1
|
||||
AML-High Risk,16,1
|
||||
AML-High Risk,157,1
|
||||
AML-High Risk,625,1
|
||||
AML-High Risk,48,1
|
||||
AML-High Risk,273,1
|
||||
AML-High Risk,63,1
|
||||
AML-High Risk,76,1
|
||||
AML-High Risk,113,1
|
||||
AML-High Risk,363,1
|
||||
|
@ -0,0 +1,24 @@
|
||||
t,s,se,linear,loglog,log,asinsqrt,logit
|
||||
1,0.97368,0.025967,8.6141,2.37831,9.7871,4.44648,2.47903
|
||||
55,0.94737,0.036224,5.4486,2.36375,6.1098,3.60151,2.46635
|
||||
74,0.92105,0.043744,3.9103,2.16833,4.3257,2.94398,2.25757
|
||||
86,0.89474,0.049784,2.9073,1.89961,3.1713,2.38164,1.97023
|
||||
104,0.86842,0.054836,2.1595,1.59196,2.3217,1.87884,1.64297
|
||||
107,0.84211,0.059153,1.5571,1.26050,1.6490,1.41733,1.29331
|
||||
109,0.81579,0.062886,1.0462,0.91307,1.0908,0.98624,0.93069
|
||||
110,0.78947,0.066135,0.5969,0.55415,0.6123,0.57846,0.56079
|
||||
122,0.73684,0.071434,–0.1842,–0.18808,–0.1826,–0.18573,–0.18728
|
||||
129,0.71053,0.073570,–0.5365,–0.56842,–0.5222,–0.54859,–0.56101
|
||||
172,0.68421,0.075405,–0.8725,–0.95372,–0.8330,–0.90178,–0.93247
|
||||
192,0.65789,0.076960,–1.1968,–1.34341,–1.1201,–1.24712,–1.30048
|
||||
194,0.63158,0.078252,–1.5133,–1.73709,–1.3870,–1.58613,–1.66406
|
||||
230,0.60412,0.079522,–1.8345,–2.14672,–1.6432,–1.92995,–2.03291
|
||||
276,0.57666,0.080509,–2.1531,–2.55898,–1.8825,–2.26871,–2.39408
|
||||
332,0.54920,0.081223,–2.4722,–2.97389,–2.1070,–2.60380,–2.74691
|
||||
383,0.52174,0.081672,–2.7948,–3.39146,–2.3183,–2.93646,–3.09068
|
||||
418,0.49428,0.081860,–3.1239,–3.81166,–2.5177,–3.26782,–3.42460
|
||||
466,0.46682,0.081788,–3.4624,–4.23445,–2.7062,–3.59898,–3.74781
|
||||
487,0.43936,0.081457,–3.8136,–4.65971,–2.8844,–3.93103,–4.05931
|
||||
526,0.41190,0.080862,–4.1812,–5.08726,–3.0527,–4.26507,–4.35795
|
||||
609,0.38248,0.080260,–4.5791,–5.52446,–3.2091,–4.60719,–4.64271
|
||||
662,0.35306,0.079296,–5.0059,–5.96222,–3.3546,–4.95358,–4.90900
|
||||
|
@ -0,0 +1,60 @@
|
||||
import numpy as np
|
||||
|
||||
"""
|
||||
Generate data sets for testing Cox proportional hazards regression
|
||||
models.
|
||||
|
||||
After updating the test data sets, use R to run the survival.R script
|
||||
to update the R results.
|
||||
"""
|
||||
|
||||
# The current data may not reflect this seed
|
||||
np.random.seed(5234)
|
||||
|
||||
# Loop over pairs containing (sample size, number of variables).
|
||||
for (n, p) in (20, 1), (50, 1), (50, 2), (100, 5), (1000, 10):
|
||||
|
||||
exog = np.random.normal(size=(5*n, p))
|
||||
coef = np.linspace(-0.5, 0.5, p)
|
||||
lpred = np.dot(exog, coef)
|
||||
expected_survival_time = np.exp(-lpred)
|
||||
|
||||
# Survival times are exponential
|
||||
survival_time = -np.log(np.random.uniform(size=5*n))
|
||||
survival_time *= expected_survival_time
|
||||
|
||||
# Set this to get a reasonable amount of censoring
|
||||
expected_censoring_time = np.mean(expected_survival_time)
|
||||
|
||||
# Theses are the observation times.
|
||||
censoring_time = -np.log(np.random.uniform(size=5*n))
|
||||
censoring_time *= expected_censoring_time
|
||||
|
||||
# Entry times
|
||||
entry_time = -np.log(np.random.uniform(size=5*n))
|
||||
entry_time *= 0.5*expected_censoring_time
|
||||
|
||||
# 1=failure (death), 0=no failure (no death)
|
||||
status = 1*(survival_time <= censoring_time)
|
||||
|
||||
# The censoring time of the failure time, whichever comes first
|
||||
time = np.where(status == 1, survival_time, censoring_time)
|
||||
|
||||
# Round time so that we have ties
|
||||
time = np.around(time, decimals=1)
|
||||
|
||||
# Only take cases where the entry time is before the failure or
|
||||
# censoring time. Take exactly n such cases.
|
||||
ii = np.flatnonzero(entry_time < time)
|
||||
ii = ii[np.random.permutation(len(ii))[0:n]]
|
||||
status = status[ii]
|
||||
time = time[ii]
|
||||
exog = exog[ii, :]
|
||||
entry_time = entry_time[ii]
|
||||
|
||||
data = np.concatenate((time[:, None], status[:, None],
|
||||
entry_time[:, None], exog),
|
||||
axis=1)
|
||||
|
||||
fname = "results/survival_data_%d_%d.csv" % (n, p)
|
||||
np.savetxt(fname, data, fmt="%.5f")
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,100 @@
|
||||
2.00000 0.00000 0.04088 1.65888 0.43887 2.16009 1.53852 -0.32477
|
||||
0.80000 0.00000 0.64317 -0.01543 1.27200 0.06238 -1.39983 0.28912
|
||||
0.70000 0.00000 0.62035 0.01568 1.10189 1.08241 0.28838 0.03060
|
||||
0.20000 0.00000 0.00396 1.92122 -0.74627 -0.20202 -0.49432 0.18627
|
||||
1.30000 0.00000 0.48061 0.03445 0.62648 -0.05107 0.21468 -1.33564
|
||||
0.10000 1.00000 0.00311 -0.42507 -0.02765 0.92646 -1.79002 0.46062
|
||||
0.10000 1.00000 0.00360 -1.92760 -0.97652 0.33572 1.09292 0.99413
|
||||
0.20000 1.00000 0.16825 -0.92224 -1.46157 -0.83315 1.27701 0.89145
|
||||
1.90000 0.00000 0.31681 0.47668 -2.21992 -1.23187 0.17330 -0.71609
|
||||
0.20000 1.00000 0.11154 -0.78852 -0.22280 -0.39515 0.49144 0.73336
|
||||
0.20000 0.00000 0.08597 0.63231 0.55002 0.32947 0.04749 -0.85148
|
||||
0.60000 1.00000 0.07035 -0.98309 0.24301 -0.72338 0.81746 -1.26767
|
||||
0.90000 1.00000 0.12016 -0.95699 -0.79824 -0.33108 1.09238 -1.56246
|
||||
0.90000 1.00000 0.02773 0.71522 0.92762 -0.58902 1.14907 0.04783
|
||||
1.10000 0.00000 0.69469 0.23457 0.83722 -0.50415 0.55788 -0.06246
|
||||
1.20000 0.00000 0.75846 -0.48568 0.26540 -0.65537 1.36581 -0.12905
|
||||
0.90000 1.00000 0.18518 -0.64696 1.20687 -1.18730 1.23675 -0.30962
|
||||
0.40000 1.00000 0.05883 -0.81157 0.13249 -1.84991 0.19780 0.79789
|
||||
0.30000 1.00000 0.29091 0.50970 1.45016 0.02051 1.09439 0.66784
|
||||
0.90000 0.00000 0.21925 1.25407 -0.55512 0.06966 -0.22258 -1.92762
|
||||
0.80000 0.00000 0.52030 -1.82573 -0.96723 3.06176 -0.78653 -1.03201
|
||||
0.50000 0.00000 0.31396 -1.50465 0.34928 -0.28756 -0.75276 -1.60910
|
||||
2.80000 0.00000 0.50161 -0.51879 1.85085 1.62061 1.62330 0.31456
|
||||
0.20000 0.00000 0.17478 0.51892 -2.01221 0.24535 0.33276 -0.00219
|
||||
0.70000 1.00000 0.02345 1.01616 -2.08282 0.85616 0.20281 0.85377
|
||||
0.50000 0.00000 0.02822 -1.22080 0.43769 -0.94754 -1.30187 0.90808
|
||||
0.60000 0.00000 0.35722 1.42375 -0.38970 -0.64537 -1.08120 -0.66272
|
||||
0.10000 0.00000 0.01318 -2.32399 -0.32153 -0.64911 2.44607 -0.67781
|
||||
0.70000 1.00000 0.33234 -0.86239 2.74390 -0.26652 -1.38002 -1.72868
|
||||
0.30000 1.00000 0.01818 -0.00276 -0.73023 -0.07908 -0.36846 0.24726
|
||||
2.50000 1.00000 0.12683 -0.20405 1.38441 0.11380 -1.55265 1.61875
|
||||
1.90000 1.00000 1.05276 0.46781 0.14070 -2.79994 0.69604 -0.71800
|
||||
0.30000 0.00000 0.12424 0.34365 -1.30879 0.06613 -1.80332 0.50442
|
||||
2.00000 1.00000 0.16247 -0.31284 -1.08730 -0.08539 0.00160 -1.68699
|
||||
2.10000 1.00000 0.19426 -0.31993 0.21405 -0.52766 -1.15955 -1.66554
|
||||
0.20000 1.00000 0.01721 0.25259 0.37725 1.05776 0.20531 0.00615
|
||||
0.20000 0.00000 0.08898 0.25225 -0.59453 -1.68651 0.01607 -0.13487
|
||||
3.30000 1.00000 0.36441 1.58715 0.10576 0.90020 -0.64476 0.16278
|
||||
1.60000 1.00000 0.25111 0.25002 0.29993 0.17598 -0.01910 0.14305
|
||||
1.00000 1.00000 0.91850 0.51040 -0.37021 -1.11632 0.21391 -0.13709
|
||||
1.50000 1.00000 0.85495 1.01267 0.53073 1.60362 0.91206 -0.06950
|
||||
1.70000 0.00000 0.98528 -0.03470 0.46678 0.51241 1.81681 -0.87271
|
||||
1.50000 0.00000 0.45072 1.22177 -0.33281 -0.21419 0.30984 0.25901
|
||||
0.30000 1.00000 0.01095 0.08628 0.06831 -0.55069 -0.98570 -1.47021
|
||||
0.70000 1.00000 0.20957 0.09985 0.55591 -0.14907 1.44737 -0.19020
|
||||
1.80000 0.00000 0.48048 -0.15396 2.06115 0.73874 -0.63995 0.83598
|
||||
1.20000 1.00000 0.05958 1.34778 1.18792 -0.37932 2.49795 0.34569
|
||||
1.60000 0.00000 0.37681 0.42462 0.39925 0.31818 -1.24178 -2.10098
|
||||
1.60000 0.00000 0.27681 0.43797 0.42857 0.71614 0.47339 -0.69239
|
||||
1.50000 0.00000 0.16083 -0.68583 -1.09449 0.14085 0.15615 -2.17219
|
||||
0.30000 0.00000 0.11799 0.84516 0.60886 -0.02455 -0.88110 -0.78903
|
||||
1.30000 0.00000 0.47439 1.14278 0.22765 0.00355 1.24747 -0.44769
|
||||
1.00000 0.00000 0.34329 1.13115 -0.71649 0.20680 -0.62674 0.11690
|
||||
0.90000 0.00000 0.07241 0.87043 -0.52193 -1.82556 -0.96574 -0.46303
|
||||
1.50000 1.00000 0.40548 0.17182 1.23767 -0.22511 0.92575 -0.99200
|
||||
0.70000 0.00000 0.13319 0.64169 0.50024 -1.40025 -0.22809 0.37239
|
||||
0.40000 1.00000 0.30444 -1.48351 -0.71597 1.13583 -0.31381 0.17228
|
||||
0.40000 0.00000 0.00518 0.78247 0.27451 0.90321 0.88329 0.87831
|
||||
0.10000 1.00000 0.06982 -0.40623 -0.59915 0.16943 0.65481 0.74213
|
||||
0.20000 1.00000 0.02326 0.98320 -0.33050 -1.45162 1.03546 0.05095
|
||||
1.70000 1.00000 0.26671 0.39948 -0.01170 -1.99802 1.09214 0.38202
|
||||
0.50000 1.00000 0.20631 1.85586 1.26267 1.09781 0.26681 0.86920
|
||||
0.30000 1.00000 0.03166 -1.12012 -2.17322 -0.81189 0.47966 0.66974
|
||||
0.40000 0.00000 0.17714 -0.62389 0.11727 0.30922 0.45983 -1.18198
|
||||
0.90000 0.00000 0.39204 -1.45848 0.60149 0.40569 -0.14587 -0.41534
|
||||
0.30000 0.00000 0.03714 0.83848 0.53119 -0.58428 1.31723 -1.24635
|
||||
1.10000 0.00000 0.46379 0.21576 -0.81655 0.31364 -0.27610 -1.03055
|
||||
1.40000 0.00000 0.71581 0.88179 2.50473 -1.20963 0.22792 -0.68145
|
||||
0.50000 1.00000 0.04560 -0.13862 1.38279 -0.96235 1.86021 0.77598
|
||||
0.10000 0.00000 0.05473 0.46752 -1.80012 -0.98436 0.60777 -0.35878
|
||||
0.80000 1.00000 0.42481 -0.40098 2.76071 0.74394 1.09659 0.23616
|
||||
0.30000 0.00000 0.23718 -0.32013 0.39748 -0.88636 -1.68891 0.75689
|
||||
0.50000 0.00000 0.03726 0.59910 -0.14940 -0.01991 -0.28925 0.23417
|
||||
0.30000 0.00000 0.12740 0.15096 0.90280 -0.61087 0.48783 1.80243
|
||||
0.70000 1.00000 0.63824 0.55312 -0.76756 -1.62404 0.50754 1.83655
|
||||
1.60000 0.00000 0.03744 -0.92345 -0.40163 -0.14609 -0.71917 -0.39060
|
||||
3.20000 0.00000 0.52178 0.30277 -0.17976 -0.45561 -0.48284 -1.54195
|
||||
0.90000 0.00000 0.04532 -0.14812 0.03298 -0.11498 0.09681 -2.37051
|
||||
0.80000 0.00000 0.36657 -0.97253 -0.04856 0.14913 0.00607 0.78143
|
||||
0.60000 1.00000 0.03655 -0.99128 0.85325 1.24141 -1.52963 1.18147
|
||||
0.40000 0.00000 0.01616 1.21142 -2.49815 2.32805 0.95173 0.40863
|
||||
0.30000 1.00000 0.00955 -2.06282 -1.01843 -1.49079 0.84123 1.16571
|
||||
0.40000 1.00000 0.01111 -0.02352 -1.14282 -1.73493 -0.08088 0.22988
|
||||
1.00000 1.00000 0.14784 0.66488 -0.55177 0.29813 1.06110 -0.09346
|
||||
0.10000 0.00000 0.01538 -0.01239 -0.38551 0.90332 0.98841 -1.09158
|
||||
1.80000 1.00000 1.44280 1.15346 1.52878 -0.78441 0.74890 1.19751
|
||||
0.40000 0.00000 0.14388 -0.62050 1.33600 -1.25079 1.04416 1.09523
|
||||
0.50000 0.00000 0.25285 0.43475 -0.66619 -1.80572 -1.41659 -0.18333
|
||||
0.70000 1.00000 0.12394 0.07814 -0.49443 0.52055 -0.85472 1.47196
|
||||
1.00000 0.00000 0.00122 1.35184 -0.75871 -0.33501 -0.20529 1.28920
|
||||
0.90000 1.00000 0.41370 0.54683 1.24851 -1.14847 -0.04749 1.60048
|
||||
0.10000 1.00000 0.06023 0.32626 -0.11112 -0.10537 0.58654 0.55261
|
||||
1.30000 0.00000 0.27967 -0.77736 -0.03111 -3.14766 -0.79793 -0.72638
|
||||
0.70000 0.00000 0.36676 -0.77517 0.31001 -1.09973 -1.75452 -0.82917
|
||||
0.30000 1.00000 0.13509 -0.12913 1.30423 -1.15341 0.04622 0.52666
|
||||
1.80000 0.00000 0.11982 -0.64227 -0.51723 0.64616 -1.48093 -0.81054
|
||||
1.10000 1.00000 0.26003 -0.04358 -0.64401 1.67422 -1.79441 -1.28941
|
||||
1.00000 0.00000 0.98041 1.36679 0.03887 0.94946 -1.98330 -1.71907
|
||||
0.50000 1.00000 0.48143 0.25458 0.05441 0.11660 0.00090 -0.40448
|
||||
1.80000 1.00000 0.15619 0.29362 -1.22544 -0.09859 0.02863 -1.39324
|
||||
|
@ -0,0 +1,20 @@
|
||||
0.70000 1.00000 0.17884 -0.80807
|
||||
0.60000 0.00000 0.23284 -0.10099
|
||||
1.40000 1.00000 0.07038 -0.34916
|
||||
0.80000 1.00000 0.04943 1.32464
|
||||
0.40000 1.00000 0.19263 -1.51983
|
||||
0.70000 0.00000 0.11941 0.75329
|
||||
0.40000 1.00000 0.16606 0.13835
|
||||
1.20000 0.00000 0.05183 0.97574
|
||||
1.20000 0.00000 0.27814 1.15109
|
||||
0.30000 0.00000 0.26536 -0.07403
|
||||
0.50000 1.00000 0.15457 -1.10065
|
||||
0.40000 1.00000 0.19745 -0.64876
|
||||
0.30000 1.00000 0.07634 0.76335
|
||||
1.10000 0.00000 0.25912 0.86522
|
||||
0.50000 1.00000 0.00805 -0.27593
|
||||
1.50000 0.00000 0.47960 0.24884
|
||||
0.10000 0.00000 0.00516 0.33618
|
||||
0.20000 0.00000 0.07805 0.39894
|
||||
1.30000 1.00000 0.28314 0.19641
|
||||
0.70000 0.00000 0.29323 0.70037
|
||||
|
@ -0,0 +1,50 @@
|
||||
1.10000 0.00000 0.34994 -0.01447
|
||||
0.50000 0.00000 0.19143 0.10335
|
||||
0.20000 1.00000 0.07772 -0.23178
|
||||
0.40000 1.00000 0.20723 -2.16909
|
||||
1.00000 0.00000 0.15399 -0.10232
|
||||
0.40000 1.00000 0.03610 -0.49694
|
||||
0.40000 1.00000 0.12840 -1.20376
|
||||
0.20000 0.00000 0.14323 0.78727
|
||||
0.30000 0.00000 0.29799 0.31506
|
||||
0.20000 1.00000 0.14530 0.89771
|
||||
1.80000 0.00000 0.20163 2.18046
|
||||
0.20000 1.00000 0.08723 -0.49941
|
||||
0.70000 0.00000 0.62887 0.74497
|
||||
1.70000 0.00000 1.26137 0.31418
|
||||
1.00000 1.00000 0.61647 1.54372
|
||||
0.70000 0.00000 0.16552 1.02511
|
||||
0.80000 1.00000 0.24764 0.03132
|
||||
0.60000 1.00000 0.31866 -0.75876
|
||||
0.10000 0.00000 0.04446 0.16542
|
||||
0.40000 0.00000 0.28586 0.12311
|
||||
0.50000 1.00000 0.36568 -0.70318
|
||||
0.40000 1.00000 0.06591 0.10302
|
||||
2.40000 0.00000 0.62202 0.89696
|
||||
0.30000 1.00000 0.04989 -2.19325
|
||||
0.50000 0.00000 0.14153 0.35311
|
||||
1.20000 0.00000 0.32188 0.37552
|
||||
1.20000 1.00000 0.43017 0.85034
|
||||
0.20000 0.00000 0.08460 0.69427
|
||||
0.40000 0.00000 0.11157 1.02984
|
||||
1.90000 1.00000 0.82567 0.56098
|
||||
0.70000 1.00000 0.03936 -0.32045
|
||||
0.40000 1.00000 0.29959 -0.53575
|
||||
0.50000 0.00000 0.40070 -2.07033
|
||||
2.80000 0.00000 0.47653 -0.13154
|
||||
1.70000 0.00000 0.90095 1.60037
|
||||
0.70000 0.00000 0.12335 0.39483
|
||||
0.80000 0.00000 0.56741 -0.29127
|
||||
0.40000 1.00000 0.35975 -0.62702
|
||||
0.60000 0.00000 0.34351 -0.60780
|
||||
1.00000 0.00000 0.54425 -0.83077
|
||||
2.40000 1.00000 0.15080 0.01460
|
||||
1.50000 0.00000 0.15170 2.29830
|
||||
1.00000 1.00000 0.09671 0.80049
|
||||
0.30000 1.00000 0.23474 0.28060
|
||||
0.90000 0.00000 0.56784 -0.45666
|
||||
1.60000 1.00000 0.73536 0.17942
|
||||
0.20000 0.00000 0.19858 1.43121
|
||||
0.30000 0.00000 0.10249 0.63181
|
||||
0.40000 0.00000 0.15787 -0.86227
|
||||
1.10000 1.00000 0.40295 0.73249
|
||||
|
@ -0,0 +1,50 @@
|
||||
1.00000 1.00000 0.03528 -0.38315 -1.11646
|
||||
0.30000 1.00000 0.01149 -2.16263 0.67790
|
||||
1.50000 1.00000 1.19729 1.33121 -0.43045
|
||||
0.70000 1.00000 0.53896 0.84117 -0.63001
|
||||
0.20000 1.00000 0.16054 -0.95780 -0.82060
|
||||
0.90000 1.00000 0.30738 -1.08477 -0.06120
|
||||
0.40000 0.00000 0.12942 -1.76866 -0.04241
|
||||
0.50000 1.00000 0.13266 -0.26914 -1.53422
|
||||
0.90000 0.00000 0.15526 -0.81154 -0.36088
|
||||
0.60000 0.00000 0.12826 0.33186 0.65154
|
||||
0.70000 0.00000 0.22373 0.92204 0.25643
|
||||
1.20000 1.00000 0.48185 -0.43982 0.31456
|
||||
0.90000 0.00000 0.63365 -1.04665 -2.21337
|
||||
0.60000 0.00000 0.07299 -2.42939 0.18910
|
||||
1.20000 1.00000 0.69923 -0.29619 0.26199
|
||||
0.80000 0.00000 0.10030 0.85841 0.88421
|
||||
0.80000 1.00000 0.63120 -0.36353 0.26827
|
||||
0.70000 1.00000 0.55604 -1.95990 -0.44759
|
||||
1.10000 0.00000 0.40564 0.88427 -1.96625
|
||||
0.20000 1.00000 0.03342 0.64777 -0.36391
|
||||
0.10000 1.00000 0.06233 -0.64523 0.51863
|
||||
1.10000 1.00000 0.04864 2.43561 0.44143
|
||||
1.00000 0.00000 0.14794 1.51211 -1.71867
|
||||
1.30000 1.00000 0.16023 -0.49040 -0.02378
|
||||
0.40000 1.00000 0.24862 0.08828 -0.70830
|
||||
0.50000 0.00000 0.12510 1.64139 -0.07560
|
||||
1.90000 1.00000 0.57775 0.22910 -0.06035
|
||||
0.60000 0.00000 0.21988 -0.61760 -0.84216
|
||||
1.50000 0.00000 0.73572 -0.31742 -0.50461
|
||||
0.20000 0.00000 0.09880 0.01778 -0.61300
|
||||
2.70000 1.00000 0.68267 0.46799 -1.20130
|
||||
0.20000 0.00000 0.00640 -0.57452 0.07641
|
||||
1.00000 0.00000 0.53120 0.10882 -1.29716
|
||||
1.40000 0.00000 0.39915 1.78210 -0.98747
|
||||
0.30000 1.00000 0.24249 -0.52481 -0.00631
|
||||
1.50000 0.00000 0.90297 -0.15558 -0.41401
|
||||
0.60000 0.00000 0.11513 1.91513 0.84025
|
||||
2.90000 0.00000 1.22897 0.83216 0.05158
|
||||
0.20000 1.00000 0.14026 -0.15508 2.57765
|
||||
0.20000 1.00000 0.02342 -0.43017 -0.19378
|
||||
0.10000 1.00000 0.01043 -2.09826 1.82889
|
||||
1.00000 0.00000 0.12414 -0.15255 -0.78868
|
||||
0.10000 0.00000 0.08182 2.05096 -0.00273
|
||||
0.70000 0.00000 0.50106 -1.11553 -0.37599
|
||||
0.70000 0.00000 0.04540 0.20011 -1.63279
|
||||
0.70000 1.00000 0.41003 1.04118 0.07873
|
||||
0.40000 1.00000 0.33584 -1.70869 -0.94676
|
||||
1.20000 0.00000 0.59698 0.21795 -2.65967
|
||||
1.10000 0.00000 0.90747 1.10303 2.21828
|
||||
0.20000 0.00000 0.15655 1.50321 0.88795
|
||||
|
@ -0,0 +1,10 @@
|
||||
import numpy as np
|
||||
|
||||
coef_50_2_0 = np.array([-0.6748149, 0.5219471])
|
||||
|
||||
coef_50_2_1 = np.array([-0.3464841, 0.211115])
|
||||
|
||||
coef_100_5_0 = np.array([
|
||||
-0.4839566, -0.3130558, -0.1239565, 0.3466049, 0.5827503])
|
||||
|
||||
coef_100_5_1 = np.array([-0.1314948, 0, 0, 0.0324285, 0.2364489])
|
||||
@ -0,0 +1,442 @@
|
||||
import numpy as np
|
||||
|
||||
coef_20_1_bre = np.array([-0.9185611])
|
||||
|
||||
se_20_1_bre = np.array([0.4706831])
|
||||
|
||||
time_20_1_bre = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1.1, 1.2, 1.3, 1.4, 1.5])
|
||||
|
||||
hazard_20_1_bre = np.array([
|
||||
0, 0, 0.04139181, 0.1755379, 0.3121216, 0.3121216, 0.4263121,
|
||||
0.6196358, 0.6196358, 0.6196358, 0.909556, 1.31083, 1.31083])
|
||||
|
||||
coef_20_1_et_bre = np.array([-0.8907007])
|
||||
|
||||
se_20_1_et_bre = np.array([0.4683384])
|
||||
|
||||
time_20_1_et_bre = np.array([0])
|
||||
|
||||
hazard_20_1_et_bre = np.array([0])
|
||||
|
||||
coef_20_1_st_bre = np.array([-0.5766809])
|
||||
|
||||
se_20_1_st_bre = np.array([0.4418918])
|
||||
|
||||
time_20_1_st_bre = np.array([0])
|
||||
|
||||
hazard_20_1_st_bre = np.array([0])
|
||||
|
||||
coef_20_1_et_st_bre = np.array([-0.5785683])
|
||||
|
||||
se_20_1_et_st_bre = np.array([0.4388437])
|
||||
|
||||
time_20_1_et_st_bre = np.array([0])
|
||||
|
||||
hazard_20_1_et_st_bre = np.array([0])
|
||||
|
||||
coef_20_1_efr = np.array([-0.9975319])
|
||||
|
||||
se_20_1_efr = np.array([0.4792421])
|
||||
|
||||
time_20_1_efr = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1.1, 1.2, 1.3, 1.4, 1.5])
|
||||
|
||||
hazard_20_1_efr = np.array([
|
||||
0, 0, 0.03934634, 0.1663316, 0.2986427, 0.2986427, 0.4119189,
|
||||
0.6077373, 0.6077373, 0.6077373, 0.8933041, 1.285732, 1.285732])
|
||||
|
||||
coef_20_1_et_efr = np.array([-0.9679541])
|
||||
|
||||
se_20_1_et_efr = np.array([0.4766406])
|
||||
|
||||
time_20_1_et_efr = np.array([0])
|
||||
|
||||
hazard_20_1_et_efr = np.array([0])
|
||||
|
||||
coef_20_1_st_efr = np.array([-0.6345294])
|
||||
|
||||
se_20_1_st_efr = np.array([0.4455952])
|
||||
|
||||
time_20_1_st_efr = np.array([0])
|
||||
|
||||
hazard_20_1_st_efr = np.array([0])
|
||||
|
||||
coef_20_1_et_st_efr = np.array([-0.6355622])
|
||||
|
||||
se_20_1_et_st_efr = np.array([0.4423104])
|
||||
|
||||
time_20_1_et_st_efr = np.array([0])
|
||||
|
||||
hazard_20_1_et_st_efr = np.array([0])
|
||||
|
||||
coef_50_1_bre = np.array([-0.6761247])
|
||||
|
||||
se_50_1_bre = np.array([0.25133])
|
||||
|
||||
time_50_1_bre = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.5, 1.6, 1.7, 1.8, 1.9, 2.4, 2.8])
|
||||
|
||||
hazard_50_1_bre = np.array([
|
||||
0, 0.04895521, 0.08457461, 0.2073863, 0.2382473, 0.2793018,
|
||||
0.3271622, 0.3842953, 0.3842953, 0.5310807, 0.6360276,
|
||||
0.7648251, 0.7648251, 0.9294298, 0.9294298, 0.9294298,
|
||||
1.206438, 1.555569, 1.555569])
|
||||
|
||||
coef_50_1_et_bre = np.array([-0.6492871])
|
||||
|
||||
se_50_1_et_bre = np.array([0.2542493])
|
||||
|
||||
time_50_1_et_bre = np.array([0])
|
||||
|
||||
hazard_50_1_et_bre = np.array([0])
|
||||
|
||||
coef_50_1_st_bre = np.array([-0.7051135])
|
||||
|
||||
se_50_1_st_bre = np.array([0.2852093])
|
||||
|
||||
time_50_1_st_bre = np.array([0])
|
||||
|
||||
hazard_50_1_st_bre = np.array([0])
|
||||
|
||||
coef_50_1_et_st_bre = np.array([-0.8672546])
|
||||
|
||||
se_50_1_et_st_bre = np.array([0.3443235])
|
||||
|
||||
time_50_1_et_st_bre = np.array([0])
|
||||
|
||||
hazard_50_1_et_st_bre = np.array([0])
|
||||
|
||||
coef_50_1_efr = np.array([-0.7119322])
|
||||
|
||||
se_50_1_efr = np.array([0.2533563])
|
||||
|
||||
time_50_1_efr = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.5, 1.6, 1.7, 1.8, 1.9, 2.4, 2.8])
|
||||
|
||||
hazard_50_1_efr = np.array([
|
||||
0, 0.04773902, 0.08238731, 0.2022993, 0.2327053, 0.2736316,
|
||||
0.3215519, 0.3787123, 0.3787123, 0.526184, 0.6323073,
|
||||
0.7627338, 0.7627338, 0.9288858, 0.9288858, 0.9288858,
|
||||
1.206835, 1.556054, 1.556054])
|
||||
|
||||
coef_50_1_et_efr = np.array([-0.7103063])
|
||||
|
||||
se_50_1_et_efr = np.array([0.2598129])
|
||||
|
||||
time_50_1_et_efr = np.array([0])
|
||||
|
||||
hazard_50_1_et_efr = np.array([0])
|
||||
|
||||
coef_50_1_st_efr = np.array([-0.7417904])
|
||||
|
||||
se_50_1_st_efr = np.array([0.2846437])
|
||||
|
||||
time_50_1_st_efr = np.array([0])
|
||||
|
||||
hazard_50_1_st_efr = np.array([0])
|
||||
|
||||
coef_50_1_et_st_efr = np.array([-0.9276112])
|
||||
|
||||
se_50_1_et_st_efr = np.array([0.3462638])
|
||||
|
||||
time_50_1_et_st_efr = np.array([0])
|
||||
|
||||
hazard_50_1_et_st_efr = np.array([0])
|
||||
|
||||
coef_50_2_bre = np.array([-0.5935189, 0.5035724])
|
||||
|
||||
se_50_2_bre = np.array([0.2172841, 0.2399933])
|
||||
|
||||
time_50_2_bre = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.3, 1.4, 1.5, 1.9, 2.7, 2.9])
|
||||
|
||||
hazard_50_2_bre = np.array([
|
||||
0.02695812, 0.09162381, 0.1309537, 0.1768423, 0.2033353,
|
||||
0.2033353, 0.3083449, 0.3547287, 0.4076453, 0.4761318,
|
||||
0.5579718, 0.7610905, 0.918962, 0.918962, 1.136173,
|
||||
1.605757, 2.457676, 2.457676])
|
||||
|
||||
coef_50_2_et_bre = np.array([-0.4001465, 0.4415933])
|
||||
|
||||
se_50_2_et_bre = np.array([0.1992302, 0.2525949])
|
||||
|
||||
time_50_2_et_bre = np.array([0])
|
||||
|
||||
hazard_50_2_et_bre = np.array([0])
|
||||
|
||||
coef_50_2_st_bre = np.array([-0.6574891, 0.4416079])
|
||||
|
||||
se_50_2_st_bre = np.array([0.2753398, 0.269458])
|
||||
|
||||
time_50_2_st_bre = np.array([0])
|
||||
|
||||
hazard_50_2_st_bre = np.array([0])
|
||||
|
||||
coef_50_2_et_st_bre = np.array([-0.3607069, 0.2731982])
|
||||
|
||||
se_50_2_et_st_bre = np.array([0.255415, 0.306942])
|
||||
|
||||
time_50_2_et_st_bre = np.array([0])
|
||||
|
||||
hazard_50_2_et_st_bre = np.array([0])
|
||||
|
||||
coef_50_2_efr = np.array([-0.6107485, 0.5309737])
|
||||
|
||||
se_50_2_efr = np.array([0.2177713, 0.2440535])
|
||||
|
||||
time_50_2_efr = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.3, 1.4, 1.5, 1.9, 2.7, 2.9])
|
||||
|
||||
hazard_50_2_efr = np.array([
|
||||
0.02610571, 0.08933637, 0.1279094, 0.1731699, 0.19933,
|
||||
0.19933, 0.303598, 0.3497025, 0.4023939, 0.4706978,
|
||||
0.5519237, 0.7545023, 0.9129989, 0.9129989, 1.13186,
|
||||
1.60574, 2.472615, 2.472615])
|
||||
|
||||
coef_50_2_et_efr = np.array([-0.4092002, 0.4871344])
|
||||
|
||||
se_50_2_et_efr = np.array([0.1968905, 0.2608527])
|
||||
|
||||
time_50_2_et_efr = np.array([0])
|
||||
|
||||
hazard_50_2_et_efr = np.array([0])
|
||||
|
||||
coef_50_2_st_efr = np.array([-0.6631286, 0.4663285])
|
||||
|
||||
se_50_2_st_efr = np.array([0.2748224, 0.273603])
|
||||
|
||||
time_50_2_st_efr = np.array([0])
|
||||
|
||||
hazard_50_2_st_efr = np.array([0])
|
||||
|
||||
coef_50_2_et_st_efr = np.array([-0.3656059, 0.2943912])
|
||||
|
||||
se_50_2_et_st_efr = np.array([0.2540752, 0.3124632])
|
||||
|
||||
time_50_2_et_st_efr = np.array([0])
|
||||
|
||||
hazard_50_2_et_st_efr = np.array([0])
|
||||
|
||||
coef_100_5_bre = np.array([
|
||||
-0.529776, -0.2916374, -0.1205425, 0.3493476, 0.6034305])
|
||||
|
||||
se_100_5_bre = np.array([
|
||||
0.1789305, 0.1482505, 0.1347422, 0.1528205, 0.1647927])
|
||||
|
||||
time_100_5_bre = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.5, 2.8, 3.2, 3.3])
|
||||
|
||||
hazard_100_5_bre = np.array([
|
||||
0.02558588, 0.05608812, 0.1087773, 0.1451098, 0.1896703,
|
||||
0.2235791, 0.3127521, 0.3355107, 0.439452, 0.504983,
|
||||
0.5431706, 0.5841462, 0.5841462, 0.5841462, 0.6916466,
|
||||
0.7540191, 0.8298704, 1.027876, 1.170335, 1.379306,
|
||||
1.648758, 1.943177, 1.943177, 1.943177, 4.727101])
|
||||
|
||||
coef_100_5_et_bre = np.array([
|
||||
-0.4000784, -0.1790941, -0.1378969, 0.3288529, 0.533246])
|
||||
|
||||
se_100_5_et_bre = np.array([
|
||||
0.1745655, 0.1513545, 0.1393968, 0.1487803, 0.1686992])
|
||||
|
||||
time_100_5_et_bre = np.array([0])
|
||||
|
||||
hazard_100_5_et_bre = np.array([0])
|
||||
|
||||
coef_100_5_st_bre = np.array([
|
||||
-0.53019, -0.3225739, -0.1241568, 0.3246598, 0.6196859])
|
||||
|
||||
se_100_5_st_bre = np.array([
|
||||
0.1954581, 0.1602811, 0.1470644, 0.17121, 0.1784115])
|
||||
|
||||
time_100_5_st_bre = np.array([0])
|
||||
|
||||
hazard_100_5_st_bre = np.array([0])
|
||||
|
||||
coef_100_5_et_st_bre = np.array([
|
||||
-0.3977171, -0.2166136, -0.1387623, 0.3251726, 0.5664705])
|
||||
|
||||
se_100_5_et_st_bre = np.array([
|
||||
0.1951054, 0.1707925, 0.1501968, 0.1699932, 0.1843428])
|
||||
|
||||
time_100_5_et_st_bre = np.array([0])
|
||||
|
||||
hazard_100_5_et_st_bre = np.array([0])
|
||||
|
||||
coef_100_5_efr = np.array([
|
||||
-0.5641909, -0.3233021, -0.1234858, 0.3712328, 0.6421963])
|
||||
|
||||
se_100_5_efr = np.array([
|
||||
0.1804027, 0.1496253, 0.1338531, 0.1529832, 0.1670848])
|
||||
|
||||
time_100_5_efr = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.5, 2.8, 3.2, 3.3])
|
||||
|
||||
hazard_100_5_efr = np.array([
|
||||
0.02393412, 0.05276399, 0.1028432, 0.1383859, 0.1823461,
|
||||
0.2158107, 0.3037825, 0.3264864, 0.4306648, 0.4964367,
|
||||
0.5348595, 0.5760305, 0.5760305, 0.5760305, 0.6842238,
|
||||
0.7468135, 0.8228841, 1.023195, 1.166635, 1.379361,
|
||||
1.652898, 1.950119, 1.950119, 1.950119, 4.910635])
|
||||
|
||||
coef_100_5_et_efr = np.array([
|
||||
-0.4338666, -0.2140139, -0.1397387, 0.3535993, 0.5768645])
|
||||
|
||||
se_100_5_et_efr = np.array([
|
||||
0.1756485, 0.1527244, 0.138298, 0.1488427, 0.1716654])
|
||||
|
||||
time_100_5_et_efr = np.array([0])
|
||||
|
||||
hazard_100_5_et_efr = np.array([0])
|
||||
|
||||
coef_100_5_st_efr = np.array([
|
||||
-0.5530876, -0.3331652, -0.128381, 0.3503472, 0.6397813])
|
||||
|
||||
se_100_5_st_efr = np.array([
|
||||
0.1969338, 0.1614976, 0.1464088, 0.171299, 0.1800787])
|
||||
|
||||
time_100_5_st_efr = np.array([0])
|
||||
|
||||
hazard_100_5_st_efr = np.array([0])
|
||||
|
||||
coef_100_5_et_st_efr = np.array([
|
||||
-0.421153, -0.2350069, -0.1433638, 0.3538863, 0.5934568])
|
||||
|
||||
se_100_5_et_st_efr = np.array([
|
||||
0.1961729, 0.1724719, 0.1492979, 0.170464, 0.1861849])
|
||||
|
||||
time_100_5_et_st_efr = np.array([0])
|
||||
|
||||
hazard_100_5_et_st_efr = np.array([0])
|
||||
|
||||
coef_1000_10_bre = np.array([
|
||||
-0.4699279, -0.464557, -0.308411, -0.2158298, -0.09048563,
|
||||
0.09359662, 0.112588, 0.3343705, 0.3480601, 0.5634985])
|
||||
|
||||
se_1000_10_bre = np.array([
|
||||
0.04722914, 0.04785291, 0.04503528, 0.04586872, 0.04429793,
|
||||
0.0446141, 0.04139944, 0.04464292, 0.04559903, 0.04864393])
|
||||
|
||||
time_1000_10_bre = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4,
|
||||
2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6,
|
||||
3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.6, 4.8, 4.9, 5, 5.1,
|
||||
5.2, 5.7, 5.8, 5.9, 6.9])
|
||||
|
||||
hazard_1000_10_bre = np.array([
|
||||
0.01610374, 0.04853538, 0.08984849, 0.1311329, 0.168397,
|
||||
0.2230488, 0.2755388, 0.3312606, 0.3668702, 0.4146558,
|
||||
0.477935, 0.5290705, 0.5831775, 0.6503129, 0.7113068,
|
||||
0.7830385, 0.8361717, 0.8910061, 0.9615944, 1.024011,
|
||||
1.113399, 1.165349, 1.239827, 1.352902, 1.409548, 1.53197,
|
||||
1.601843, 1.682158, 1.714907, 1.751564, 1.790898, 1.790898,
|
||||
1.83393, 1.83393, 1.936055, 1.992303, 2.050778, 2.118776,
|
||||
2.263056, 2.504999, 2.739343, 2.895514, 3.090349, 3.090349,
|
||||
3.391772, 3.728142, 4.152769, 4.152769, 4.152769, 4.725957,
|
||||
4.725957, 5.69653, 5.69653, 5.69653])
|
||||
|
||||
coef_1000_10_et_bre = np.array([
|
||||
-0.410889, -0.3929442, -0.2975845, -0.1851533, -0.0918359,
|
||||
0.1011997, 0.106735, 0.2899179, 0.3220672, 0.5069589])
|
||||
|
||||
se_1000_10_et_bre = np.array([
|
||||
0.04696754, 0.04732169, 0.04537707, 0.04605371, 0.04365232,
|
||||
0.04450021, 0.04252475, 0.04482007, 0.04562374, 0.04859727])
|
||||
|
||||
time_1000_10_et_bre = np.array([0])
|
||||
|
||||
hazard_1000_10_et_bre = np.array([0])
|
||||
|
||||
coef_1000_10_st_bre = np.array([
|
||||
-0.471015, -0.4766859, -0.3070839, -0.2091938, -0.09190845,
|
||||
0.0964942, 0.1138269, 0.3307131, 0.3543551, 0.562492])
|
||||
|
||||
se_1000_10_st_bre = np.array([
|
||||
0.04814778, 0.04841938, 0.04572291, 0.04641227, 0.04502525,
|
||||
0.04517603, 0.04203737, 0.04524356, 0.04635037, 0.04920866])
|
||||
|
||||
time_1000_10_st_bre = np.array([0])
|
||||
|
||||
hazard_1000_10_st_bre = np.array([0])
|
||||
|
||||
coef_1000_10_et_st_bre = np.array([
|
||||
-0.4165849, -0.4073504, -0.2980959, -0.1765194, -0.09152798,
|
||||
0.1013213, 0.1009838, 0.2859668, 0.3247608, 0.5044448])
|
||||
|
||||
se_1000_10_et_st_bre = np.array([
|
||||
0.04809818, 0.04809499, 0.0460829, 0.04679922, 0.0445294,
|
||||
0.04514045, 0.04339298, 0.04580591, 0.04652447, 0.04920744])
|
||||
|
||||
time_1000_10_et_st_bre = np.array([0])
|
||||
|
||||
hazard_1000_10_et_st_bre = np.array([0])
|
||||
|
||||
coef_1000_10_efr = np.array([
|
||||
-0.4894399, -0.4839746, -0.3227769, -0.2261293, -0.09318482,
|
||||
0.09767154, 0.1173205, 0.3493732, 0.3640146, 0.5879749])
|
||||
|
||||
se_1000_10_efr = np.array([
|
||||
0.0474181, 0.04811855, 0.04507655, 0.04603044, 0.04440409,
|
||||
0.04478202, 0.04136728, 0.04473343, 0.045768, 0.04891375])
|
||||
|
||||
time_1000_10_efr = np.array([
|
||||
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2,
|
||||
1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4,
|
||||
2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6,
|
||||
3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.6, 4.8, 4.9, 5, 5.1,
|
||||
5.2, 5.7, 5.8, 5.9, 6.9])
|
||||
|
||||
hazard_1000_10_efr = np.array([
|
||||
0.01549698, 0.04680035, 0.08682564, 0.1269429, 0.1632388,
|
||||
0.2167291, 0.2682311, 0.3231316, 0.3582936, 0.4054892, 0.4681098,
|
||||
0.5188697, 0.5727059, 0.639571, 0.7003012, 0.7718979, 0.825053,
|
||||
0.880063, 0.950935, 1.013828, 1.103903, 1.156314, 1.231707,
|
||||
1.346235, 1.40359, 1.527475, 1.598231, 1.6795, 1.712779,
|
||||
1.750227, 1.790455, 1.790455, 1.834455, 1.834455, 1.938997,
|
||||
1.996804, 2.056859, 2.126816, 2.275217, 2.524027, 2.76669,
|
||||
2.929268, 3.13247, 3.13247, 3.448515, 3.80143, 4.249649,
|
||||
4.249649, 4.249649, 4.851365, 4.851365, 5.877307, 5.877307, 5.877307])
|
||||
|
||||
coef_1000_10_et_efr = np.array([
|
||||
-0.4373066, -0.4131901, -0.3177637, -0.1978493, -0.09679451,
|
||||
0.1092037, 0.1136069, 0.3088907, 0.3442007, 0.5394121])
|
||||
|
||||
se_1000_10_et_efr = np.array([
|
||||
0.04716041, 0.04755342, 0.04546713, 0.04627802, 0.04376583,
|
||||
0.04474868, 0.04259991, 0.04491564, 0.04589027, 0.04890847])
|
||||
|
||||
time_1000_10_et_efr = np.array([0])
|
||||
|
||||
hazard_1000_10_et_efr = np.array([0])
|
||||
|
||||
coef_1000_10_st_efr = np.array([
|
||||
-0.4911117, -0.4960756, -0.3226152, -0.220949, -0.09478141,
|
||||
0.1015735, 0.1195524, 0.3446977, 0.3695904, 0.5878576])
|
||||
|
||||
se_1000_10_st_efr = np.array([
|
||||
0.04833676, 0.04868554, 0.04578407, 0.04661755, 0.04518267,
|
||||
0.04537135, 0.04202183, 0.04531266, 0.0464931, 0.04949831])
|
||||
|
||||
time_1000_10_st_efr = np.array([0])
|
||||
|
||||
hazard_1000_10_st_efr = np.array([0])
|
||||
|
||||
coef_1000_10_et_st_efr = np.array([
|
||||
-0.444355, -0.4283278, -0.3198815, -0.1901781, -0.09727039,
|
||||
0.1106191, 0.1092104, 0.3034778, 0.3451699, 0.5382381])
|
||||
|
||||
se_1000_10_et_st_efr = np.array([
|
||||
0.04830664, 0.04833619, 0.04617371, 0.04706401, 0.04472699,
|
||||
0.0454208, 0.04350539, 0.04588588, 0.04675675, 0.04950987])
|
||||
|
||||
time_1000_10_et_st_efr = np.array([0])
|
||||
|
||||
hazard_1000_10_et_st_efr = np.array([0])
|
||||
@ -0,0 +1,416 @@
|
||||
import itertools
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
from statsmodels.duration.hazard_regression import PHReg
|
||||
from numpy.testing import (assert_allclose,
|
||||
assert_equal, assert_)
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
# TODO: Include some corner cases: data sets with empty strata, strata
|
||||
# with no events, entry times after censoring times, etc.
|
||||
|
||||
# All the R results
|
||||
from .results import survival_r_results
|
||||
from .results import survival_enet_r_results
|
||||
|
||||
"""
|
||||
Tests of PHReg against R coxph.
|
||||
|
||||
Tests include entry times and stratification.
|
||||
|
||||
phreg_gentests.py generates the test data sets and puts them into the
|
||||
results folder.
|
||||
|
||||
survival.R runs R on all the test data sets and constructs the
|
||||
survival_r_results module.
|
||||
"""
|
||||
|
||||
# Arguments passed to the PHReg fit method.
|
||||
args = {"method": "bfgs", "disp": 0}
|
||||
|
||||
|
||||
def get_results(n, p, ext, ties):
|
||||
if ext is None:
|
||||
coef_name = "coef_%d_%d_%s" % (n, p, ties)
|
||||
se_name = "se_%d_%d_%s" % (n, p, ties)
|
||||
time_name = "time_%d_%d_%s" % (n, p, ties)
|
||||
hazard_name = "hazard_%d_%d_%s" % (n, p, ties)
|
||||
else:
|
||||
coef_name = "coef_%d_%d_%s_%s" % (n, p, ext, ties)
|
||||
se_name = "se_%d_%d_%s_%s" % (n, p, ext, ties)
|
||||
time_name = "time_%d_%d_%s_%s" % (n, p, ext, ties)
|
||||
hazard_name = "hazard_%d_%d_%s_%s" % (n, p, ext, ties)
|
||||
coef = getattr(survival_r_results, coef_name)
|
||||
se = getattr(survival_r_results, se_name)
|
||||
time = getattr(survival_r_results, time_name)
|
||||
hazard = getattr(survival_r_results, hazard_name)
|
||||
return coef, se, time, hazard
|
||||
|
||||
class TestPHReg:
|
||||
|
||||
# Load a data file from the results directory
|
||||
@staticmethod
|
||||
def load_file(fname):
|
||||
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
data = np.genfromtxt(os.path.join(cur_dir, 'results', fname),
|
||||
delimiter=" ")
|
||||
time = data[:,0]
|
||||
status = data[:,1]
|
||||
entry = data[:,2]
|
||||
exog = data[:,3:]
|
||||
|
||||
return time, status, entry, exog
|
||||
|
||||
# Run a single test against R output
|
||||
@staticmethod
|
||||
def do1(fname, ties, entry_f, strata_f):
|
||||
|
||||
# Read the test data.
|
||||
time, status, entry, exog = TestPHReg.load_file(fname)
|
||||
n = len(time)
|
||||
|
||||
vs = fname.split("_")
|
||||
n = int(vs[2])
|
||||
p = int(vs[3].split(".")[0])
|
||||
ties1 = ties[0:3]
|
||||
|
||||
# Needs to match the kronecker statement in survival.R
|
||||
strata = np.kron(range(5), np.ones(n // 5))
|
||||
|
||||
# No stratification or entry times
|
||||
mod = PHReg(time, exog, status, ties=ties)
|
||||
phrb = mod.fit(**args)
|
||||
coef_r, se_r, time_r, hazard_r = get_results(n, p, None, ties1)
|
||||
assert_allclose(phrb.params, coef_r, rtol=1e-3)
|
||||
assert_allclose(phrb.bse, se_r, rtol=1e-4)
|
||||
time_h, cumhaz, surv = phrb.baseline_cumulative_hazard[0]
|
||||
|
||||
# Entry times but no stratification
|
||||
phrb = PHReg(time, exog, status, entry=entry,
|
||||
ties=ties).fit(**args)
|
||||
coef, se, time_r, hazard_r = get_results(n, p, "et", ties1)
|
||||
assert_allclose(phrb.params, coef, rtol=1e-3)
|
||||
assert_allclose(phrb.bse, se, rtol=1e-3)
|
||||
|
||||
# Stratification but no entry times
|
||||
phrb = PHReg(time, exog, status, strata=strata,
|
||||
ties=ties).fit(**args)
|
||||
coef, se, time_r, hazard_r = get_results(n, p, "st", ties1)
|
||||
assert_allclose(phrb.params, coef, rtol=1e-4)
|
||||
assert_allclose(phrb.bse, se, rtol=1e-4)
|
||||
|
||||
# Stratification and entry times
|
||||
phrb = PHReg(time, exog, status, entry=entry,
|
||||
strata=strata, ties=ties).fit(**args)
|
||||
coef, se, time_r, hazard_r = get_results(n, p, "et_st", ties1)
|
||||
assert_allclose(phrb.params, coef, rtol=1e-3)
|
||||
assert_allclose(phrb.bse, se, rtol=1e-4)
|
||||
|
||||
#smoke test
|
||||
time_h, cumhaz, surv = phrb.baseline_cumulative_hazard[0]
|
||||
|
||||
def test_missing(self):
|
||||
|
||||
np.random.seed(34234)
|
||||
time = 50 * np.random.uniform(size=200)
|
||||
status = np.random.randint(0, 2, 200).astype(np.float64)
|
||||
exog = np.random.normal(size=(200,4))
|
||||
|
||||
time[0:5] = np.nan
|
||||
status[5:10] = np.nan
|
||||
exog[10:15,:] = np.nan
|
||||
|
||||
md = PHReg(time, exog, status, missing='drop')
|
||||
assert_allclose(len(md.endog), 185)
|
||||
assert_allclose(len(md.status), 185)
|
||||
assert_allclose(md.exog.shape, np.r_[185,4])
|
||||
|
||||
def test_formula(self):
|
||||
|
||||
np.random.seed(34234)
|
||||
time = 50 * np.random.uniform(size=200)
|
||||
status = np.random.randint(0, 2, 200).astype(np.float64)
|
||||
exog = np.random.normal(size=(200,4))
|
||||
entry = np.zeros_like(time)
|
||||
entry[0:10] = time[0:10] / 2
|
||||
|
||||
df = pd.DataFrame({"time": time, "status": status,
|
||||
"exog1": exog[:, 0], "exog2": exog[:, 1],
|
||||
"exog3": exog[:, 2], "exog4": exog[:, 3],
|
||||
"entry": entry})
|
||||
|
||||
mod1 = PHReg(time, exog, status, entry=entry)
|
||||
rslt1 = mod1.fit()
|
||||
|
||||
# works with "0 +" on RHS but issues warning
|
||||
fml = "time ~ exog1 + exog2 + exog3 + exog4"
|
||||
mod2 = PHReg.from_formula(fml, df, status=status,
|
||||
entry=entry)
|
||||
rslt2 = mod2.fit()
|
||||
|
||||
mod3 = PHReg.from_formula(fml, df, status="status",
|
||||
entry="entry")
|
||||
rslt3 = mod3.fit()
|
||||
|
||||
assert_allclose(rslt1.params, rslt2.params)
|
||||
assert_allclose(rslt1.params, rslt3.params)
|
||||
assert_allclose(rslt1.bse, rslt2.bse)
|
||||
assert_allclose(rslt1.bse, rslt3.bse)
|
||||
|
||||
def test_formula_cat_interactions(self):
|
||||
|
||||
time = np.r_[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
status = np.r_[1, 1, 0, 0, 1, 0, 1, 1, 1]
|
||||
x1 = np.r_[1, 1, 1, 2, 2, 2, 3, 3, 3]
|
||||
x2 = np.r_[1, 2, 3, 1, 2, 3, 1, 2, 3]
|
||||
df = pd.DataFrame({"time": time, "status": status,
|
||||
"x1": x1, "x2": x2})
|
||||
|
||||
model1 = PHReg.from_formula("time ~ C(x1) + C(x2) + C(x1)*C(x2)", status="status",
|
||||
data=df)
|
||||
assert_equal(model1.exog.shape, [9, 8])
|
||||
|
||||
def test_predict_formula(self):
|
||||
|
||||
n = 100
|
||||
np.random.seed(34234)
|
||||
time = 50 * np.random.uniform(size=n)
|
||||
status = np.random.randint(0, 2, n).astype(np.float64)
|
||||
exog = np.random.uniform(1, 2, size=(n, 2))
|
||||
|
||||
df = pd.DataFrame({"time": time, "status": status,
|
||||
"exog1": exog[:, 0], "exog2": exog[:, 1]})
|
||||
|
||||
# Works with "0 +" on RHS but issues warning
|
||||
fml = "time ~ exog1 + np.log(exog2) + exog1*exog2"
|
||||
model1 = PHReg.from_formula(fml, df, status=status)
|
||||
result1 = model1.fit()
|
||||
|
||||
from patsy import dmatrix
|
||||
dfp = dmatrix(model1.data.design_info, df)
|
||||
|
||||
pr1 = result1.predict()
|
||||
pr2 = result1.predict(exog=df)
|
||||
pr3 = model1.predict(result1.params, exog=dfp) # No standard errors
|
||||
pr4 = model1.predict(result1.params,
|
||||
cov_params=result1.cov_params(),
|
||||
exog=dfp)
|
||||
|
||||
prl = (pr1, pr2, pr3, pr4)
|
||||
for i in range(4):
|
||||
for j in range(i):
|
||||
assert_allclose(prl[i].predicted_values,
|
||||
prl[j].predicted_values)
|
||||
|
||||
prl = (pr1, pr2, pr4)
|
||||
for i in range(3):
|
||||
for j in range(i):
|
||||
assert_allclose(prl[i].standard_errors, prl[j].standard_errors)
|
||||
|
||||
def test_formula_args(self):
|
||||
|
||||
np.random.seed(34234)
|
||||
n = 200
|
||||
time = 50 * np.random.uniform(size=n)
|
||||
status = np.random.randint(0, 2, size=n).astype(np.float64)
|
||||
exog = np.random.normal(size=(200, 2))
|
||||
offset = np.random.uniform(size=n)
|
||||
entry = np.random.uniform(0, 1, size=n) * time
|
||||
|
||||
df = pd.DataFrame({"time": time, "status": status, "x1": exog[:, 0],
|
||||
"x2": exog[:, 1], "offset": offset, "entry": entry})
|
||||
model1 = PHReg.from_formula("time ~ x1 + x2", status="status", offset="offset",
|
||||
entry="entry", data=df)
|
||||
result1 = model1.fit()
|
||||
model2 = PHReg.from_formula("time ~ x1 + x2", status=df.status, offset=df.offset,
|
||||
entry=df.entry, data=df)
|
||||
result2 = model2.fit()
|
||||
assert_allclose(result1.params, result2.params)
|
||||
assert_allclose(result1.bse, result2.bse)
|
||||
|
||||
def test_offset(self):
|
||||
|
||||
np.random.seed(34234)
|
||||
time = 50 * np.random.uniform(size=200)
|
||||
status = np.random.randint(0, 2, 200).astype(np.float64)
|
||||
exog = np.random.normal(size=(200,4))
|
||||
|
||||
for ties in "breslow", "efron":
|
||||
mod1 = PHReg(time, exog, status)
|
||||
rslt1 = mod1.fit()
|
||||
offset = exog[:,0] * rslt1.params[0]
|
||||
exog = exog[:, 1:]
|
||||
|
||||
mod2 = PHReg(time, exog, status, offset=offset, ties=ties)
|
||||
rslt2 = mod2.fit()
|
||||
|
||||
assert_allclose(rslt2.params, rslt1.params[1:])
|
||||
|
||||
def test_post_estimation(self):
|
||||
# All regression tests
|
||||
np.random.seed(34234)
|
||||
time = 50 * np.random.uniform(size=200)
|
||||
status = np.random.randint(0, 2, 200).astype(np.float64)
|
||||
exog = np.random.normal(size=(200,4))
|
||||
|
||||
mod = PHReg(time, exog, status)
|
||||
rslt = mod.fit()
|
||||
mart_resid = rslt.martingale_residuals
|
||||
assert_allclose(np.abs(mart_resid).sum(), 120.72475743348433)
|
||||
|
||||
w_avg = rslt.weighted_covariate_averages
|
||||
assert_allclose(np.abs(w_avg[0]).sum(0),
|
||||
np.r_[7.31008415, 9.77608674,10.89515885, 13.1106801])
|
||||
|
||||
bc_haz = rslt.baseline_cumulative_hazard
|
||||
v = [np.mean(np.abs(x)) for x in bc_haz[0]]
|
||||
w = np.r_[23.482841556421608, 0.44149255358417017,
|
||||
0.68660114081275281]
|
||||
assert_allclose(v, w)
|
||||
|
||||
score_resid = rslt.score_residuals
|
||||
v = np.r_[ 0.50924792, 0.4533952, 0.4876718, 0.5441128]
|
||||
w = np.abs(score_resid).mean(0)
|
||||
assert_allclose(v, w)
|
||||
|
||||
groups = np.random.randint(0, 3, 200)
|
||||
mod = PHReg(time, exog, status)
|
||||
rslt = mod.fit(groups=groups)
|
||||
robust_cov = rslt.cov_params()
|
||||
v = [0.00513432, 0.01278423, 0.00810427, 0.00293147]
|
||||
w = np.abs(robust_cov).mean(0)
|
||||
assert_allclose(v, w, rtol=1e-6)
|
||||
|
||||
s_resid = rslt.schoenfeld_residuals
|
||||
ii = np.flatnonzero(np.isfinite(s_resid).all(1))
|
||||
s_resid = s_resid[ii, :]
|
||||
v = np.r_[0.85154336, 0.72993748, 0.73758071, 0.78599333]
|
||||
assert_allclose(np.abs(s_resid).mean(0), v)
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_summary(self):
|
||||
np.random.seed(34234)
|
||||
time = 50 * np.random.uniform(size=200)
|
||||
status = np.random.randint(0, 2, 200).astype(np.float64)
|
||||
exog = np.random.normal(size=(200,4))
|
||||
|
||||
mod = PHReg(time, exog, status)
|
||||
rslt = mod.fit()
|
||||
smry = rslt.summary()
|
||||
|
||||
strata = np.kron(np.arange(50), np.ones(4))
|
||||
mod = PHReg(time, exog, status, strata=strata)
|
||||
rslt = mod.fit()
|
||||
smry = rslt.summary()
|
||||
msg = "3 strata dropped for having no events"
|
||||
assert_(msg in str(smry))
|
||||
|
||||
groups = np.kron(np.arange(25), np.ones(8))
|
||||
mod = PHReg(time, exog, status)
|
||||
rslt = mod.fit(groups=groups)
|
||||
smry = rslt.summary()
|
||||
|
||||
entry = np.random.uniform(0.1, 0.8, 200) * time
|
||||
mod = PHReg(time, exog, status, entry=entry)
|
||||
rslt = mod.fit()
|
||||
smry = rslt.summary()
|
||||
msg = "200 observations have positive entry times"
|
||||
assert_(msg in str(smry))
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_predict(self):
|
||||
# All smoke tests. We should be able to convert the lhr and hr
|
||||
# tests into real tests against R. There are many options to
|
||||
# this function that may interact in complicated ways. Only a
|
||||
# few key combinations are tested here.
|
||||
np.random.seed(34234)
|
||||
endog = 50 * np.random.uniform(size=200)
|
||||
status = np.random.randint(0, 2, 200).astype(np.float64)
|
||||
exog = np.random.normal(size=(200,4))
|
||||
|
||||
mod = PHReg(endog, exog, status)
|
||||
rslt = mod.fit()
|
||||
rslt.predict()
|
||||
for pred_type in 'lhr', 'hr', 'cumhaz', 'surv':
|
||||
rslt.predict(pred_type=pred_type)
|
||||
rslt.predict(endog=endog[0:10], pred_type=pred_type)
|
||||
rslt.predict(endog=endog[0:10], exog=exog[0:10,:],
|
||||
pred_type=pred_type)
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_get_distribution(self):
|
||||
np.random.seed(34234)
|
||||
n = 200
|
||||
exog = np.random.normal(size=(n, 2))
|
||||
lin_pred = exog.sum(1)
|
||||
elin_pred = np.exp(-lin_pred)
|
||||
time = -elin_pred * np.log(np.random.uniform(size=n))
|
||||
status = np.ones(n)
|
||||
status[0:20] = 0
|
||||
strata = np.kron(range(5), np.ones(n // 5))
|
||||
|
||||
mod = PHReg(time, exog, status=status, strata=strata)
|
||||
rslt = mod.fit()
|
||||
|
||||
dist = rslt.get_distribution()
|
||||
|
||||
fitted_means = dist.mean()
|
||||
true_means = elin_pred
|
||||
fitted_var = dist.var()
|
||||
fitted_sd = dist.std()
|
||||
sample = dist.rvs()
|
||||
|
||||
def test_fit_regularized(self):
|
||||
|
||||
# Data set sizes
|
||||
for n,p in (50,2),(100,5):
|
||||
|
||||
# Penalty weights
|
||||
for js,s in enumerate([0,0.1]):
|
||||
|
||||
coef_name = "coef_%d_%d_%d" % (n, p, js)
|
||||
params = getattr(survival_enet_r_results, coef_name)
|
||||
|
||||
fname = "survival_data_%d_%d.csv" % (n, p)
|
||||
time, status, entry, exog = self.load_file(fname)
|
||||
|
||||
exog -= exog.mean(0)
|
||||
exog /= exog.std(0, ddof=1)
|
||||
|
||||
model = PHReg(time, exog, status=status, ties='breslow')
|
||||
sm_result = model.fit_regularized(alpha=s)
|
||||
|
||||
# The agreement is not very high, the issue may be on
|
||||
# the R side. See below for further checks.
|
||||
assert_allclose(sm_result.params, params, rtol=0.3)
|
||||
|
||||
# The penalized log-likelihood that we are maximizing.
|
||||
def plf(params):
|
||||
llf = model.loglike(params) / len(time)
|
||||
L1_wt = 1
|
||||
llf = llf - s * ((1 - L1_wt)*np.sum(params**2) / 2 + L1_wt*np.sum(np.abs(params)))
|
||||
return llf
|
||||
|
||||
# Confirm that we are doing better than glmnet.
|
||||
llf_r = plf(params)
|
||||
llf_sm = plf(sm_result.params)
|
||||
assert_equal(np.sign(llf_sm - llf_r), 1)
|
||||
|
||||
|
||||
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
rdir = os.path.join(cur_dir, 'results')
|
||||
fnames = os.listdir(rdir)
|
||||
fnames = [x for x in fnames if x.startswith("survival")
|
||||
and x.endswith(".csv")]
|
||||
|
||||
ties = ("breslow", "efron")
|
||||
entry_f = (False, True)
|
||||
strata_f = (False, True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('fname,ties,entry_f,strata_f',
|
||||
list(itertools.product(fnames, ties, entry_f, strata_f)))
|
||||
def test_r(fname, ties, entry_f, strata_f):
|
||||
TestPHReg.do1(fname, ties, entry_f, strata_f)
|
||||
@ -0,0 +1,565 @@
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
from statsmodels.duration.survfunc import (
|
||||
SurvfuncRight, survdiff, plot_survfunc,
|
||||
CumIncidenceRight)
|
||||
from numpy.testing import assert_allclose
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
# If true, the output is written to a multi-page pdf file.
|
||||
pdf_output = False
|
||||
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def close_or_save(pdf, fig):
|
||||
if pdf_output:
|
||||
pdf.savefig(fig)
|
||||
|
||||
|
||||
"""
|
||||
library(survival)
|
||||
ti1 = c(3, 1, 2, 3, 2, 1, 5, 3)
|
||||
st1 = c(0, 1, 1, 1, 0, 0, 1, 0)
|
||||
ti2 = c(1, 1, 2, 3, 7, 1, 5, 3, 9)
|
||||
st2 = c(0, 1, 0, 0, 1, 0, 1, 0, 1)
|
||||
|
||||
ti = c(ti1, ti2)
|
||||
st = c(st1, st2)
|
||||
ix = c(rep(1, length(ti1)), rep(2, length(ti2)))
|
||||
sd = survdiff(Surv(ti, st) ~ ix)
|
||||
"""
|
||||
|
||||
ti1 = np.r_[3, 1, 2, 3, 2, 1, 5, 3]
|
||||
st1 = np.r_[0, 1, 1, 1, 0, 0, 1, 0]
|
||||
times1 = np.r_[1, 2, 3, 5]
|
||||
surv_prob1 = np.r_[0.8750000, 0.7291667, 0.5468750, 0.0000000]
|
||||
surv_prob_se1 = np.r_[0.1169268, 0.1649762, 0.2005800, np.nan]
|
||||
n_risk1 = np.r_[8, 6, 4, 1]
|
||||
n_events1 = np.r_[1., 1., 1., 1.]
|
||||
|
||||
ti2 = np.r_[1, 1, 2, 3, 7, 1, 5, 3, 9]
|
||||
st2 = np.r_[0, 1, 0, 0, 1, 0, 1, 0, 1]
|
||||
times2 = np.r_[1, 5, 7, 9]
|
||||
surv_prob2 = np.r_[0.8888889, 0.5925926, 0.2962963, 0.0000000]
|
||||
surv_prob_se2 = np.r_[0.1047566, 0.2518034, 0.2444320, np.nan]
|
||||
n_risk2 = np.r_[9, 3, 2, 1]
|
||||
n_events2 = np.r_[1., 1., 1., 1.]
|
||||
|
||||
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
fp = os.path.join(cur_dir, 'results', 'bmt.csv')
|
||||
bmt = pd.read_csv(fp)
|
||||
|
||||
|
||||
def test_survfunc1():
|
||||
# Test where all times have at least 1 event.
|
||||
|
||||
sr = SurvfuncRight(ti1, st1)
|
||||
assert_allclose(sr.surv_prob, surv_prob1, atol=1e-5, rtol=1e-5)
|
||||
assert_allclose(sr.surv_prob_se, surv_prob_se1, atol=1e-5, rtol=1e-5)
|
||||
assert_allclose(sr.surv_times, times1)
|
||||
assert_allclose(sr.n_risk, n_risk1)
|
||||
assert_allclose(sr.n_events, n_events1)
|
||||
|
||||
|
||||
def test_survfunc2():
|
||||
# Test where some times have no events.
|
||||
|
||||
sr = SurvfuncRight(ti2, st2)
|
||||
assert_allclose(sr.surv_prob, surv_prob2, atol=1e-5, rtol=1e-5)
|
||||
assert_allclose(sr.surv_prob_se, surv_prob_se2, atol=1e-5, rtol=1e-5)
|
||||
assert_allclose(sr.surv_times, times2)
|
||||
assert_allclose(sr.n_risk, n_risk2)
|
||||
assert_allclose(sr.n_events, n_events2)
|
||||
|
||||
|
||||
def test_survdiff_basic():
|
||||
|
||||
# Constants taken from R, code above
|
||||
ti = np.concatenate((ti1, ti2))
|
||||
st = np.concatenate((st1, st2))
|
||||
groups = np.ones(len(ti))
|
||||
groups[0:len(ti1)] = 0
|
||||
z, p = survdiff(ti, st, groups)
|
||||
assert_allclose(z, 2.14673, atol=1e-4, rtol=1e-4)
|
||||
assert_allclose(p, 0.14287, atol=1e-4, rtol=1e-4)
|
||||
|
||||
|
||||
def test_simultaneous_cb():
|
||||
|
||||
# The exact numbers here are regression tests, but they are close
|
||||
# to page 103 of Klein and Moeschberger.
|
||||
|
||||
df = bmt.loc[bmt["Group"] == "ALL", :]
|
||||
sf = SurvfuncRight(df["T"], df["Status"])
|
||||
lcb1, ucb1 = sf.simultaneous_cb(transform="log")
|
||||
lcb2, ucb2 = sf.simultaneous_cb(transform="arcsin")
|
||||
|
||||
ti = sf.surv_times.tolist()
|
||||
ix = [ti.index(x) for x in (110, 122, 129, 172)]
|
||||
assert_allclose(lcb1[ix], np.r_[0.43590582, 0.42115592,
|
||||
0.4035897, 0.38785927])
|
||||
assert_allclose(ucb1[ix], np.r_[0.93491636, 0.89776803,
|
||||
0.87922239, 0.85894181])
|
||||
|
||||
assert_allclose(lcb2[ix], np.r_[0.52115708, 0.48079378,
|
||||
0.45595321, 0.43341115])
|
||||
assert_allclose(ucb2[ix], np.r_[0.96465636, 0.92745068,
|
||||
0.90885428, 0.88796708])
|
||||
|
||||
|
||||
def test_bmt():
|
||||
# All tests against SAS
|
||||
# Results taken from here:
|
||||
# http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_lifetest_details03.htm
|
||||
|
||||
# Confidence intervals for 25% percentile of the survival
|
||||
# distribution (for "ALL" subjects), taken from the SAS web site
|
||||
cb = {"linear": [107, 276],
|
||||
"cloglog": [86, 230],
|
||||
"log": [107, 332],
|
||||
"asinsqrt": [104, 276],
|
||||
"logit": [104, 230]}
|
||||
|
||||
dfa = bmt[bmt.Group == "ALL"]
|
||||
|
||||
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
fp = os.path.join(cur_dir, 'results', 'bmt_results.csv')
|
||||
rslt = pd.read_csv(fp)
|
||||
|
||||
sf = SurvfuncRight(dfa["T"].values, dfa.Status.values)
|
||||
|
||||
assert_allclose(sf.surv_times, rslt.t)
|
||||
assert_allclose(sf.surv_prob, rslt.s, atol=1e-4, rtol=1e-4)
|
||||
assert_allclose(sf.surv_prob_se, rslt.se, atol=1e-4, rtol=1e-4)
|
||||
|
||||
for method in "linear", "cloglog", "log", "logit", "asinsqrt":
|
||||
lcb, ucb = sf.quantile_ci(0.25, method=method)
|
||||
assert_allclose(cb[method], np.r_[lcb, ucb])
|
||||
|
||||
|
||||
def test_survdiff():
|
||||
# Results come from R survival and survMisc packages (survMisc is
|
||||
# used for non G-rho family tests but does not seem to support
|
||||
# stratification)
|
||||
|
||||
full_df = bmt.copy()
|
||||
df = bmt[bmt.Group != "ALL"].copy()
|
||||
|
||||
# Not stratified
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group)
|
||||
assert_allclose(stat, 13.44556, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="gb")
|
||||
assert_allclose(stat, 15.38787, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="tw")
|
||||
assert_allclose(stat, 14.98382, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="fh",
|
||||
fh_p=0.5)
|
||||
assert_allclose(stat, 14.46866, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, weight_type="fh",
|
||||
fh_p=1)
|
||||
assert_allclose(stat, 14.84500, atol=1e-4, rtol=1e-4)
|
||||
|
||||
# Not stratified, >2 groups
|
||||
stat, p = survdiff(full_df["T"], full_df.Status, full_df.Group,
|
||||
weight_type="fh", fh_p=1)
|
||||
assert_allclose(stat, 15.67247, atol=1e-4, rtol=1e-4)
|
||||
|
||||
# 5 strata
|
||||
strata = np.arange(df.shape[0]) % 5
|
||||
df["strata"] = strata
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata)
|
||||
assert_allclose(stat, 11.97799, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata,
|
||||
weight_type="fh", fh_p=0.5)
|
||||
assert_allclose(stat, 12.6257, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata,
|
||||
weight_type="fh", fh_p=1)
|
||||
assert_allclose(stat, 12.73565, atol=1e-4, rtol=1e-4)
|
||||
|
||||
# 5 strata, >2 groups
|
||||
full_strata = np.arange(full_df.shape[0]) % 5
|
||||
full_df["strata"] = full_strata
|
||||
stat, p = survdiff(full_df["T"], full_df.Status, full_df.Group,
|
||||
strata=full_df.strata, weight_type="fh", fh_p=0.5)
|
||||
assert_allclose(stat, 13.56793, atol=1e-4, rtol=1e-4)
|
||||
|
||||
# 8 strata
|
||||
df["strata"] = np.arange(df.shape[0]) % 8
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata)
|
||||
assert_allclose(stat, 12.12631, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata,
|
||||
weight_type="fh", fh_p=0.5)
|
||||
assert_allclose(stat, 12.9633, atol=1e-4, rtol=1e-4)
|
||||
stat, p = survdiff(df["T"], df.Status, df.Group, strata=df.strata,
|
||||
weight_type="fh", fh_p=1)
|
||||
assert_allclose(stat, 13.35259, atol=1e-4, rtol=1e-4)
|
||||
|
||||
|
||||
@pytest.mark.matplotlib
|
||||
def test_plot_km(close_figures):
|
||||
|
||||
if pdf_output:
|
||||
from matplotlib.backends.backend_pdf import PdfPages
|
||||
pdf = PdfPages("test_survfunc.pdf")
|
||||
else:
|
||||
pdf = None
|
||||
|
||||
sr1 = SurvfuncRight(ti1, st1)
|
||||
sr2 = SurvfuncRight(ti2, st2)
|
||||
|
||||
fig = plot_survfunc(sr1)
|
||||
close_or_save(pdf, fig)
|
||||
|
||||
fig = plot_survfunc(sr2)
|
||||
close_or_save(pdf, fig)
|
||||
|
||||
fig = plot_survfunc([sr1, sr2])
|
||||
close_or_save(pdf, fig)
|
||||
|
||||
# Plot the SAS BMT data
|
||||
gb = bmt.groupby("Group")
|
||||
sv = []
|
||||
for g in gb:
|
||||
s0 = SurvfuncRight(g[1]["T"], g[1]["Status"], title=g[0])
|
||||
sv.append(s0)
|
||||
fig = plot_survfunc(sv)
|
||||
ax = fig.get_axes()[0]
|
||||
ax.set_position([0.1, 0.1, 0.64, 0.8])
|
||||
ha, lb = ax.get_legend_handles_labels()
|
||||
fig.legend([ha[k] for k in (0, 2, 4)],
|
||||
[lb[k] for k in (0, 2, 4)],
|
||||
loc='center right')
|
||||
close_or_save(pdf, fig)
|
||||
|
||||
# Simultaneous CB for BMT data
|
||||
ii = bmt.Group == "ALL"
|
||||
sf = SurvfuncRight(bmt.loc[ii, "T"], bmt.loc[ii, "Status"])
|
||||
fig = sf.plot()
|
||||
ax = fig.get_axes()[0]
|
||||
ax.set_position([0.1, 0.1, 0.64, 0.8])
|
||||
ha, lb = ax.get_legend_handles_labels()
|
||||
lcb, ucb = sf.simultaneous_cb(transform="log")
|
||||
plt.fill_between(sf.surv_times, lcb, ucb, color="lightgrey")
|
||||
lcb, ucb = sf.simultaneous_cb(transform="arcsin")
|
||||
plt.plot(sf.surv_times, lcb, color="darkgrey")
|
||||
plt.plot(sf.surv_times, ucb, color="darkgrey")
|
||||
plt.plot(sf.surv_times, sf.surv_prob - 2*sf.surv_prob_se, color="red")
|
||||
plt.plot(sf.surv_times, sf.surv_prob + 2*sf.surv_prob_se, color="red")
|
||||
plt.xlim(100, 600)
|
||||
close_or_save(pdf, fig)
|
||||
|
||||
if pdf_output:
|
||||
pdf.close()
|
||||
|
||||
|
||||
def test_weights1():
|
||||
# tm = c(1, 3, 5, 6, 7, 8, 8, 9, 3, 4, 1, 3, 2)
|
||||
# st = c(1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0)
|
||||
# wt = c(1, 2, 3, 2, 3, 1, 2, 1, 1, 2, 2, 3, 1)
|
||||
# library(survival)
|
||||
# sf = survfit(Surv(tm, st) ~ 1, weights=wt, err='tsiatis')
|
||||
|
||||
tm = np.r_[1, 3, 5, 6, 7, 8, 8, 9, 3, 4, 1, 3, 2]
|
||||
st = np.r_[1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0]
|
||||
wt = np.r_[1, 2, 3, 2, 3, 1, 2, 1, 1, 2, 2, 3, 1]
|
||||
|
||||
sf = SurvfuncRight(tm, st, freq_weights=wt)
|
||||
assert_allclose(sf.surv_times, np.r_[1, 3, 6, 7, 9])
|
||||
assert_allclose(sf.surv_prob,
|
||||
np.r_[0.875, 0.65625, 0.51041667, 0.29166667, 0.])
|
||||
assert_allclose(sf.surv_prob_se,
|
||||
np.r_[0.07216878, 0.13307266, 0.20591185, 0.3219071,
|
||||
1.05053519])
|
||||
|
||||
|
||||
def test_weights2():
|
||||
# tm = c(1, 3, 5, 6, 7, 2, 4, 6, 8, 10)
|
||||
# st = c(1, 1, 0, 1, 1, 1, 1, 0, 1, 1)
|
||||
# wt = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)
|
||||
# library(survival)
|
||||
# sf =s urvfit(Surv(tm, st) ~ 1, weights=wt, err='tsiatis')
|
||||
|
||||
tm = np.r_[1, 3, 5, 6, 7, 2, 4, 6, 8, 10]
|
||||
st = np.r_[1, 1, 0, 1, 1, 1, 1, 0, 1, 1]
|
||||
wt = np.r_[1, 1, 1, 1, 1, 2, 2, 2, 2, 2]
|
||||
tm0 = np.r_[1, 3, 5, 6, 7, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10]
|
||||
st0 = np.r_[1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1]
|
||||
|
||||
sf0 = SurvfuncRight(tm, st, freq_weights=wt)
|
||||
sf1 = SurvfuncRight(tm0, st0)
|
||||
|
||||
assert_allclose(sf0.surv_times, sf1.surv_times)
|
||||
assert_allclose(sf0.surv_prob, sf1.surv_prob)
|
||||
|
||||
assert_allclose(sf0.surv_prob_se,
|
||||
np.r_[0.06666667, 0.1210311, 0.14694547,
|
||||
0.19524829, 0.23183377,
|
||||
0.30618115, 0.46770386, 0.84778942])
|
||||
|
||||
|
||||
def test_incidence():
|
||||
# Check estimates in R:
|
||||
# ftime = c(1, 1, 2, 4, 4, 4, 6, 6, 7, 8, 9, 9, 9, 1, 2, 2, 4, 4)
|
||||
# fstat = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
# cuminc(ftime, fstat)
|
||||
#
|
||||
# The standard errors agree with Stata, not with R (cmprisk
|
||||
# package), which uses a different SE formula from Aalen (1978)
|
||||
#
|
||||
# To check with Stata:
|
||||
# stset ftime failure(fstat==1)
|
||||
# stcompet ci=ci, compet1(2)
|
||||
|
||||
ftime = np.r_[1, 1, 2, 4, 4, 4, 6, 6, 7, 8, 9, 9, 9, 1, 2, 2, 4, 4]
|
||||
fstat = np.r_[1, 1, 1, 2, 2, 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
|
||||
ci = CumIncidenceRight(ftime, fstat)
|
||||
|
||||
cinc = [np.array([0.11111111, 0.17037037, 0.17037037, 0.17037037,
|
||||
0.17037037, 0.17037037, 0.17037037]),
|
||||
np.array([0., 0., 0.20740741, 0.20740741,
|
||||
0.20740741, 0.20740741, 0.20740741]),
|
||||
np.array([0., 0., 0., 0.17777778,
|
||||
0.26666667, 0.26666667, 0.26666667])]
|
||||
assert_allclose(cinc[0], ci.cinc[0])
|
||||
assert_allclose(cinc[1], ci.cinc[1])
|
||||
assert_allclose(cinc[2], ci.cinc[2])
|
||||
|
||||
cinc_se = [np.array([0.07407407, 0.08976251, 0.08976251, 0.08976251,
|
||||
0.08976251, 0.08976251, 0.08976251]),
|
||||
np.array([0., 0., 0.10610391, 0.10610391, 0.10610391,
|
||||
0.10610391, 0.10610391]),
|
||||
np.array([0., 0., 0., 0.11196147, 0.12787781,
|
||||
0.12787781, 0.12787781])]
|
||||
assert_allclose(cinc_se[0], ci.cinc_se[0])
|
||||
assert_allclose(cinc_se[1], ci.cinc_se[1])
|
||||
assert_allclose(cinc_se[2], ci.cinc_se[2])
|
||||
|
||||
# Simple check for frequency weights
|
||||
weights = np.ones(len(ftime))
|
||||
ciw = CumIncidenceRight(ftime, fstat, freq_weights=weights)
|
||||
assert_allclose(ci.cinc[0], ciw.cinc[0])
|
||||
assert_allclose(ci.cinc[1], ciw.cinc[1])
|
||||
assert_allclose(ci.cinc[2], ciw.cinc[2])
|
||||
|
||||
|
||||
def test_survfunc_entry_1():
|
||||
# times = c(1, 3, 3, 5, 5, 7, 7, 8, 8, 9, 10, 10)
|
||||
# status = c(1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1)
|
||||
# entry = c(0, 1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 0)
|
||||
# sv = Surv(entry, times, event=status)
|
||||
# sdf = survfit(coxph(sv ~ 1), type='kaplan-meier')
|
||||
|
||||
times = np.r_[1, 3, 3, 5, 5, 7, 7, 8, 8, 9, 10, 10]
|
||||
status = np.r_[1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1]
|
||||
entry = np.r_[0, 1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 0]
|
||||
|
||||
sf = SurvfuncRight(times, status, entry=entry)
|
||||
|
||||
assert_allclose(sf.n_risk, np.r_[2, 6, 9, 7, 5, 3, 2])
|
||||
assert_allclose(sf.surv_times, np.r_[1, 3, 5, 7, 8, 9, 10])
|
||||
assert_allclose(sf.surv_prob, np.r_[
|
||||
0.5000, 0.4167, 0.3241, 0.2778, 0.2222, 0.1481, 0.0741],
|
||||
atol=1e-4)
|
||||
assert_allclose(sf.surv_prob_se, np.r_[
|
||||
0.3536, 0.3043, 0.2436, 0.2132, 0.1776, 0.1330, 0.0846],
|
||||
atol=1e-4)
|
||||
|
||||
|
||||
def test_survfunc_entry_2():
|
||||
# entry = 0 is equivalent to no entry time
|
||||
|
||||
times = np.r_[1, 3, 3, 5, 5, 7, 7, 8, 8, 9, 10, 10]
|
||||
status = np.r_[1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1]
|
||||
entry = np.r_[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
|
||||
sf = SurvfuncRight(times, status, entry=entry)
|
||||
sf0 = SurvfuncRight(times, status)
|
||||
|
||||
assert_allclose(sf.n_risk, sf0.n_risk)
|
||||
assert_allclose(sf.surv_times, sf0.surv_times)
|
||||
assert_allclose(sf.surv_prob, sf0.surv_prob)
|
||||
assert_allclose(sf.surv_prob_se, sf0.surv_prob_se)
|
||||
|
||||
|
||||
def test_survfunc_entry_3():
|
||||
# times = c(1, 2, 5, 6, 6, 6, 6, 6, 9)
|
||||
# status = c(0, 0, 1, 1, 1, 0, 1, 1, 0)
|
||||
# entry = c(0, 1, 1, 2, 2, 2, 3, 4, 4)
|
||||
# sv = Surv(entry, times, event=status)
|
||||
# sdf = survfit(coxph(sv ~ 1), type='kaplan-meier')
|
||||
|
||||
times = np.r_[1, 2, 5, 6, 6, 6, 6, 6, 9]
|
||||
status = np.r_[0, 0, 1, 1, 1, 0, 1, 1, 0]
|
||||
entry = np.r_[0, 1, 1, 2, 2, 2, 3, 4, 4]
|
||||
|
||||
sf = SurvfuncRight(times, status, entry=entry)
|
||||
|
||||
assert_allclose(sf.n_risk, np.r_[7, 6])
|
||||
assert_allclose(sf.surv_times, np.r_[5, 6])
|
||||
assert_allclose(sf.surv_prob, np.r_[0.857143, 0.285714], atol=1e-5)
|
||||
assert_allclose(sf.surv_prob_se, np.r_[0.13226, 0.170747], atol=1e-5)
|
||||
|
||||
|
||||
def test_survdiff_entry_1():
|
||||
# entry times = 0 is equivalent to no entry times
|
||||
ti = np.r_[1, 3, 4, 2, 5, 4, 6, 7, 5, 9]
|
||||
st = np.r_[1, 1, 0, 1, 1, 0, 1, 1, 0, 0]
|
||||
gr = np.r_[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
|
||||
entry = np.r_[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
z1, p1 = survdiff(ti, st, gr, entry=entry)
|
||||
z2, p2 = survdiff(ti, st, gr)
|
||||
assert_allclose(z1, z2)
|
||||
assert_allclose(p1, p2)
|
||||
|
||||
|
||||
def test_survdiff_entry_2():
|
||||
# Tests against Stata:
|
||||
#
|
||||
# stset time, failure(status) entry(entry)
|
||||
# sts test group, logrank
|
||||
|
||||
ti = np.r_[5, 3, 4, 2, 5, 4, 6, 7, 5, 9]
|
||||
st = np.r_[1, 1, 0, 1, 1, 0, 1, 1, 0, 0]
|
||||
gr = np.r_[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
|
||||
entry = np.r_[1, 2, 2, 1, 3, 3, 5, 4, 2, 5]
|
||||
|
||||
# Check with no entry times
|
||||
z, p = survdiff(ti, st, gr)
|
||||
assert_allclose(z, 6.694424)
|
||||
assert_allclose(p, 0.00967149)
|
||||
|
||||
# Check with entry times
|
||||
z, p = survdiff(ti, st, gr, entry=entry)
|
||||
assert_allclose(z, 3.0)
|
||||
assert_allclose(p, 0.083264516)
|
||||
|
||||
|
||||
def test_survdiff_entry_3():
|
||||
# Tests against Stata:
|
||||
#
|
||||
# stset time, failure(status) entry(entry)
|
||||
# sts test group, logrank
|
||||
|
||||
ti = np.r_[2, 1, 5, 8, 7, 8, 8, 9, 4, 9]
|
||||
st = np.r_[1, 1, 1, 1, 1, 0, 1, 0, 0, 0]
|
||||
gr = np.r_[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
|
||||
entry = np.r_[1, 1, 2, 2, 3, 3, 2, 1, 2, 0]
|
||||
|
||||
# Check with no entry times
|
||||
z, p = survdiff(ti, st, gr)
|
||||
assert_allclose(z, 6.9543024)
|
||||
assert_allclose(p, 0.008361789)
|
||||
|
||||
# Check with entry times
|
||||
z, p = survdiff(ti, st, gr, entry=entry)
|
||||
assert_allclose(z, 6.75082959)
|
||||
assert_allclose(p, 0.00937041)
|
||||
|
||||
|
||||
def test_incidence2():
|
||||
# Check that the cumulative incidence functions for all competing
|
||||
# risks sum to the complementary survival function.
|
||||
|
||||
np.random.seed(2423)
|
||||
n = 200
|
||||
time = -np.log(np.random.uniform(size=n))
|
||||
status = np.random.randint(0, 3, size=n)
|
||||
ii = np.argsort(time)
|
||||
time = time[ii]
|
||||
status = status[ii]
|
||||
ci = CumIncidenceRight(time, status)
|
||||
statusa = 1*(status >= 1)
|
||||
sf = SurvfuncRight(time, statusa)
|
||||
x = 1 - sf.surv_prob
|
||||
y = (ci.cinc[0] + ci.cinc[1])[np.flatnonzero(statusa)]
|
||||
assert_allclose(x, y)
|
||||
|
||||
|
||||
def test_kernel_survfunc1():
|
||||
# Regression test
|
||||
n = 100
|
||||
np.random.seed(3434)
|
||||
x = np.random.normal(size=(n, 3))
|
||||
time = np.random.uniform(size=n)
|
||||
status = np.random.randint(0, 2, size=n)
|
||||
|
||||
result = SurvfuncRight(time, status, exog=x)
|
||||
|
||||
timex = np.r_[0.30721103, 0.0515439, 0.69246897, 0.16446079, 0.31308528]
|
||||
sprob = np.r_[0.98948277, 0.98162275, 0.97129237, 0.96044668, 0.95030368]
|
||||
|
||||
assert_allclose(result.time[0:5], timex)
|
||||
assert_allclose(result.surv_prob[0:5], sprob)
|
||||
|
||||
|
||||
def test_kernel_survfunc2():
|
||||
# Check that when bandwidth is very large, the kernel procedure
|
||||
# agrees with standard KM. (Note: the results do not agree
|
||||
# perfectly when there are tied times).
|
||||
|
||||
n = 100
|
||||
np.random.seed(3434)
|
||||
x = np.random.normal(size=(n, 3))
|
||||
time = np.random.uniform(0, 10, size=n)
|
||||
status = np.random.randint(0, 2, size=n)
|
||||
|
||||
resultkm = SurvfuncRight(time, status)
|
||||
result = SurvfuncRight(time, status, exog=x, bw_factor=10000)
|
||||
|
||||
assert_allclose(resultkm.surv_times, result.surv_times)
|
||||
assert_allclose(resultkm.surv_prob, result.surv_prob, rtol=1e-6, atol=1e-6)
|
||||
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_kernel_survfunc3():
|
||||
# cases with tied times
|
||||
|
||||
n = 100
|
||||
np.random.seed(3434)
|
||||
x = np.random.normal(size=(n, 3))
|
||||
time = np.random.randint(0, 10, size=n)
|
||||
status = np.random.randint(0, 2, size=n)
|
||||
SurvfuncRight(time, status, exog=x, bw_factor=10000)
|
||||
SurvfuncRight(time, status, exog=x, bw_factor=np.r_[10000, 10000])
|
||||
|
||||
|
||||
def test_kernel_cumincidence1():
|
||||
# Check that when the bandwidth is very large, the kernel
|
||||
# procedure agrees with standard cumulative incidence
|
||||
# calculations. (Note: the results do not agree perfectly when
|
||||
# there are tied times).
|
||||
|
||||
n = 100
|
||||
np.random.seed(3434)
|
||||
x = np.random.normal(size=(n, 3))
|
||||
time = np.random.uniform(0, 10, size=n)
|
||||
status = np.random.randint(0, 3, size=n)
|
||||
|
||||
result1 = CumIncidenceRight(time, status)
|
||||
|
||||
for dimred in False, True:
|
||||
result2 = CumIncidenceRight(time, status, exog=x, bw_factor=10000,
|
||||
dimred=dimred)
|
||||
|
||||
assert_allclose(result1.times, result2.times)
|
||||
for k in 0, 1:
|
||||
assert_allclose(result1.cinc[k], result2.cinc[k], rtol=1e-5)
|
||||
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_kernel_cumincidence2():
|
||||
# cases with tied times
|
||||
|
||||
n = 100
|
||||
np.random.seed(3434)
|
||||
x = np.random.normal(size=(n, 3))
|
||||
time = np.random.randint(0, 10, size=n)
|
||||
status = np.random.randint(0, 3, size=n)
|
||||
CumIncidenceRight(time, status, exog=x, bw_factor=10000)
|
||||
Reference in New Issue
Block a user