meta-edc 1.0.7__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- meta_ae/action_items.py +10 -2
- meta_ae/baker_recipes.py +1 -2
- meta_ae/tests/tests/test_actions.py +1 -2
- meta_analytics/README.rst +1 -2
- meta_analytics/notebooks/anu.ipynb +95 -0
- meta_analytics/notebooks/appointment_planning.ipynb +329 -0
- meta_analytics/notebooks/arvs.ipynb +103 -0
- meta_analytics/notebooks/cleaning/consent_v1_ext.ipynb +227 -0
- meta_analytics/notebooks/cleaning/offschedule_eos.ipynb +353 -0
- meta_analytics/notebooks/dsmc/renal_dysfunction.ipynb +435 -0
- meta_analytics/notebooks/endpoints/meta_endpoints_by_date.ipynb +664 -0
- meta_analytics/notebooks/followup_examination.ipynb +141 -0
- meta_analytics/notebooks/hba1c.ipynb +136 -0
- meta_analytics/notebooks/hiv_regimens.ipynb +122 -118
- meta_analytics/notebooks/incidence.ipynb +232 -0
- meta_analytics/notebooks/liver.ipynb +389 -0
- meta_analytics/notebooks/magreth.ipynb +645 -0
- meta_analytics/notebooks/monitoring_report.ipynb +721 -448
- meta_analytics/notebooks/pharmacy.ipynb +405 -306
- meta_analytics/notebooks/pharmacy_stock_202410.ipynb +306 -0
- meta_analytics/notebooks/steering.ipynb +61 -0
- meta_analytics/notebooks/undiagnosed/meta3_screening_consort_chart.ipynb +1176 -0
- meta_analytics/notebooks/undiagnosed/meta3_screening_undiagnosed.ipynb +519 -0
- meta_analytics/notebooks/undiagnosed/meta_screening_table2.ipynb +964 -0
- meta_analytics/notebooks/undiagnosed/screen_undiagnosed_or.ipynb +296 -0
- meta_analytics/notebooks/undiagnosed/screening.ipynb +273 -0
- meta_analytics/notebooks/undiagnosed/screening2.ipynb +958 -0
- meta_analytics/notebooks/undiagnosed/screening_undiagnosed_20241002.ipynb +958 -0
- meta_analytics/notebooks/ven.ipynb +191 -0
- meta_analytics/notebooks/vitals.ipynb +263 -0
- meta_edc/settings/debug.py +3 -2
- meta_edc/urls.py +1 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/METADATA +3 -3
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/RECORD +62 -35
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/WHEEL +1 -1
- meta_labs/reportables.py +14 -11
- meta_labs/tests/test_reportables.py +33 -12
- meta_pharmacy/notebooks/pharmacy.ipynb +41 -0
- meta_prn/admin/offschedule_pregnancy_admin.py +3 -3
- meta_prn/admin/onschedule_dm_referral_admin.py +5 -5
- meta_prn/form_validators/end_of_study.py +2 -2
- meta_prn/migrations/0063_historicaloffstudymedication_singleton_field_and_more.py +37 -0
- meta_prn/migrations/0064_auto_20250602_2143.py +18 -0
- meta_prn/models/end_of_study.py +2 -0
- meta_prn/models/off_study_medication.py +2 -0
- meta_reports/admin/last_imp_refill_admin.py +3 -2
- meta_screening/eligibility/eligibility_part_three/base_eligibility_part_three.py +59 -47
- meta_screening/form_validators/screening_part_three.py +6 -1
- meta_screening/tests/meta_test_case_mixin.py +3 -0
- meta_screening/tests/tests/test_forms.py +9 -2
- meta_screening/tests/tests/test_screening_part_three.py +11 -14
- meta_subject/action_items.py +2 -3
- meta_subject/choices.py +2 -1
- meta_subject/form_validators/delivery_form_validator.py +1 -0
- meta_subject/forms/blood_results/blood_results_rft_form.py +60 -3
- meta_subject/forms/delivery_form.py +2 -0
- meta_subject/migrations/0223_bloodresultsfbc_errors_bloodresultsgludummy_errors_and_more.py +83 -0
- meta_subject/migrations/0224_bloodresultsfbc_abnormal_summary_and_more.py +153 -0
- meta_subject/tests/tests/test_egfr.py +5 -5
- meta_analytics/dataframes/enrolled/__init__.py +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/licenses/AUTHORS.rst +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/licenses/LICENSE +0 -0
- {meta_edc-1.0.7.dist-info → meta_edc-1.1.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,958 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "0",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"%%capture\n",
|
11
|
+
"# output is suppressed but normally would spew out all the edc loading messages\n",
|
12
|
+
"\n",
|
13
|
+
"import os\n",
|
14
|
+
"from pathlib import Path\n",
|
15
|
+
"from datetime import datetime\n",
|
16
|
+
"import pandas as pd\n",
|
17
|
+
"import numpy as np\n",
|
18
|
+
"import math\n",
|
19
|
+
"# import matplotlxib.pyplot as plt\n",
|
20
|
+
"# import seaborn as sns\n",
|
21
|
+
"import scipy.stats as stats\n",
|
22
|
+
"\n",
|
23
|
+
"from dj_notebook import activate\n",
|
24
|
+
"\n",
|
25
|
+
"env_file = os.environ[\"META_ENV\"]\n",
|
26
|
+
"documents_folder = os.environ[\"META_DOCUMENTS_FOLDER\"]\n",
|
27
|
+
"report_folder = Path(documents_folder)\n",
|
28
|
+
"\n",
|
29
|
+
"plus = activate(dotenv_file=env_file)\n"
|
30
|
+
]
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"cell_type": "code",
|
34
|
+
"execution_count": null,
|
35
|
+
"id": "1",
|
36
|
+
"metadata": {},
|
37
|
+
"outputs": [],
|
38
|
+
"source": [
|
39
|
+
"import itertools\n",
|
40
|
+
"from meta_analytics.dataframes import GlucoseEndpointsByDate, get_eos_df, get_screening_df\n",
|
41
|
+
"from meta_analytics.dataframes.screening import get_glucose_tested_only_df\n"
|
42
|
+
]
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"cell_type": "code",
|
46
|
+
"execution_count": null,
|
47
|
+
"id": "2",
|
48
|
+
"metadata": {},
|
49
|
+
"outputs": [],
|
50
|
+
"source": [
|
51
|
+
"\n",
|
52
|
+
"df = get_screening_df()\n"
|
53
|
+
]
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"cell_type": "code",
|
57
|
+
"execution_count": null,
|
58
|
+
"id": "3",
|
59
|
+
"metadata": {},
|
60
|
+
"outputs": [],
|
61
|
+
"source": [
|
62
|
+
"# unwilling to stay or not living nearby\n",
|
63
|
+
"df[(df[\"reasons_ineligible_part_one\"].str.contains(\"nearby\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"ART\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"VL\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"Pregnant\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"META\", na=False))].reasons_ineligible_part_one.value_counts(dropna=False)\n"
|
64
|
+
]
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"cell_type": "code",
|
68
|
+
"execution_count": null,
|
69
|
+
"id": "4",
|
70
|
+
"metadata": {},
|
71
|
+
"outputs": [],
|
72
|
+
"source": [
|
73
|
+
"df[(df[\"reasons_ineligible_part_one\"].str.contains(\"nearby\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"ART\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"VL\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"Pregnant\", na=False)) & (~df[\"reasons_ineligible_part_one\"].str.contains(\"META\", na=False))].reasons_ineligible_part_one.count()"
|
74
|
+
]
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"cell_type": "code",
|
78
|
+
"execution_count": null,
|
79
|
+
"id": "5",
|
80
|
+
"metadata": {},
|
81
|
+
"outputs": [],
|
82
|
+
"source": [
|
83
|
+
"df[\n",
|
84
|
+
"(df[\"reasons_ineligible_part_one\"].str.contains(\"ART\", na=False)) & \n",
|
85
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"VL\", na=False)) & \n",
|
86
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"Pregnant\", na=False)) & \n",
|
87
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"META\", na=False))\n",
|
88
|
+
"].reasons_ineligible_part_one.count()"
|
89
|
+
]
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"cell_type": "code",
|
93
|
+
"execution_count": null,
|
94
|
+
"id": "6",
|
95
|
+
"metadata": {},
|
96
|
+
"outputs": [],
|
97
|
+
"source": [
|
98
|
+
"# VL not suppressed or not measured within last 6-12\n",
|
99
|
+
"df[\n",
|
100
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"ART\", na=False)) & \n",
|
101
|
+
"(df[\"reasons_ineligible_part_one\"].str.contains(\"VL\", na=False)) & \n",
|
102
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"Pregnant\", na=False)) & \n",
|
103
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"META\", na=False))\n",
|
104
|
+
"].reasons_ineligible_part_one.count()"
|
105
|
+
]
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"cell_type": "code",
|
109
|
+
"execution_count": null,
|
110
|
+
"id": "7",
|
111
|
+
"metadata": {},
|
112
|
+
"outputs": [],
|
113
|
+
"source": [
|
114
|
+
"# pregnant (unconfirmed)\n",
|
115
|
+
"df[\n",
|
116
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"ART\", na=False)) & \n",
|
117
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"VL\", na=False)) & \n",
|
118
|
+
"(df[\"reasons_ineligible_part_one\"].str.contains(\"Pregnant\", na=False)) & \n",
|
119
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"META\", na=False))\n",
|
120
|
+
"].reasons_ineligible_part_one.counts()"
|
121
|
+
]
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"cell_type": "code",
|
125
|
+
"execution_count": null,
|
126
|
+
"id": "8",
|
127
|
+
"metadata": {},
|
128
|
+
"outputs": [],
|
129
|
+
"source": [
|
130
|
+
"# META 2 participant\n",
|
131
|
+
"df[\n",
|
132
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"ART\", na=False)) & \n",
|
133
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"VL\", na=False)) & \n",
|
134
|
+
"(~df[\"reasons_ineligible_part_one\"].str.contains(\"Pregnant\", na=False)) & \n",
|
135
|
+
"(df[\"reasons_ineligible_part_one\"].str.contains(\"META\", na=False))\n",
|
136
|
+
"].reasons_ineligible_part_one.count()"
|
137
|
+
]
|
138
|
+
},
|
139
|
+
{
|
140
|
+
"cell_type": "code",
|
141
|
+
"execution_count": null,
|
142
|
+
"id": "9",
|
143
|
+
"metadata": {},
|
144
|
+
"outputs": [],
|
145
|
+
"source": [
|
146
|
+
"prods = list(itertools.product([\"Yes\", \"No\", \"tbd\"], repeat=3))\n",
|
147
|
+
"dfs = []\n",
|
148
|
+
"for p in prods:\n",
|
149
|
+
" if p[0] == \"tbd\":\n",
|
150
|
+
" continue\n",
|
151
|
+
" dfs.append(\n",
|
152
|
+
" pd.DataFrame([[\n",
|
153
|
+
" p[0], \n",
|
154
|
+
" p[1],\n",
|
155
|
+
" p[2],\n",
|
156
|
+
" df[\n",
|
157
|
+
" (df.eligible_part_one==p[0]) & \n",
|
158
|
+
" (df.eligible_part_two==p[1]) &\n",
|
159
|
+
" (df.eligible_part_three==p[2])\n",
|
160
|
+
" ].eligible_part_three.count()]],\n",
|
161
|
+
" columns=[\"p1\", \"p2\", \"p3\", \"count\"]))\n",
|
162
|
+
"\n",
|
163
|
+
"df_eligibility = pd.concat(dfs, ignore_index=True)\n",
|
164
|
+
"df_eligibility"
|
165
|
+
]
|
166
|
+
},
|
167
|
+
{
|
168
|
+
"cell_type": "code",
|
169
|
+
"execution_count": null,
|
170
|
+
"id": "10",
|
171
|
+
"metadata": {},
|
172
|
+
"outputs": [],
|
173
|
+
"source": []
|
174
|
+
},
|
175
|
+
{
|
176
|
+
"cell_type": "code",
|
177
|
+
"execution_count": null,
|
178
|
+
"id": "11",
|
179
|
+
"metadata": {},
|
180
|
+
"outputs": [],
|
181
|
+
"source": [
|
182
|
+
"# assessed part one only\n",
|
183
|
+
"p1 = df_eligibility[df_eligibility.p2.isin([\"tbd\"])][\"count\"].sum()\n",
|
184
|
+
"p1"
|
185
|
+
]
|
186
|
+
},
|
187
|
+
{
|
188
|
+
"cell_type": "code",
|
189
|
+
"execution_count": null,
|
190
|
+
"id": "12",
|
191
|
+
"metadata": {},
|
192
|
+
"outputs": [],
|
193
|
+
"source": [
|
194
|
+
"# assessed part one and part two\n",
|
195
|
+
"p12 = df_eligibility[\n",
|
196
|
+
" (df_eligibility.p1.isin([\"Yes\", \"No\"])) & \n",
|
197
|
+
" (df_eligibility.p2.isin([\"Yes\", \"No\"])) & \n",
|
198
|
+
" (df_eligibility.p3 == \"tbd\")\n",
|
199
|
+
"][\"count\"].sum()\n",
|
200
|
+
"p12"
|
201
|
+
]
|
202
|
+
},
|
203
|
+
{
|
204
|
+
"cell_type": "code",
|
205
|
+
"execution_count": null,
|
206
|
+
"id": "13",
|
207
|
+
"metadata": {},
|
208
|
+
"outputs": [],
|
209
|
+
"source": [
|
210
|
+
"# assessed part one, part two, part three\n",
|
211
|
+
"p123 = df_eligibility[\n",
|
212
|
+
" (df_eligibility.p1.isin([\"Yes\", \"No\"])) & \n",
|
213
|
+
" (df_eligibility.p2.isin([\"Yes\", \"No\"])) & \n",
|
214
|
+
" (df_eligibility.p3 != \"tbd\")\n",
|
215
|
+
"][\"count\"].sum()\n",
|
216
|
+
"p123"
|
217
|
+
]
|
218
|
+
},
|
219
|
+
{
|
220
|
+
"cell_type": "code",
|
221
|
+
"execution_count": null,
|
222
|
+
"id": "14",
|
223
|
+
"metadata": {},
|
224
|
+
"outputs": [],
|
225
|
+
"source": [
|
226
|
+
"assert p1+p12+p123 == 10574"
|
227
|
+
]
|
228
|
+
},
|
229
|
+
{
|
230
|
+
"cell_type": "code",
|
231
|
+
"execution_count": null,
|
232
|
+
"id": "15",
|
233
|
+
"metadata": {},
|
234
|
+
"outputs": [],
|
235
|
+
"source": [
|
236
|
+
"p12 + p123"
|
237
|
+
]
|
238
|
+
},
|
239
|
+
{
|
240
|
+
"cell_type": "code",
|
241
|
+
"execution_count": null,
|
242
|
+
"id": "16",
|
243
|
+
"metadata": {},
|
244
|
+
"outputs": [],
|
245
|
+
"source": [
|
246
|
+
"cond = (df[\"eligible_part_one\"] == \"Yes\") \n",
|
247
|
+
"df[cond].count()"
|
248
|
+
]
|
249
|
+
},
|
250
|
+
{
|
251
|
+
"cell_type": "code",
|
252
|
+
"execution_count": null,
|
253
|
+
"id": "17",
|
254
|
+
"metadata": {},
|
255
|
+
"outputs": [],
|
256
|
+
"source": [
|
257
|
+
"# 9706 evaluated for part one and two\n",
|
258
|
+
"cond = (df[\"eligible_part_one\"].isin([\"Yes\", \"No\"])) & (df[\"eligible_part_two\"].isin([\"Yes\", \"No\"]))\n",
|
259
|
+
"df[cond].count()"
|
260
|
+
]
|
261
|
+
},
|
262
|
+
{
|
263
|
+
"cell_type": "code",
|
264
|
+
"execution_count": null,
|
265
|
+
"id": "18",
|
266
|
+
"metadata": {},
|
267
|
+
"outputs": [],
|
268
|
+
"source": []
|
269
|
+
},
|
270
|
+
{
|
271
|
+
"cell_type": "code",
|
272
|
+
"execution_count": null,
|
273
|
+
"id": "19",
|
274
|
+
"metadata": {},
|
275
|
+
"outputs": [],
|
276
|
+
"source": []
|
277
|
+
},
|
278
|
+
{
|
279
|
+
"cell_type": "code",
|
280
|
+
"execution_count": null,
|
281
|
+
"id": "20",
|
282
|
+
"metadata": {},
|
283
|
+
"outputs": [],
|
284
|
+
"source": []
|
285
|
+
},
|
286
|
+
{
|
287
|
+
"cell_type": "code",
|
288
|
+
"execution_count": null,
|
289
|
+
"id": "21",
|
290
|
+
"metadata": {},
|
291
|
+
"outputs": [],
|
292
|
+
"source": [
|
293
|
+
"# 9706 evaluated for part one and two\n",
|
294
|
+
"cond = (df[\"eligible_part_one\"].isin([\"Yes\", \"No\"])) & (df[\"eligible_part_two\"].isin([\"Yes\", \"No\"]))\n",
|
295
|
+
"df[cond].eligible_part_three.value_counts()\n",
|
296
|
+
"\n"
|
297
|
+
]
|
298
|
+
},
|
299
|
+
{
|
300
|
+
"cell_type": "code",
|
301
|
+
"execution_count": null,
|
302
|
+
"id": "22",
|
303
|
+
"metadata": {},
|
304
|
+
"outputs": [],
|
305
|
+
"source": []
|
306
|
+
},
|
307
|
+
{
|
308
|
+
"cell_type": "code",
|
309
|
+
"execution_count": null,
|
310
|
+
"id": "23",
|
311
|
+
"metadata": {},
|
312
|
+
"outputs": [],
|
313
|
+
"source": []
|
314
|
+
},
|
315
|
+
{
|
316
|
+
"cell_type": "code",
|
317
|
+
"execution_count": null,
|
318
|
+
"id": "24",
|
319
|
+
"metadata": {},
|
320
|
+
"outputs": [],
|
321
|
+
"source": [
|
322
|
+
"df_glu = get_glucose_tested_only_df()"
|
323
|
+
]
|
324
|
+
},
|
325
|
+
{
|
326
|
+
"cell_type": "code",
|
327
|
+
"execution_count": null,
|
328
|
+
"id": "25",
|
329
|
+
"metadata": {},
|
330
|
+
"outputs": [],
|
331
|
+
"source": [
|
332
|
+
"df_glu.eligible_part_three.value_counts()\n"
|
333
|
+
]
|
334
|
+
},
|
335
|
+
{
|
336
|
+
"cell_type": "code",
|
337
|
+
"execution_count": null,
|
338
|
+
"id": "26",
|
339
|
+
"metadata": {},
|
340
|
+
"outputs": [],
|
341
|
+
"source": [
|
342
|
+
"cond = (df[\"eligible_part_one\"].isin([\"Yes\"])) & (df[\"eligible_part_two\"].isin([\"Yes\"]))\n",
|
343
|
+
"df[cond].agree_to_p3.value_counts()"
|
344
|
+
]
|
345
|
+
},
|
346
|
+
{
|
347
|
+
"cell_type": "code",
|
348
|
+
"execution_count": null,
|
349
|
+
"id": "27",
|
350
|
+
"metadata": {},
|
351
|
+
"outputs": [],
|
352
|
+
"source": [
|
353
|
+
"df_glu.gender.value_counts()"
|
354
|
+
]
|
355
|
+
},
|
356
|
+
{
|
357
|
+
"cell_type": "code",
|
358
|
+
"execution_count": null,
|
359
|
+
"id": "28",
|
360
|
+
"metadata": {},
|
361
|
+
"outputs": [],
|
362
|
+
"source": [
|
363
|
+
"df_glu = df_glu.set_index(\"screening_identifier\")"
|
364
|
+
]
|
365
|
+
},
|
366
|
+
{
|
367
|
+
"cell_type": "code",
|
368
|
+
"execution_count": null,
|
369
|
+
"id": "29",
|
370
|
+
"metadata": {},
|
371
|
+
"outputs": [],
|
372
|
+
"source": [
|
373
|
+
"cond = (df[\"eligible_part_one\"].isin([\"Yes\", \"No\"])) & (df[\"eligible_part_two\"].isin([\"Yes\", \"No\"]) & (df[\"has_dm\"]==\"No\"))\n",
|
374
|
+
"df[cond].eligible_part_three.count()\n"
|
375
|
+
]
|
376
|
+
},
|
377
|
+
{
|
378
|
+
"cell_type": "code",
|
379
|
+
"execution_count": null,
|
380
|
+
"id": "30",
|
381
|
+
"metadata": {},
|
382
|
+
"outputs": [],
|
383
|
+
"source": [
|
384
|
+
"df2 = df[cond].copy()\n",
|
385
|
+
"df2 = df2.reset_index(drop=True)\n",
|
386
|
+
"df2 = df2.set_index(\"screening_identifier\")\n",
|
387
|
+
"df2.count()"
|
388
|
+
]
|
389
|
+
},
|
390
|
+
{
|
391
|
+
"cell_type": "code",
|
392
|
+
"execution_count": null,
|
393
|
+
"id": "31",
|
394
|
+
"metadata": {},
|
395
|
+
"outputs": [],
|
396
|
+
"source": [
|
397
|
+
"df2 = df2.drop(index=df_glu.index)"
|
398
|
+
]
|
399
|
+
},
|
400
|
+
{
|
401
|
+
"cell_type": "code",
|
402
|
+
"execution_count": null,
|
403
|
+
"id": "32",
|
404
|
+
"metadata": {},
|
405
|
+
"outputs": [],
|
406
|
+
"source": [
|
407
|
+
"df2.count()"
|
408
|
+
]
|
409
|
+
},
|
410
|
+
{
|
411
|
+
"cell_type": "code",
|
412
|
+
"execution_count": null,
|
413
|
+
"id": "33",
|
414
|
+
"metadata": {},
|
415
|
+
"outputs": [],
|
416
|
+
"source": [
|
417
|
+
"df2.gender.value_counts()"
|
418
|
+
]
|
419
|
+
},
|
420
|
+
{
|
421
|
+
"cell_type": "code",
|
422
|
+
"execution_count": null,
|
423
|
+
"id": "34",
|
424
|
+
"metadata": {},
|
425
|
+
"outputs": [],
|
426
|
+
"source": [
|
427
|
+
"df2[df2[\"gender\"] == \"F\"].age_in_years.describe()"
|
428
|
+
]
|
429
|
+
},
|
430
|
+
{
|
431
|
+
"cell_type": "code",
|
432
|
+
"execution_count": null,
|
433
|
+
"id": "35",
|
434
|
+
"metadata": {},
|
435
|
+
"outputs": [],
|
436
|
+
"source": [
|
437
|
+
"df_glu[df_glu[\"gender\"] == \"F\"].age_in_years.describe()"
|
438
|
+
]
|
439
|
+
},
|
440
|
+
{
|
441
|
+
"cell_type": "code",
|
442
|
+
"execution_count": null,
|
443
|
+
"id": "36",
|
444
|
+
"metadata": {},
|
445
|
+
"outputs": [],
|
446
|
+
"source": [
|
447
|
+
"df_glu.age_in_years.describe()"
|
448
|
+
]
|
449
|
+
},
|
450
|
+
{
|
451
|
+
"cell_type": "code",
|
452
|
+
"execution_count": null,
|
453
|
+
"id": "37",
|
454
|
+
"metadata": {},
|
455
|
+
"outputs": [],
|
456
|
+
"source": [
|
457
|
+
"df_glu[df_glu[\"gender\"] == \"M\"].age_in_years.describe()"
|
458
|
+
]
|
459
|
+
},
|
460
|
+
{
|
461
|
+
"cell_type": "code",
|
462
|
+
"execution_count": null,
|
463
|
+
"id": "38",
|
464
|
+
"metadata": {},
|
465
|
+
"outputs": [],
|
466
|
+
"source": [
|
467
|
+
"import scipy.stats as stats\n",
|
468
|
+
"df_glu[(df_glu[\"gender\"] == \"F\")].count()"
|
469
|
+
]
|
470
|
+
},
|
471
|
+
{
|
472
|
+
"cell_type": "code",
|
473
|
+
"execution_count": null,
|
474
|
+
"id": "39",
|
475
|
+
"metadata": {},
|
476
|
+
"outputs": [],
|
477
|
+
"source": [
|
478
|
+
"cond_fasting = (df_glu.fasting == \"Yes\") & (df_glu.fasting_fbg_hrs >= 8.0)\n",
|
479
|
+
"cond_f = (df_glu[\"gender\"] == \"F\")\n",
|
480
|
+
"cond_m = (df_glu[\"gender\"] == \"M\")\n",
|
481
|
+
"\n",
|
482
|
+
"df_glu[(df_glu.fasting == \"Yes\") & (df_glu.fasting_fbg_hrs >= 8.0)].gender.value_counts()"
|
483
|
+
]
|
484
|
+
},
|
485
|
+
{
|
486
|
+
"cell_type": "code",
|
487
|
+
"execution_count": null,
|
488
|
+
"id": "40",
|
489
|
+
"metadata": {},
|
490
|
+
"outputs": [],
|
491
|
+
"source": [
|
492
|
+
"df_glu[cond_fasting & cond_f].count()\n",
|
493
|
+
"df_glu[cond_fasting & cond_f & (df_glu.ogtt.notna())].count()"
|
494
|
+
]
|
495
|
+
},
|
496
|
+
{
|
497
|
+
"cell_type": "code",
|
498
|
+
"execution_count": null,
|
499
|
+
"id": "41",
|
500
|
+
"metadata": {},
|
501
|
+
"outputs": [],
|
502
|
+
"source": []
|
503
|
+
},
|
504
|
+
{
|
505
|
+
"cell_type": "code",
|
506
|
+
"execution_count": null,
|
507
|
+
"id": "42",
|
508
|
+
"metadata": {},
|
509
|
+
"outputs": [],
|
510
|
+
"source": [
|
511
|
+
"df_glu[\"fbg_threshold\"] = df_glu[cond_fasting].fbg >= 7.0\n",
|
512
|
+
"df_glu[\"ogtt_threshold\"] = df_glu[cond_fasting].ogtt >= 11.1\n"
|
513
|
+
]
|
514
|
+
},
|
515
|
+
{
|
516
|
+
"cell_type": "code",
|
517
|
+
"execution_count": null,
|
518
|
+
"id": "43",
|
519
|
+
"metadata": {},
|
520
|
+
"outputs": [],
|
521
|
+
"source": [
|
522
|
+
"df_glu_female = df_glu[cond_f & cond_fasting][[\"fbg_threshold\", \"ogtt_threshold\"]].value_counts().to_frame().reset_index()"
|
523
|
+
]
|
524
|
+
},
|
525
|
+
{
|
526
|
+
"cell_type": "code",
|
527
|
+
"execution_count": null,
|
528
|
+
"id": "44",
|
529
|
+
"metadata": {},
|
530
|
+
"outputs": [],
|
531
|
+
"source": [
|
532
|
+
"assert df_glu_female[\"count\"].sum() == 4201"
|
533
|
+
]
|
534
|
+
},
|
535
|
+
{
|
536
|
+
"cell_type": "code",
|
537
|
+
"execution_count": null,
|
538
|
+
"id": "45",
|
539
|
+
"metadata": {},
|
540
|
+
"outputs": [],
|
541
|
+
"source": [
|
542
|
+
"assert df_glu_female[df_glu_female.fbg_threshold == True][\"count\"].sum() == 534"
|
543
|
+
]
|
544
|
+
},
|
545
|
+
{
|
546
|
+
"cell_type": "code",
|
547
|
+
"execution_count": null,
|
548
|
+
"id": "46",
|
549
|
+
"metadata": {},
|
550
|
+
"outputs": [],
|
551
|
+
"source": [
|
552
|
+
"assert df_glu_female[df_glu_female.ogtt_threshold == True][\"count\"].sum() == 148"
|
553
|
+
]
|
554
|
+
},
|
555
|
+
{
|
556
|
+
"cell_type": "code",
|
557
|
+
"execution_count": null,
|
558
|
+
"id": "47",
|
559
|
+
"metadata": {},
|
560
|
+
"outputs": [],
|
561
|
+
"source": [
|
562
|
+
"assert df_glu[cond_f & cond_fasting & (df_glu.fbg >= 7.0)][\"gender\"].count() == 534\n",
|
563
|
+
"assert df_glu_female[df_glu_female.fbg_threshold == True][\"count\"].sum() == 534"
|
564
|
+
]
|
565
|
+
},
|
566
|
+
{
|
567
|
+
"cell_type": "code",
|
568
|
+
"execution_count": null,
|
569
|
+
"id": "48",
|
570
|
+
"metadata": {},
|
571
|
+
"outputs": [],
|
572
|
+
"source": []
|
573
|
+
},
|
574
|
+
{
|
575
|
+
"cell_type": "code",
|
576
|
+
"execution_count": null,
|
577
|
+
"id": "49",
|
578
|
+
"metadata": {},
|
579
|
+
"outputs": [],
|
580
|
+
"source": []
|
581
|
+
},
|
582
|
+
{
|
583
|
+
"cell_type": "code",
|
584
|
+
"execution_count": null,
|
585
|
+
"id": "50",
|
586
|
+
"metadata": {},
|
587
|
+
"outputs": [],
|
588
|
+
"source": []
|
589
|
+
},
|
590
|
+
{
|
591
|
+
"cell_type": "code",
|
592
|
+
"execution_count": null,
|
593
|
+
"id": "51",
|
594
|
+
"metadata": {},
|
595
|
+
"outputs": [],
|
596
|
+
"source": []
|
597
|
+
},
|
598
|
+
{
|
599
|
+
"cell_type": "code",
|
600
|
+
"execution_count": null,
|
601
|
+
"id": "52",
|
602
|
+
"metadata": {},
|
603
|
+
"outputs": [],
|
604
|
+
"source": []
|
605
|
+
},
|
606
|
+
{
|
607
|
+
"cell_type": "code",
|
608
|
+
"execution_count": null,
|
609
|
+
"id": "53",
|
610
|
+
"metadata": {},
|
611
|
+
"outputs": [],
|
612
|
+
"source": [
|
613
|
+
"# men fbg\n",
|
614
|
+
"df_glu[cond_m & cond_fasting][[\"fbg\", \"ogtt\"]].count()"
|
615
|
+
]
|
616
|
+
},
|
617
|
+
{
|
618
|
+
"cell_type": "code",
|
619
|
+
"execution_count": null,
|
620
|
+
"id": "54",
|
621
|
+
"metadata": {},
|
622
|
+
"outputs": [],
|
623
|
+
"source": [
|
624
|
+
"# men fbg\n",
|
625
|
+
"assert df_glu[cond_m & cond_fasting & (df_glu.fbg >= 7.0)][\"gender\"].count() == 194"
|
626
|
+
]
|
627
|
+
},
|
628
|
+
{
|
629
|
+
"cell_type": "code",
|
630
|
+
"execution_count": null,
|
631
|
+
"id": "55",
|
632
|
+
"metadata": {},
|
633
|
+
"outputs": [],
|
634
|
+
"source": [
|
635
|
+
"# men fbg\n",
|
636
|
+
"194/1414"
|
637
|
+
]
|
638
|
+
},
|
639
|
+
{
|
640
|
+
"cell_type": "code",
|
641
|
+
"execution_count": null,
|
642
|
+
"id": "56",
|
643
|
+
"metadata": {},
|
644
|
+
"outputs": [],
|
645
|
+
"source": [
|
646
|
+
"# men ogtt\n",
|
647
|
+
"assert df_glu[cond_m & cond_fasting & (df_glu.ogtt >= 11.1)][\"gender\"].count() == 76"
|
648
|
+
]
|
649
|
+
},
|
650
|
+
{
|
651
|
+
"cell_type": "code",
|
652
|
+
"execution_count": null,
|
653
|
+
"id": "57",
|
654
|
+
"metadata": {},
|
655
|
+
"outputs": [],
|
656
|
+
"source": [
|
657
|
+
"76/1393"
|
658
|
+
]
|
659
|
+
},
|
660
|
+
{
|
661
|
+
"cell_type": "code",
|
662
|
+
"execution_count": null,
|
663
|
+
"id": "58",
|
664
|
+
"metadata": {},
|
665
|
+
"outputs": [],
|
666
|
+
"source": [
|
667
|
+
"\n",
|
668
|
+
"df_glu_male = df_glu[cond_m & cond_fasting & (df_glu.)][\n",
|
669
|
+
"[\"fbg_threshold\", \"ogtt_threshold\"]].value_counts().to_frame().reset_index()\n"
|
670
|
+
]
|
671
|
+
},
|
672
|
+
{
|
673
|
+
"cell_type": "code",
|
674
|
+
"execution_count": null,
|
675
|
+
"id": "59",
|
676
|
+
"metadata": {},
|
677
|
+
"outputs": [],
|
678
|
+
"source": [
|
679
|
+
"df_glu_male"
|
680
|
+
]
|
681
|
+
},
|
682
|
+
{
|
683
|
+
"cell_type": "code",
|
684
|
+
"execution_count": null,
|
685
|
+
"id": "60",
|
686
|
+
"metadata": {},
|
687
|
+
"outputs": [],
|
688
|
+
"source": [
|
689
|
+
"assert df_glu_male[\"count\"].sum() == 1414"
|
690
|
+
]
|
691
|
+
},
|
692
|
+
{
|
693
|
+
"cell_type": "code",
|
694
|
+
"execution_count": null,
|
695
|
+
"id": "61",
|
696
|
+
"metadata": {},
|
697
|
+
"outputs": [],
|
698
|
+
"source": []
|
699
|
+
},
|
700
|
+
{
|
701
|
+
"cell_type": "code",
|
702
|
+
"execution_count": null,
|
703
|
+
"id": "62",
|
704
|
+
"metadata": {},
|
705
|
+
"outputs": [],
|
706
|
+
"source": []
|
707
|
+
},
|
708
|
+
{
|
709
|
+
"cell_type": "code",
|
710
|
+
"execution_count": null,
|
711
|
+
"id": "63",
|
712
|
+
"metadata": {},
|
713
|
+
"outputs": [],
|
714
|
+
"source": []
|
715
|
+
},
|
716
|
+
{
|
717
|
+
"cell_type": "code",
|
718
|
+
"execution_count": null,
|
719
|
+
"id": "64",
|
720
|
+
"metadata": {},
|
721
|
+
"outputs": [],
|
722
|
+
"source": [
|
723
|
+
"from scipy.stats.contingency import odds_ratio\n",
|
724
|
+
"\n",
|
725
|
+
"# female\n",
|
726
|
+
"df_glu_female"
|
727
|
+
]
|
728
|
+
},
|
729
|
+
{
|
730
|
+
"cell_type": "code",
|
731
|
+
"execution_count": null,
|
732
|
+
"id": "65",
|
733
|
+
"metadata": {},
|
734
|
+
"outputs": [],
|
735
|
+
"source": [
|
736
|
+
"# female\n",
|
737
|
+
"res = odds_ratio([[98, 436], [50,3617]])\n",
|
738
|
+
"res.statistic"
|
739
|
+
]
|
740
|
+
},
|
741
|
+
{
|
742
|
+
"cell_type": "code",
|
743
|
+
"execution_count": null,
|
744
|
+
"id": "66",
|
745
|
+
"metadata": {},
|
746
|
+
"outputs": [],
|
747
|
+
"source": [
|
748
|
+
"# male\n",
|
749
|
+
"df_glu_male"
|
750
|
+
]
|
751
|
+
},
|
752
|
+
{
|
753
|
+
"cell_type": "code",
|
754
|
+
"execution_count": null,
|
755
|
+
"id": "67",
|
756
|
+
"metadata": {},
|
757
|
+
"outputs": [],
|
758
|
+
"source": [
|
759
|
+
"# male\n",
|
760
|
+
"df_glu_male\n",
|
761
|
+
"res = odds_ratio([[44, 32], [150,1188]])\n",
|
762
|
+
"res.statistic"
|
763
|
+
]
|
764
|
+
},
|
765
|
+
{
|
766
|
+
"cell_type": "code",
|
767
|
+
"execution_count": null,
|
768
|
+
"id": "68",
|
769
|
+
"metadata": {},
|
770
|
+
"outputs": [],
|
771
|
+
"source": [
|
772
|
+
"# female\n",
|
773
|
+
"res.confidence_interval(confidence_level=0.95)"
|
774
|
+
]
|
775
|
+
},
|
776
|
+
{
|
777
|
+
"cell_type": "code",
|
778
|
+
"execution_count": null,
|
779
|
+
"id": "69",
|
780
|
+
"metadata": {},
|
781
|
+
"outputs": [],
|
782
|
+
"source": [
|
783
|
+
"res.confidence_interval(confidence_level=0.95)"
|
784
|
+
]
|
785
|
+
},
|
786
|
+
{
|
787
|
+
"cell_type": "code",
|
788
|
+
"execution_count": null,
|
789
|
+
"id": "70",
|
790
|
+
"metadata": {},
|
791
|
+
"outputs": [],
|
792
|
+
"source": [
|
793
|
+
"df_glu[\"ogtt\"].dtype"
|
794
|
+
]
|
795
|
+
},
|
796
|
+
{
|
797
|
+
"cell_type": "code",
|
798
|
+
"execution_count": null,
|
799
|
+
"id": "71",
|
800
|
+
"metadata": {},
|
801
|
+
"outputs": [],
|
802
|
+
"source": [
|
803
|
+
"# df_glu[cond_f & cond_fasting & (df_glu.ogtt.notna()) & ((df_glu.fbg>=7.0) | (df_glu.ogtt>=11.1))].count()\n",
|
804
|
+
"\n",
|
805
|
+
"# when ogtt not done \n",
|
806
|
+
"# df_glu[cond_f & cond_fasting & (df_glu.ogtt.isna())].fbg.describe()\n",
|
807
|
+
"\n",
|
808
|
+
"# we never have ogtt w/o fbg\n",
|
809
|
+
"# df_glu[cond_f & cond_fasting & (df_glu.fbg.isna())].ogtt.describe()\n",
|
810
|
+
"df_glu2 = get_glucose_tested_only_df()\n",
|
811
|
+
"cond_fasting2 = (df_glu2.fasting == \"Yes\") & (df_glu2.fasting_fbg_hrs >= 8.0)\n",
|
812
|
+
"\n",
|
813
|
+
"# df_glu = df_glu.reset_index(drop=False)\n",
|
814
|
+
"def dx(row):\n",
|
815
|
+
" # print((row.fbg>=7.0) & (row.ogtt>=11.1))\n",
|
816
|
+
" # print(row.fbg, row.ogtt)\n",
|
817
|
+
" if (row.fbg>=7.0) & (row.ogtt>=11.1):\n",
|
818
|
+
" ret = \"fbg_ogtt\"\n",
|
819
|
+
" elif (row.fbg>=7.0) & (row.ogtt<11.1):\n",
|
820
|
+
" ret = \"fbg_only\"\n",
|
821
|
+
" elif (row.fbg<7.0) & (row.ogtt>=11.1):\n",
|
822
|
+
" ret = \"ogtt_only\"\n",
|
823
|
+
" elif (row.fbg<7.0) & (row.ogtt<11.1):\n",
|
824
|
+
" ret = \"neither\"\n",
|
825
|
+
" else:\n",
|
826
|
+
" ret = \"error\"\n",
|
827
|
+
" return ret\n",
|
828
|
+
" \n",
|
829
|
+
"df_glu2[\"glucose\"] = \"\" \n",
|
830
|
+
"df_glu2[\"glucose\"] = df_glu2[cond_fasting2].apply(lambda r: dx(r), axis=1)\n",
|
831
|
+
"df_glu2[\"glucose\"].value_counts()\n",
|
832
|
+
"# df_glu[cond_fasting & cond_f]\n"
|
833
|
+
]
|
834
|
+
},
|
835
|
+
{
|
836
|
+
"cell_type": "code",
|
837
|
+
"execution_count": null,
|
838
|
+
"id": "72",
|
839
|
+
"metadata": {},
|
840
|
+
"outputs": [],
|
841
|
+
"source": []
|
842
|
+
},
|
843
|
+
{
|
844
|
+
"cell_type": "code",
|
845
|
+
"execution_count": null,
|
846
|
+
"id": "73",
|
847
|
+
"metadata": {},
|
848
|
+
"outputs": [],
|
849
|
+
"source": [
|
850
|
+
"df_glu[cond_m & cond_fasting & ((df_glu.fbg>=7.0) | (df_glu.ogtt>=11.1))].count()"
|
851
|
+
]
|
852
|
+
},
|
853
|
+
{
|
854
|
+
"cell_type": "code",
|
855
|
+
"execution_count": null,
|
856
|
+
"id": "74",
|
857
|
+
"metadata": {},
|
858
|
+
"outputs": [],
|
859
|
+
"source": [
|
860
|
+
"df_glu_female = df_glu[\n",
|
861
|
+
" cond_f & \n",
|
862
|
+
" cond_fasting & \n",
|
863
|
+
" ((df_glu.fbg>=7.0) | (df_glu.fbg.isna()) | (df_glu.ogtt>=11.1) | (df_glu.ogtt.isna()) )\n",
|
864
|
+
"][[\"fbg_threshold\", \"ogtt_threshold\"]].value_counts().to_frame().reset_index()\n",
|
865
|
+
"df_glu_female"
|
866
|
+
]
|
867
|
+
},
|
868
|
+
{
|
869
|
+
"cell_type": "code",
|
870
|
+
"execution_count": null,
|
871
|
+
"id": "75",
|
872
|
+
"metadata": {},
|
873
|
+
"outputs": [],
|
874
|
+
"source": [
|
875
|
+
"res = odds_ratio([[98, 50], [436,3619]])\n",
|
876
|
+
"res.statistic"
|
877
|
+
]
|
878
|
+
},
|
879
|
+
{
|
880
|
+
"cell_type": "code",
|
881
|
+
"execution_count": null,
|
882
|
+
"id": "76",
|
883
|
+
"metadata": {},
|
884
|
+
"outputs": [],
|
885
|
+
"source": [
|
886
|
+
"res.confidence_interval(confidence_level=0.95)"
|
887
|
+
]
|
888
|
+
},
|
889
|
+
{
|
890
|
+
"cell_type": "code",
|
891
|
+
"execution_count": null,
|
892
|
+
"id": "77",
|
893
|
+
"metadata": {},
|
894
|
+
"outputs": [],
|
895
|
+
"source": [
|
896
|
+
"import numpy as np\n",
|
897
|
+
"from scipy.stats import hypergeom\n",
|
898
|
+
"table = np.array([[98, 436], [50, 3619]])\n",
|
899
|
+
"M = table.sum()\n",
|
900
|
+
"n = table[0].sum()\n",
|
901
|
+
"N = table[:, 0].sum()\n",
|
902
|
+
"start, end = hypergeom.support(M, n, N)\n",
|
903
|
+
"hypergeom.pmf(np.arange(start, end+1), M, n, N)\n"
|
904
|
+
]
|
905
|
+
},
|
906
|
+
{
|
907
|
+
"cell_type": "code",
|
908
|
+
"execution_count": null,
|
909
|
+
"id": "78",
|
910
|
+
"metadata": {},
|
911
|
+
"outputs": [],
|
912
|
+
"source": [
|
913
|
+
"from scipy.stats import fisher_exact\n",
|
914
|
+
"res = fisher_exact(table, alternative='two-sided')\n",
|
915
|
+
"res.pvalue"
|
916
|
+
]
|
917
|
+
},
|
918
|
+
{
|
919
|
+
"cell_type": "code",
|
920
|
+
"execution_count": null,
|
921
|
+
"id": "79",
|
922
|
+
"metadata": {},
|
923
|
+
"outputs": [],
|
924
|
+
"source": [
|
925
|
+
"res.statistic"
|
926
|
+
]
|
927
|
+
},
|
928
|
+
{
|
929
|
+
"cell_type": "code",
|
930
|
+
"execution_count": null,
|
931
|
+
"id": "80",
|
932
|
+
"metadata": {},
|
933
|
+
"outputs": [],
|
934
|
+
"source": []
|
935
|
+
}
|
936
|
+
],
|
937
|
+
"metadata": {
|
938
|
+
"kernelspec": {
|
939
|
+
"display_name": "Python 3 (ipykernel)",
|
940
|
+
"language": "python",
|
941
|
+
"name": "python3"
|
942
|
+
},
|
943
|
+
"language_info": {
|
944
|
+
"codemirror_mode": {
|
945
|
+
"name": "ipython",
|
946
|
+
"version": 3
|
947
|
+
},
|
948
|
+
"file_extension": ".py",
|
949
|
+
"mimetype": "text/x-python",
|
950
|
+
"name": "python",
|
951
|
+
"nbconvert_exporter": "python",
|
952
|
+
"pygments_lexer": "ipython3",
|
953
|
+
"version": "3.12.4"
|
954
|
+
}
|
955
|
+
},
|
956
|
+
"nbformat": 4,
|
957
|
+
"nbformat_minor": 5
|
958
|
+
}
|