Mercurial > repos > fubar > lifelines_km_cph_tool
annotate lifelines_tool/test-data/readme_sample @ 2:dd5e65893cb8 draft default tip
add survival and collapsed life table outputs suggested by Wolfgang
author | fubar |
---|---|
date | Thu, 10 Aug 2023 22:52:45 +0000 |
parents | 232b874046a7 |
children |
rev | line source |
---|---|
2
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
1 ## Lifelines tool |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
2 Input data header = Index(['Unnamed: 0', 'week', 'arrest', 'fin', 'age', 'race', 'wexp', 'mar', |
0 | 3 'paro', 'prio'], |
4 dtype='object') time column = week status column = arrest | |
5 Logrank test for race - 0 vs 1 | |
6 | |
7 <lifelines.StatisticalResult: logrank_test> | |
8 t_0 = -1 | |
9 null_distribution = chi squared | |
10 degrees_of_freedom = 1 | |
11 alpha = 0.99 | |
12 test_name = logrank_test | |
13 | |
14 --- | |
15 test_statistic p -log2(p) | |
16 0.58 0.45 1.16 | |
2
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
17 #### Survival table using time week and event arrest |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
18 removed observed censored entrance at_risk |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
19 event_at |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
20 0.0 0 0 0 432 432 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
21 1.0 1 1 0 0 432 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
22 2.0 1 1 0 0 431 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
23 3.0 1 1 0 0 430 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
24 4.0 1 1 0 0 429 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
25 5.0 1 1 0 0 428 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
26 6.0 1 1 0 0 427 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
27 7.0 1 1 0 0 426 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
28 8.0 5 5 0 0 425 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
29 9.0 2 2 0 0 420 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
30 10.0 1 1 0 0 418 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
31 11.0 2 2 0 0 417 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
32 12.0 2 2 0 0 415 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
33 13.0 1 1 0 0 413 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
34 14.0 3 3 0 0 412 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
35 15.0 2 2 0 0 409 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
36 16.0 2 2 0 0 407 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
37 17.0 3 3 0 0 405 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
38 18.0 3 3 0 0 402 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
39 19.0 2 2 0 0 399 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
40 20.0 5 5 0 0 397 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
41 21.0 2 2 0 0 392 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
42 22.0 1 1 0 0 390 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
43 23.0 1 1 0 0 389 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
44 24.0 4 4 0 0 388 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
45 25.0 3 3 0 0 384 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
46 26.0 3 3 0 0 381 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
47 27.0 2 2 0 0 378 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
48 28.0 2 2 0 0 376 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
49 30.0 2 2 0 0 374 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
50 31.0 1 1 0 0 372 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
51 32.0 2 2 0 0 371 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
52 33.0 2 2 0 0 369 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
53 34.0 2 2 0 0 367 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
54 35.0 4 4 0 0 365 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
55 36.0 3 3 0 0 361 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
56 37.0 4 4 0 0 358 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
57 38.0 1 1 0 0 354 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
58 39.0 2 2 0 0 353 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
59 40.0 4 4 0 0 351 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
60 42.0 2 2 0 0 347 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
61 43.0 4 4 0 0 345 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
62 44.0 2 2 0 0 341 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
63 45.0 2 2 0 0 339 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
64 46.0 4 4 0 0 337 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
65 47.0 1 1 0 0 333 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
66 48.0 2 2 0 0 332 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
67 49.0 5 5 0 0 330 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
68 50.0 3 3 0 0 325 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
69 52.0 322 4 318 0 322 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
70 #### Life table using time week and event arrest |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
71 removed observed censored at_risk |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
72 event_at |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
73 (-0.001, 13.844] 20 20 0 432 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
74 (13.844, 27.687] 36 36 0 412 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
75 (27.687, 41.531] 29 29 0 376 |
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
76 (41.531, 55.374] 347 29 318 347 |
0 | 77 ### Lifelines test of Proportional Hazards results with prio, age, race, paro, mar, fin as covariates on KM and CPH in lifelines test |
78 <lifelines.CoxPHFitter: fitted with 432 total observations, 318 right-censored observations> | |
79 duration col = 'week' | |
80 event col = 'arrest' | |
81 baseline estimation = breslow | |
82 number of observations = 432 | |
83 number of events observed = 114 | |
84 partial log-likelihood = -659.00 | |
2
dd5e65893cb8
add survival and collapsed life table outputs suggested by Wolfgang
fubar
parents:
1
diff
changeset
|
85 time fit was run = 2023-08-10 12:00:14 UTC |
0 | 86 |
87 --- | |
88 coef exp(coef) se(coef) coef lower 95% coef upper 95% exp(coef) lower 95% exp(coef) upper 95% | |
89 covariate | |
90 prio 0.10 1.10 0.03 0.04 0.15 1.04 1.16 | |
91 age -0.06 0.94 0.02 -0.10 -0.02 0.90 0.98 | |
92 race 0.32 1.38 0.31 -0.28 0.92 0.75 2.52 | |
93 paro -0.09 0.91 0.20 -0.47 0.29 0.62 1.34 | |
94 mar -0.48 0.62 0.38 -1.22 0.25 0.30 1.29 | |
95 fin -0.38 0.68 0.19 -0.75 -0.00 0.47 1.00 | |
96 | |
97 cmp to z p -log2(p) | |
98 covariate | |
99 prio 0.00 3.53 <0.005 11.26 | |
100 age 0.00 -2.95 <0.005 8.28 | |
101 race 0.00 1.04 0.30 1.75 | |
102 paro 0.00 -0.46 0.65 0.63 | |
103 mar 0.00 -1.28 0.20 2.32 | |
104 fin 0.00 -1.98 0.05 4.40 | |
105 --- | |
106 Concordance = 0.63 | |
107 Partial AIC = 1330.00 | |
108 log-likelihood ratio test = 32.77 on 6 df | |
109 -log2(p) of ll-ratio test = 16.39 | |
110 | |
111 | |
112 Bootstrapping lowess lines. May take a moment... | |
113 | |
114 | |
115 Bootstrapping lowess lines. May take a moment... | |
116 | |
117 The ``p_value_threshold`` is set at 0.01. Even under the null hypothesis of no violations, some | |
118 covariates will be below the threshold by chance. This is compounded when there are many covariates. | |
119 Similarly, when there are lots of observations, even minor deviances from the proportional hazard | |
120 assumption will be flagged. | |
121 | |
122 With that in mind, it's best to use a combination of statistical tests and visual tests to determine | |
123 the most serious violations. Produce visual plots using ``check_assumptions(..., show_plots=True)`` | |
124 and looking for non-constant lines. See link [A] below for a full example. | |
125 | |
126 <lifelines.StatisticalResult: proportional_hazard_test> | |
127 null_distribution = chi squared | |
128 degrees_of_freedom = 1 | |
129 model = <lifelines.CoxPHFitter: fitted with 432 total observations, 318 right-censored observations> | |
130 test_name = proportional_hazard_test | |
131 | |
132 --- | |
133 test_statistic p -log2(p) | |
134 age km 6.99 0.01 6.93 | |
135 rank 7.40 0.01 7.26 | |
136 fin km 0.02 0.90 0.15 | |
137 rank 0.01 0.91 0.13 | |
138 mar km 1.64 0.20 2.32 | |
139 rank 1.80 0.18 2.48 | |
140 paro km 0.06 0.81 0.31 | |
141 rank 0.07 0.79 0.34 | |
142 prio km 0.92 0.34 1.57 | |
143 rank 0.88 0.35 1.52 | |
144 race km 1.70 0.19 2.38 | |
145 rank 1.68 0.19 2.36 | |
146 | |
147 | |
148 1. Variable 'age' failed the non-proportional test: p-value is 0.0065. | |
149 | |
150 Advice 1: the functional form of the variable 'age' might be incorrect. That is, there may be | |
151 non-linear terms missing. The proportional hazard test used is very sensitive to incorrect | |
152 functional forms. See documentation in link [D] below on how to specify a functional form. | |
153 | |
154 Advice 2: try binning the variable 'age' using pd.cut, and then specify it in `strata=['age', | |
155 ...]` in the call in `.fit`. See documentation in link [B] below. | |
156 | |
157 Advice 3: try adding an interaction term with your time variable. See documentation in link [C] | |
158 below. | |
159 | |
160 | |
161 Bootstrapping lowess lines. May take a moment... | |
162 | |
163 | |
164 Bootstrapping lowess lines. May take a moment... | |
165 | |
166 | |
167 Bootstrapping lowess lines. May take a moment... | |
168 | |
169 | |
170 Bootstrapping lowess lines. May take a moment... | |
171 | |
172 | |
173 --- | |
174 [A] https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Proportional%20hazard%20assumption.html | |
175 [B] https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Proportional%20hazard%20assumption.html#Bin-variable-and-stratify-on-it | |
176 [C] https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Proportional%20hazard%20assumption.html#Introduce-time-varying-covariates | |
177 [D] https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Proportional%20hazard%20assumption.html#Modify-the-functional-form | |
178 [E] https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Proportional%20hazard%20assumption.html#Stratification | |
179 |