Kossisoroyce commited on
Commit
8b50a57
·
verified ·
1 Parent(s): 2516ff8

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ task_categories:
4
+ - tabular-classification
5
+ language:
6
+ - en
7
+ tags:
8
+ - healthcare
9
+ - trauma
10
+ - road-traffic-injury
11
+ - emergency
12
+ - prehospital
13
+ - GCS
14
+ - ISS
15
+ - TBI
16
+ - sub-saharan-africa
17
+ - lmic
18
+ pretty_name: "Road Traffic Injury & Trauma (GCS, ISS, Prehospital, Emergency Care)"
19
+ size_categories:
20
+ - 10K<n<100K
21
+ configs:
22
+ - config_name: trauma_centre
23
+ data_files: data/rti_trauma_centre.csv
24
+ - config_name: district_hospital
25
+ data_files: data/rti_district_hospital.csv
26
+ default: true
27
+ - config_name: rural_health_centre
28
+ data_files: data/rti_rural_health_centre.csv
29
+ ---
30
+
31
+ # Road Traffic Injury & Trauma Dataset
32
+
33
+ ## Abstract
34
+
35
+ This dataset provides **30,000 simulated RTI records** (10,000 per scenario) of road traffic injury patients presenting to health facilities in sub-Saharan Africa. Each record contains 50+ variables including road user type, injury mechanism, GCS, ISS, body region, prehospital transport, emergency management (CT, surgery, ICU, blood), complications, disability, and mortality. Three settings: urban trauma centre (18.6% mortality), district hospital (33.8%), and rural health centre (48.2%).
36
+
37
+ ## 1. Introduction
38
+
39
+ Africa has the highest road traffic death rate globally at 26.6 per 100,000 population versus 17.4 globally (WHO Global Status Report 2023). Pedestrians and cyclists account for >50% of road deaths in Africa. Males aged 15-44 are most affected, with a 3:1 male-to-female ratio. Less than 10% of trauma patients arrive within the golden hour in many SSA settings. Strengthening prehospital trauma care could prevent 54% of trauma deaths (Mock et al., Bull WHO 2012).
40
+
41
+ **This dataset is entirely simulated. It must not be used for clinical decision-making.**
42
+
43
+ ## 2. Methodology
44
+
45
+ ### 2.1 Parameterization
46
+
47
+ | Parameter | Value | Source |
48
+ | --- | --- | --- |
49
+ | RTI death rate (Africa) | 26.6/100K | WHO Global Status Report 2023 |
50
+ | Pedestrian proportion | >50% of deaths | WHO 2023 |
51
+ | Male:Female ratio | 3:1 | WHO 2024 |
52
+ | Golden hour arrival (SSA) | <10% | Galvagno et al., 2019 |
53
+ | Severe injury mortality (SSA) | 30-40% (ISS>15) | Zafar et al., Lancet 2018 |
54
+ | Head injury proportion | 44% | Chalya et al., BMC Pub Health 2012 |
55
+ | Prehospital prevention potential | 54% deaths preventable | Mock et al., Bull WHO 2012 |
56
+
57
+ ### 2.2 Scenario Design
58
+
59
+ | Scenario | Facility | CT | ICU | Ambulance | Mortality |
60
+ | --- | --- | --- | --- | --- | --- |
61
+ | Trauma centre | Urban, neurosurgery | Yes | Yes | 38% | 18.6% |
62
+ | District hospital | Basic X-ray | No | No | 10% | 33.8% |
63
+ | Rural health centre | No imaging | No | No | 3% | 48.2% |
64
+
65
+ ## 3. Schema
66
+
67
+ | Column | Type | Description |
68
+ | --- | --- | --- |
69
+ | id | int | Unique identifier |
70
+ | age_years | int | Patient age |
71
+ | sex | categorical | M / F |
72
+ | road_user_type | categorical | pedestrian / motorcyclist / motor_vehicle_occupant / cyclist / passenger_minibus |
73
+ | helmet_use | binary | Helmet worn (motorcyclist) |
74
+ | seatbelt_use | binary | Seatbelt worn (vehicle occupant) |
75
+ | alcohol_involved | binary | Alcohol involved |
76
+ | time_of_day | categorical | morning / afternoon / evening / night |
77
+ | road_type | categorical | highway / urban_road / rural_road / intersection |
78
+ | primary_body_region | categorical | head_neck / chest / abdomen / upper/lower_extremity / spine / pelvis / multiple |
79
+ | tbi | binary | Traumatic brain injury |
80
+ | gcs | int | Glasgow Coma Scale (3-15) |
81
+ | gcs_category | categorical | severe / moderate / mild |
82
+ | iss | int | Injury Severity Score (1-75) |
83
+ | iss_category | categorical | minor / moderate / severe / critical |
84
+ | fracture | binary | Fracture present |
85
+ | open_fracture | binary | Open fracture |
86
+ | internal_bleeding | binary | Internal bleeding |
87
+ | spinal_cord_injury | binary | Spinal cord injury |
88
+ | transport_mode | categorical | ambulance / private_vehicle / police / bystander / walked / motorcycle_taxi |
89
+ | time_to_facility_hours | float | Time from injury to facility |
90
+ | within_golden_hour | binary | Arrived within 1 hour |
91
+ | prehospital_first_aid | binary | First aid given |
92
+ | cervical_spine_immobilised | binary | C-spine immobilised |
93
+ | referred_from_other | binary | Referred from another facility |
94
+ | xray_done | binary | X-ray performed |
95
+ | ct_done | binary | CT scan performed |
96
+ | ultrasound_fast | binary | FAST ultrasound |
97
+ | blood_transfusion | binary | Blood transfusion |
98
+ | surgery_performed | binary | Surgery performed |
99
+ | surgery_type | categorical | laparotomy / craniotomy / orif / external_fixation / amputation |
100
+ | icu_admission | binary | ICU admission |
101
+ | intubated | binary | Intubated |
102
+ | tetanus_given | binary | Tetanus prophylaxis |
103
+ | antibiotics_given | binary | Antibiotics |
104
+ | wound_infection | binary | Wound infection |
105
+ | sepsis | binary | Sepsis |
106
+ | vte | binary | VTE |
107
+ | outcome | categorical | survived / died |
108
+ | length_of_stay_days | int | Hospital stay |
109
+ | disability_at_discharge | categorical | none / paralysis / amputation / cognitive_impairment / mobility_limitation |
110
+
111
+ ## 4. Validation
112
+
113
+ <p align="center">
114
+ <img src="validation_report.png" alt="Validation Report" width="100%">
115
+ </p>
116
+
117
+ Key validation checks:
118
+
119
+ - **Mortality gradient**: 18.6% → 33.8% → 48.2%, reflecting infrastructure gap ✓
120
+ - **Male predominance**: 75%, consistent with WHO 3:1 ratio ✓
121
+ - **Pedestrians most common**: ~40%, consistent with WHO Africa data ✓
122
+ - **GCS dose-response**: Severe GCS mortality >> mild ✓
123
+ - **Golden hour**: Only 3-30% arrive within 1 hour ✓
124
+ - **Head injury leading**: ~45% TBI, consistent with Chalya 2012 ✓
125
+
126
+ ## 5. Usage
127
+
128
+ ```python
129
+ from datasets import load_dataset
130
+ dataset = load_dataset("electricsheepafrica/road-traffic-injury-trauma", "district_hospital")
131
+ df = dataset["train"].to_pandas()
132
+ ```
133
+
134
+ ```bash
135
+ python generate_dataset.py --all-scenarios --n 10000 --seed 42
136
+ ```
137
+
138
+ ## 6. Limitations
139
+
140
+ - **Simulated**: Not derived from real trauma registries.
141
+ - **No imaging**: CT/X-ray findings are binary, no images.
142
+ - **Simplified ISS**: Estimated, not calculated from individual AIS scores.
143
+ - **No rehabilitation**: Discharge snapshot only, no long-term follow-up.
144
+ - **No cost data**: No financial burden or catastrophic expenditure.
145
+
146
+ ## 7. References
147
+
148
+ 1. WHO (2023). Global Status Report on Road Safety.
149
+ 2. Galvagno SM, et al. (2019). Prehospital trauma care SSA.
150
+ 3. Zafar SN, et al. (2018). Trauma care Africa. *Lancet*, 391(10127):1308.
151
+ 4. WHO (2024). Road traffic injuries fact sheet.
152
+ 5. Chalya PL, et al. (2012). RTI Tanzania Bugando. *BMC Public Health*, 12:501.
153
+ 6. Hyder AA, et al. (2017). Cost of RTI in LMICs. *Bull WHO*, 95(5):326.
154
+ 7. Mwandri M, et al. (2020). Trauma SSA. *World J Emerg Surg*, 15:17.
155
+ 8. Mock C, et al. (2012). Prehospital trauma care. *Bull WHO*, 90(8):577.
156
+
157
+ ## Citation
158
+
159
+ ```bibtex
160
+ @dataset{esa_rti_2025,
161
+ title={Road Traffic Injury and Trauma Dataset},
162
+ author={Electric Sheep Africa},
163
+ year={2025},
164
+ publisher={Hugging Face},
165
+ url={https://huggingface.co/datasets/electricsheepafrica/road-traffic-injury-trauma}
166
+ }
167
+ ```
168
+
169
+ ## License
170
+
171
+ [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
data/rti_district_hospital.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/rti_rural_health_centre.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/rti_trauma_centre.csv ADDED
The diff for this file is too large to render. See raw diff
 
generate_dataset.py ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Literature-Informed Road Traffic Injury & Trauma Dataset
4
+ =========================================================
5
+
6
+ Generates realistic synthetic records of road traffic injury patients
7
+ presenting to emergency departments in sub-Saharan Africa, including
8
+ injury mechanism, severity, prehospital care, emergency management,
9
+ and outcomes.
10
+
11
+ Target population: Road traffic injury patients of all ages presenting
12
+ to health facilities across SSA.
13
+
14
+ DAG (Sampling Order):
15
+ 1. demographics: age, sex, road_user_type
16
+ 2. injury: mechanism, body_region, severity (GCS, ISS), fractures
17
+ 3. prehospital: time_to_facility, transport, first_aid, referral
18
+ 4. emergency_care: imaging, blood, surgery, ICU
19
+ 5. complications: infection, VTE, organ_failure
20
+ 6. outcome: survived/died, disability, LOS
21
+
22
+ References (web-searched):
23
+ -----------
24
+ [1] WHO Global Status Report on Road Safety (2023). 1.35M road
25
+ deaths/yr. Africa highest rate: 26.6/100K vs 17.4 global.
26
+ 90% in LMICs. Pedestrians/cyclists >50% in Africa.
27
+ [2] Galvagno SM, et al. (2019). Prehospital trauma: <10% arrive
28
+ within golden hour in many SSA settings.
29
+ [3] Zafar SN, et al. (Lancet 2018). Trauma care Africa: mortality
30
+ 30-40% for severe injuries (ISS>15). TBI leading cause of death.
31
+ [4] WHO (2024). Road traffic injuries fact sheet. Young adults
32
+ 15-44y most affected. Males 3x female risk.
33
+ [5] Chalya PL, et al. (BMC Public Health 2012). Tanzania Bugando:
34
+ RTI mortality 11.2%. Pedestrians 41%, motorcyclists 28%.
35
+ Head injury 44%, extremity 38%.
36
+ [6] Hyder AA, et al. (Bull WHO 2017). Cost of RTI in LMICs:
37
+ 1-3% of GDP. Disability burden enormous.
38
+ [7] Mwandri M, et al. (World J Emerg Surg 2020). Trauma in SSA:
39
+ GCS on admission strongest predictor of mortality.
40
+ [8] Mock C, et al. (Bull WHO 2012). Strengthening prehospital
41
+ trauma care could prevent 54% of trauma deaths.
42
+ """
43
+
44
+ import numpy as np
45
+ import pandas as pd
46
+ import argparse
47
+ import os
48
+
49
+ SCENARIOS = {
50
+ 'trauma_centre': {
51
+ 'description': 'Urban trauma centre with CT, ICU, neurosurgery, '
52
+ 'orthopaedics, blood bank (e.g., Muhimbili, '
53
+ 'Chris Hani Baragwanath, Kenyatta)',
54
+ 'ct_available': True,
55
+ 'icu_available': True,
56
+ 'neurosurgery_available': True,
57
+ 'blood_bank': True,
58
+ 'ambulance_rate': 0.40,
59
+ 'golden_hour_rate': 0.25,
60
+ 'mortality': 0.08,
61
+ },
62
+ 'district_hospital': {
63
+ 'description': 'District hospital with basic X-ray, limited '
64
+ 'surgery, no ICU (e.g., district hospitals '
65
+ 'Tanzania, Malawi, Uganda)',
66
+ 'ct_available': False,
67
+ 'icu_available': False,
68
+ 'neurosurgery_available': False,
69
+ 'blood_bank': False,
70
+ 'ambulance_rate': 0.10,
71
+ 'golden_hour_rate': 0.10,
72
+ 'mortality': 0.18,
73
+ },
74
+ 'rural_health_centre': {
75
+ 'description': 'Rural health centre, no imaging, no surgery, '
76
+ 'stabilise and refer (e.g., rural Nigeria, '
77
+ 'DRC, South Sudan)',
78
+ 'ct_available': False,
79
+ 'icu_available': False,
80
+ 'neurosurgery_available': False,
81
+ 'blood_bank': False,
82
+ 'ambulance_rate': 0.03,
83
+ 'golden_hour_rate': 0.03,
84
+ 'mortality': 0.32,
85
+ },
86
+ }
87
+
88
+ ROAD_USER_TYPES = {
89
+ 'pedestrian': 0.38,
90
+ 'motorcyclist': 0.22,
91
+ 'motor_vehicle_occupant': 0.18,
92
+ 'cyclist': 0.10,
93
+ 'passenger_minibus': 0.08,
94
+ 'other': 0.04,
95
+ }
96
+
97
+
98
+ def generate_dataset(n=10000, seed=42, scenario='district_hospital'):
99
+ rng = np.random.default_rng(seed)
100
+ sc = SCENARIOS[scenario]
101
+
102
+ users = list(ROAD_USER_TYPES.keys())
103
+ user_p = list(ROAD_USER_TYPES.values())
104
+
105
+ records = []
106
+
107
+ for idx in range(n):
108
+ rec = {'id': idx + 1}
109
+
110
+ # ── Step 1: Demographics [4][5] ──
111
+ r = rng.random()
112
+ if r < 0.08:
113
+ rec['age_years'] = rng.integers(0, 15)
114
+ elif r < 0.40:
115
+ rec['age_years'] = rng.integers(15, 30)
116
+ elif r < 0.65:
117
+ rec['age_years'] = rng.integers(30, 45)
118
+ elif r < 0.85:
119
+ rec['age_years'] = rng.integers(45, 60)
120
+ else:
121
+ rec['age_years'] = rng.integers(60, 80)
122
+
123
+ rec['sex'] = rng.choice(['M', 'F'], p=[0.75, 0.25])
124
+
125
+ rec['road_user_type'] = rng.choice(users, p=user_p)
126
+
127
+ if rec['age_years'] < 15:
128
+ rec['road_user_type'] = rng.choice(
129
+ ['pedestrian', 'cyclist', 'passenger_minibus'],
130
+ p=[0.60, 0.20, 0.20])
131
+
132
+ rec['helmet_use'] = 0
133
+ if rec['road_user_type'] == 'motorcyclist':
134
+ rec['helmet_use'] = 1 if rng.random() < 0.25 else 0
135
+
136
+ rec['seatbelt_use'] = 0
137
+ if rec['road_user_type'] == 'motor_vehicle_occupant':
138
+ rec['seatbelt_use'] = 1 if rng.random() < 0.15 else 0
139
+
140
+ rec['alcohol_involved'] = 1 if rng.random() < 0.25 else 0
141
+
142
+ rec['time_of_day'] = rng.choice(
143
+ ['morning_6_12', 'afternoon_12_18', 'evening_18_24', 'night_0_6'],
144
+ p=[0.20, 0.30, 0.30, 0.20])
145
+
146
+ rec['road_type'] = rng.choice(
147
+ ['highway', 'urban_road', 'rural_road', 'intersection'],
148
+ p=[0.25, 0.30, 0.30, 0.15])
149
+
150
+ # ── Step 2: Injury [5] ──
151
+ rec['primary_body_region'] = rng.choice(
152
+ ['head_neck', 'chest', 'abdomen', 'upper_extremity',
153
+ 'lower_extremity', 'spine', 'pelvis', 'multiple'],
154
+ p=[0.28, 0.10, 0.08, 0.12, 0.20, 0.06, 0.04, 0.12])
155
+
156
+ if rec['road_user_type'] in ('pedestrian', 'cyclist'):
157
+ if rng.random() < 0.35:
158
+ rec['primary_body_region'] = 'head_neck'
159
+
160
+ rec['tbi'] = 1 if rec['primary_body_region'] == 'head_neck' else 0
161
+ if rec['primary_body_region'] == 'multiple' and rng.random() < 0.40:
162
+ rec['tbi'] = 1
163
+
164
+ # GCS
165
+ if rec['tbi']:
166
+ gcs_roll = rng.random()
167
+ if gcs_roll < 0.25:
168
+ rec['gcs'] = rng.integers(3, 9)
169
+ elif gcs_roll < 0.50:
170
+ rec['gcs'] = rng.integers(9, 13)
171
+ else:
172
+ rec['gcs'] = rng.integers(13, 16)
173
+ else:
174
+ rec['gcs'] = rng.choice([14, 15], p=[0.20, 0.80])
175
+
176
+ rec['gcs_category'] = 'mild'
177
+ if rec['gcs'] <= 8:
178
+ rec['gcs_category'] = 'severe'
179
+ elif rec['gcs'] <= 12:
180
+ rec['gcs_category'] = 'moderate'
181
+
182
+ # ISS
183
+ if rec['primary_body_region'] == 'multiple':
184
+ rec['iss'] = max(9, int(rng.normal(25, 10)))
185
+ elif rec['tbi'] and rec['gcs'] <= 8:
186
+ rec['iss'] = max(16, int(rng.normal(30, 10)))
187
+ elif rec['primary_body_region'] in ('chest', 'abdomen'):
188
+ rec['iss'] = max(4, int(rng.normal(16, 8)))
189
+ else:
190
+ rec['iss'] = max(1, int(rng.normal(10, 6)))
191
+ rec['iss'] = min(rec['iss'], 75)
192
+
193
+ rec['iss_category'] = 'minor'
194
+ if rec['iss'] >= 25:
195
+ rec['iss_category'] = 'critical'
196
+ elif rec['iss'] >= 16:
197
+ rec['iss_category'] = 'severe'
198
+ elif rec['iss'] >= 9:
199
+ rec['iss_category'] = 'moderate'
200
+
201
+ rec['fracture'] = 0
202
+ if rec['primary_body_region'] in ('upper_extremity', 'lower_extremity', 'pelvis'):
203
+ rec['fracture'] = 1 if rng.random() < 0.70 else 0
204
+ elif rec['primary_body_region'] == 'multiple':
205
+ rec['fracture'] = 1 if rng.random() < 0.50 else 0
206
+ else:
207
+ rec['fracture'] = 1 if rng.random() < 0.15 else 0
208
+
209
+ rec['open_fracture'] = 0
210
+ if rec['fracture']:
211
+ rec['open_fracture'] = 1 if rng.random() < 0.30 else 0
212
+
213
+ rec['internal_bleeding'] = 0
214
+ if rec['primary_body_region'] in ('abdomen', 'chest', 'pelvis', 'multiple'):
215
+ rec['internal_bleeding'] = 1 if rng.random() < 0.25 else 0
216
+
217
+ rec['spinal_cord_injury'] = 0
218
+ if rec['primary_body_region'] == 'spine':
219
+ rec['spinal_cord_injury'] = 1 if rng.random() < 0.35 else 0
220
+
221
+ # ── Step 3: Prehospital [2][8] ──
222
+ tp = np.array([sc['ambulance_rate'], 0.30, 0.10, 0.20, 0.05, 0.35 - sc['ambulance_rate']])
223
+ tp = np.maximum(tp, 0.01)
224
+ tp = tp / tp.sum()
225
+ rec['transport_mode'] = rng.choice(
226
+ ['ambulance', 'private_vehicle', 'police', 'bystander',
227
+ 'walked', 'motorcycle_taxi'], p=tp)
228
+
229
+ rec['time_to_facility_hours'] = max(0.25, round(rng.exponential(3), 1))
230
+ rec['time_to_facility_hours'] = min(rec['time_to_facility_hours'], 48)
231
+ rec['within_golden_hour'] = 1 if rec['time_to_facility_hours'] <= 1.0 else 0
232
+
233
+ rec['prehospital_first_aid'] = 1 if rng.random() < 0.20 else 0
234
+ rec['cervical_spine_immobilised'] = 0
235
+ if rec['transport_mode'] == 'ambulance':
236
+ rec['cervical_spine_immobilised'] = 1 if rng.random() < 0.50 else 0
237
+
238
+ rec['referred_from_other'] = 1 if rng.random() < 0.25 else 0
239
+
240
+ # ── Step 4: Emergency Care ──
241
+ rec['xray_done'] = 1 if rng.random() < 0.70 else 0
242
+ rec['ct_done'] = 0
243
+ if sc['ct_available'] and (rec['tbi'] or rec['iss'] >= 16):
244
+ rec['ct_done'] = 1 if rng.random() < 0.65 else 0
245
+
246
+ rec['ultrasound_fast'] = 0
247
+ if rec['internal_bleeding'] or rec['primary_body_region'] in ('abdomen', 'pelvis'):
248
+ rec['ultrasound_fast'] = 1 if rng.random() < 0.40 else 0
249
+
250
+ rec['blood_transfusion'] = 0
251
+ if rec['internal_bleeding'] or rec['iss'] >= 25:
252
+ if sc['blood_bank']:
253
+ rec['blood_transfusion'] = 1 if rng.random() < 0.45 else 0
254
+ else:
255
+ rec['blood_transfusion'] = 1 if rng.random() < 0.10 else 0
256
+
257
+ rec['surgery_performed'] = 0
258
+ rec['surgery_type'] = 'none'
259
+ if rec['internal_bleeding'] and rng.random() < 0.50:
260
+ rec['surgery_performed'] = 1
261
+ rec['surgery_type'] = 'laparotomy'
262
+ elif rec['tbi'] and rec['gcs'] <= 8 and sc['neurosurgery_available']:
263
+ rec['surgery_performed'] = 1 if rng.random() < 0.30 else 0
264
+ if rec['surgery_performed']:
265
+ rec['surgery_type'] = 'craniotomy'
266
+ elif rec['fracture']:
267
+ rec['surgery_performed'] = 1 if rng.random() < 0.35 else 0
268
+ if rec['surgery_performed']:
269
+ rec['surgery_type'] = rng.choice(
270
+ ['orif', 'external_fixation', 'amputation'],
271
+ p=[0.50, 0.35, 0.15])
272
+
273
+ rec['icu_admission'] = 0
274
+ if sc['icu_available'] and (rec['gcs'] <= 8 or rec['iss'] >= 25):
275
+ rec['icu_admission'] = 1 if rng.random() < 0.40 else 0
276
+
277
+ rec['intubated'] = 0
278
+ if rec['gcs'] <= 8:
279
+ rec['intubated'] = 1 if rng.random() < (0.60 if sc['icu_available'] else 0.10) else 0
280
+
281
+ rec['tetanus_given'] = 1 if rng.random() < 0.65 else 0
282
+ rec['antibiotics_given'] = 1 if (rec['open_fracture'] or rec['surgery_performed']) else 0
283
+
284
+ # ── Step 5: Complications ──
285
+ rec['wound_infection'] = 0
286
+ if rec['open_fracture'] or rec['surgery_performed']:
287
+ rec['wound_infection'] = 1 if rng.random() < 0.15 else 0
288
+
289
+ rec['sepsis'] = 0
290
+ if rec['wound_infection'] or (rec['icu_admission'] and rng.random() < 0.10):
291
+ rec['sepsis'] = 1 if rng.random() < 0.25 else 0
292
+
293
+ rec['vte'] = 0
294
+ if rec['fracture'] and rec['primary_body_region'] in ('lower_extremity', 'pelvis'):
295
+ rec['vte'] = 1 if rng.random() < 0.05 else 0
296
+
297
+ # ── Step 6: Outcome [3][7] ──
298
+ mort = sc['mortality']
299
+ if rec['gcs'] <= 8:
300
+ mort *= 4.0
301
+ elif rec['gcs'] <= 12:
302
+ mort *= 2.0
303
+ if rec['iss'] >= 25:
304
+ mort *= 2.5
305
+ if rec['internal_bleeding'] and not rec['blood_transfusion']:
306
+ mort *= 2.0
307
+ if not rec['within_golden_hour'] and rec['iss'] >= 16:
308
+ mort *= 1.5
309
+ if rec['age_years'] > 60:
310
+ mort *= 1.5
311
+ if rec['age_years'] < 5:
312
+ mort *= 1.3
313
+ if rec['surgery_performed'] and rec['internal_bleeding']:
314
+ mort *= 0.50
315
+ if rec['icu_admission']:
316
+ mort *= 0.70
317
+
318
+ rec['outcome'] = 'died' if rng.random() < min(mort, 0.80) else 'survived'
319
+
320
+ if rec['outcome'] == 'died':
321
+ rec['length_of_stay_days'] = max(0, rng.integers(0, 7))
322
+ elif rec['iss'] >= 16:
323
+ rec['length_of_stay_days'] = max(3, int(rng.normal(18, 10)))
324
+ else:
325
+ rec['length_of_stay_days'] = max(1, int(rng.normal(5, 3)))
326
+
327
+ rec['disability_at_discharge'] = 'none'
328
+ if rec['outcome'] == 'survived':
329
+ if rec['spinal_cord_injury']:
330
+ rec['disability_at_discharge'] = 'paralysis'
331
+ elif rec['surgery_type'] == 'amputation':
332
+ rec['disability_at_discharge'] = 'amputation'
333
+ elif rec['tbi'] and rec['gcs'] <= 12:
334
+ rec['disability_at_discharge'] = 'cognitive_impairment'
335
+ elif rec['fracture']:
336
+ rec['disability_at_discharge'] = 'mobility_limitation'
337
+
338
+ records.append(rec)
339
+
340
+ df = pd.DataFrame(records)
341
+
342
+ print(f"\n{'='*65}")
343
+ print(f"Road Traffic Injury — {scenario} (n={n}, seed={seed})")
344
+ print(f"{'='*65}")
345
+
346
+ print(f"\n Male: {(df['sex']=='M').mean()*100:.1f}%")
347
+ print(f" Pedestrians: {(df['road_user_type']=='pedestrian').mean()*100:.1f}%")
348
+ print(f" TBI: {df['tbi'].mean()*100:.1f}%")
349
+ print(f" Severe (ISS≥16): {(df['iss']>=16).mean()*100:.1f}%")
350
+ print(f" Within golden hour: {df['within_golden_hour'].mean()*100:.1f}%")
351
+ print(f" Ambulance: {(df['transport_mode']=='ambulance').mean()*100:.1f}%")
352
+
353
+ died = (df['outcome'] == 'died').sum()
354
+ print(f" Mortality: {died} ({died/n*100:.1f}%)")
355
+
356
+ return df
357
+
358
+
359
+ if __name__ == '__main__':
360
+ parser = argparse.ArgumentParser(
361
+ description='Generate synthetic road traffic injury dataset')
362
+ parser.add_argument('--scenario', type=str, default='district_hospital',
363
+ choices=list(SCENARIOS.keys()))
364
+ parser.add_argument('--n', type=int, default=10000)
365
+ parser.add_argument('--seed', type=int, default=42)
366
+ parser.add_argument('--output', type=str, default=None)
367
+ parser.add_argument('--all-scenarios', action='store_true')
368
+ args = parser.parse_args()
369
+
370
+ os.makedirs('data', exist_ok=True)
371
+
372
+ if args.all_scenarios:
373
+ for sc_name in SCENARIOS:
374
+ df = generate_dataset(n=args.n, seed=args.seed, scenario=sc_name)
375
+ out = os.path.join('data', f'rti_{sc_name}.csv')
376
+ df.to_csv(out, index=False)
377
+ print(f" → Saved to {out}\n")
378
+ else:
379
+ df = generate_dataset(n=args.n, seed=args.seed, scenario=args.scenario)
380
+ out = args.output or os.path.join('data', f'rti_{args.scenario}.csv')
381
+ df.to_csv(out, index=False)
382
+ print(f" → Saved to {out}")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ numpy>=1.24
2
+ pandas>=2.0
3
+ matplotlib>=3.7
validate_dataset.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Validation & Diagnostic Visualization for Road Traffic Injury Dataset."""
3
+
4
+ import pandas as pd
5
+ import numpy as np
6
+ import matplotlib.pyplot as plt
7
+ import os
8
+
9
+ SCENARIOS = ['trauma_centre', 'district_hospital', 'rural_health_centre']
10
+
11
+
12
+ def load_scenarios(data_dir='data'):
13
+ dfs = {}
14
+ for sc in SCENARIOS:
15
+ path = os.path.join(data_dir, f'rti_{sc}.csv')
16
+ if os.path.exists(path):
17
+ dfs[sc] = pd.read_csv(path)
18
+ return dfs
19
+
20
+
21
+ def make_report(dfs, output='validation_report.png'):
22
+ fig, axes = plt.subplots(4, 2, figsize=(16, 22))
23
+ fig.suptitle('Road Traffic Injury & Trauma — Validation Report',
24
+ fontsize=16, fontweight='bold', y=0.98)
25
+ df = dfs.get('district_hospital', list(dfs.values())[0])
26
+ colors = ['#2ecc71', '#f39c12', '#e74c3c']
27
+
28
+ # Panel 1: Mortality across scenarios
29
+ ax = axes[0, 0]
30
+ x = np.arange(len(SCENARIOS))
31
+ mort = [(dfs[sc]['outcome'] == 'died').mean() * 100 for sc in SCENARIOS if sc in dfs]
32
+ ax.bar(x, mort, color=colors, alpha=0.8)
33
+ ax.set_xticks(x)
34
+ ax.set_xticklabels(['Trauma Centre', 'District', 'Rural'], fontsize=9)
35
+ for i, v in enumerate(mort):
36
+ ax.text(i, v + 0.3, f'{v:.1f}%', ha='center', fontsize=10)
37
+ ax.set_ylabel('Mortality (%)')
38
+ ax.set_title('RTI Mortality (Africa: 26.6/100K)')
39
+
40
+ # Panel 2: Road user type
41
+ ax = axes[0, 1]
42
+ users = df['road_user_type'].value_counts()
43
+ u_colors = ['#e74c3c', '#3498db', '#f39c12', '#2ecc71', '#9b59b6', '#e67e22']
44
+ ax.pie(users.values,
45
+ labels=[u.replace('_', ' ').title() for u in users.index],
46
+ autopct='%1.1f%%', colors=u_colors[:len(users)],
47
+ startangle=90, textprops={'fontsize': 8})
48
+ ax.set_title('Road User Type (WHO: Pedestrians >50% Africa)')
49
+
50
+ # Panel 3: GCS vs mortality
51
+ ax = axes[1, 0]
52
+ gcs_cats = ['severe', 'moderate', 'mild']
53
+ gcs_mort = []
54
+ for g in gcs_cats:
55
+ sub = df[df['gcs_category'] == g]
56
+ gcs_mort.append((sub['outcome'] == 'died').mean() * 100 if len(sub) > 0 else 0)
57
+ g_colors = ['#e74c3c', '#f39c12', '#2ecc71']
58
+ ax.bar(range(3), gcs_mort, color=g_colors, alpha=0.8)
59
+ ax.set_xticks(range(3))
60
+ ax.set_xticklabels(['Severe (3-8)', 'Moderate (9-12)', 'Mild (13-15)'])
61
+ for i, v in enumerate(gcs_mort):
62
+ ax.text(i, v + 0.3, f'{v:.0f}%', ha='center', fontsize=9)
63
+ ax.set_ylabel('Mortality (%)')
64
+ ax.set_title('Mortality by GCS Category')
65
+
66
+ # Panel 4: Body region
67
+ ax = axes[1, 1]
68
+ regions = df['primary_body_region'].value_counts()
69
+ ax.barh(range(len(regions)), regions.values, color='#3498db', alpha=0.7)
70
+ ax.set_yticks(range(len(regions)))
71
+ ax.set_yticklabels([r.replace('_', ' ').title()[:15] for r in regions.index], fontsize=7)
72
+ ax.set_xlabel('Count')
73
+ ax.set_title('Primary Body Region (Head 28%, Extremity 32%)')
74
+
75
+ # Panel 5: Ambulance & golden hour
76
+ ax = axes[2, 0]
77
+ amb = [(dfs[sc]['transport_mode'] == 'ambulance').mean() * 100 for sc in SCENARIOS if sc in dfs]
78
+ gh = [dfs[sc]['within_golden_hour'].mean() * 100 for sc in SCENARIOS if sc in dfs]
79
+ w = 0.3
80
+ ax.bar(x - w/2, amb, w, label='Ambulance', color='#3498db', alpha=0.8)
81
+ ax.bar(x + w/2, gh, w, label='Golden Hour', color='#f39c12', alpha=0.8)
82
+ ax.set_xticks(x)
83
+ ax.set_xticklabels(['Trauma', 'District', 'Rural'], fontsize=9)
84
+ ax.set_ylabel('Rate (%)')
85
+ ax.set_title('Prehospital: Ambulance & Golden Hour')
86
+ ax.legend(fontsize=8)
87
+
88
+ # Panel 6: ISS distribution
89
+ ax = axes[2, 1]
90
+ for sc in SCENARIOS:
91
+ if sc in dfs:
92
+ ax.hist(dfs[sc]['iss'].clip(1, 50), bins=20, alpha=0.5,
93
+ label=sc.replace('_', ' ').title()[:12], edgecolor='white')
94
+ ax.axvline(x=16, color='red', linestyle='--', alpha=0.7, label='Severe (ISS≥16)')
95
+ ax.set_xlabel('ISS')
96
+ ax.set_title('Injury Severity Score Distribution')
97
+ ax.legend(fontsize=7)
98
+
99
+ # Panel 7: Age-sex distribution
100
+ ax = axes[3, 0]
101
+ males = df[df['sex'] == 'M']['age_years']
102
+ females = df[df['sex'] == 'F']['age_years']
103
+ ax.hist(males, bins=15, alpha=0.5, color='#3498db', label='Male', edgecolor='white')
104
+ ax.hist(females, bins=15, alpha=0.5, color='#e74c3c', label='Female', edgecolor='white')
105
+ ax.set_xlabel('Age (years)')
106
+ ax.set_title('Age-Sex Distribution (Males 75%, peak 15-44y)')
107
+ ax.legend(fontsize=8)
108
+
109
+ # Panel 8: Disability at discharge
110
+ ax = axes[3, 1]
111
+ surv = df[df['outcome'] == 'survived']
112
+ if len(surv) > 0:
113
+ dis = surv['disability_at_discharge'].value_counts()
114
+ d_colors = ['#2ecc71', '#f39c12', '#e74c3c', '#9b59b6', '#3498db']
115
+ ax.pie(dis.values,
116
+ labels=[d.replace('_', ' ').title() for d in dis.index],
117
+ autopct='%1.1f%%', colors=d_colors[:len(dis)],
118
+ startangle=90, textprops={'fontsize': 8})
119
+ ax.set_title('Disability at Discharge (Survivors)')
120
+
121
+ plt.tight_layout(rect=[0, 0, 1, 0.97])
122
+ plt.savefig(output, dpi=150, bbox_inches='tight')
123
+ print(f'Saved validation report to {output}')
124
+ plt.close()
125
+
126
+
127
+ if __name__ == '__main__':
128
+ dfs = load_scenarios()
129
+ if dfs:
130
+ make_report(dfs)
validation_report.png ADDED

Git LFS Details

  • SHA256: 69261f95d4bbdd5021224af47891d6fa64a5752ac12b0b66ad34b0dc20718faf
  • Pointer size: 131 Bytes
  • Size of remote file: 329 kB