Kossisoroyce commited on
Commit
7d8f3a7
·
verified ·
1 Parent(s): 1a7d5c7

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ task_categories:
4
+ - tabular-classification
5
+ - tabular-regression
6
+ language:
7
+ - en
8
+ tags:
9
+ - synthetic
10
+ - healthcare
11
+ - immunisation
12
+ - vaccination
13
+ - epi
14
+ - zero-dose
15
+ - dropout
16
+ - equity
17
+ - who-unicef
18
+ - wuenic
19
+ - dhs
20
+ - lmic
21
+ - gavi
22
+ pretty_name: "Synthetic Childhood Immunisation Coverage & Dropout Dataset (0-23 months)"
23
+ size_categories:
24
+ - 10K<n<100K
25
+ configs:
26
+ - config_name: high_coverage
27
+ data_files: data/immunisation_high_coverage.csv
28
+ - config_name: moderate_coverage
29
+ data_files: data/immunisation_moderate_coverage.csv
30
+ default: true
31
+ - config_name: low_coverage
32
+ data_files: data/immunisation_low_coverage.csv
33
+ ---
34
+
35
+ # Synthetic Childhood Immunisation Coverage & Dropout Dataset (0–23 months)
36
+
37
+ ## Abstract
38
+
39
+ This dataset provides **30,000 synthetic records** (10,000 per scenario) of childhood immunisation status for children aged 0-23 months in LMIC settings. Each record contains 28 variables: demographics, socioeconomic determinants (wealth quintile, maternal education, urban/rural, distance to facility), individual vaccine doses (BCG, OPV0-3, Penta1-3, PCV1-3, Rota1-2, IPV1, MCV1-2), and derived indicators (fully immunised, zero-dose, dropout). Coverage and equity gradients are parameterized from WHO/UNICEF WUENIC estimates, Gavi zero-dose analytics, and DHS vaccination equity analyses. Three scenarios (high, moderate, low coverage) capture the spectrum from well-performing programmes to fragile/conflict-affected settings.
40
+
41
+ ## 1. Introduction
42
+
43
+ Globally, 14.3 million children received no routine vaccines ("zero-dose") in 2022 (WUENIC 2023). Immunisation coverage inequities by wealth, geography, and education remain a central challenge for the Immunization Agenda 2030. Open-access individual-level vaccination datasets from LMICs are scarce—DHS microdata requires registration and is survey-weighted, making it unsuitable for direct ML training.
44
+
45
+ This synthetic dataset addresses this gap for:
46
+
47
+ - Training ML models for zero-dose identification and dropout prediction
48
+ - Equity analysis and coverage gap modelling
49
+ - Prototyping immunisation programme dashboards
50
+ - Educational use in vaccinology and public health informatics
51
+
52
+ **This dataset is entirely synthetic. It must not be used for clinical decision-making or programme evaluation.**
53
+
54
+ ## 2. Methodology
55
+
56
+ ### 2.1 Vaccine Schedule
57
+
58
+ Based on WHO Expanded Programme on Immunization (EPI) recommendations:
59
+
60
+ | Vaccine | Doses | Schedule | Disease Target |
61
+ | --- | --- | --- | --- |
62
+ | BCG | 1 | Birth | Tuberculosis |
63
+ | OPV | 4 (0-3) | Birth, 6, 10, 14 weeks | Poliomyelitis |
64
+ | Penta (DTP-HepB-Hib) | 3 | 6, 10, 14 weeks | Diphtheria, tetanus, pertussis, hepatitis B, Hib |
65
+ | PCV | 3 | 6, 10, 14 weeks | Pneumococcal disease |
66
+ | Rotavirus | 2 | 6, 10 weeks | Rotavirus diarrhoea |
67
+ | IPV | 1 | 14 weeks | Poliomyelitis |
68
+ | Measles (MCV) | 2 | 9, 15 months | Measles |
69
+
70
+ ### 2.2 Equity Determinants
71
+
72
+ Individual coverage probability is modulated by five equity determinants, each with literature-grounded multipliers:
73
+
74
+ | Determinant | Effect | Source |
75
+ | --- | --- | --- |
76
+ | Wealth quintile (1-5) | 0.65x (Q1) to 1.30x (Q5) | Restrepo-Méndez et al., Bull WHO 2016 |
77
+ | Urban/Rural | 1.10x urban, 0.90x rural | DHS pooled estimates |
78
+ | Maternal education | 0.70x (none) to 1.20x (tertiary) | Arsenault et al., Lancet Global Health 2017 |
79
+ | Distance to facility | -1.2% per km | DHS access analyses |
80
+ | Individual random effect | N(1.0, 0.08) | Unobserved heterogeneity |
81
+
82
+ ### 2.3 Scenario Design
83
+
84
+ | Scenario | Context | BCG | Penta3 | MCV1 | MCV2 | Zero-dose |
85
+ | --- | --- | --- | --- | --- | --- | --- |
86
+ | High coverage | Well-performing LMIC | 75.5% | 34.8% | 64.1% | 40.1% | 4.8% |
87
+ | Moderate coverage | Average LMIC | 66.5% | 27.8% | 55.4% | 33.4% | 11.6% |
88
+ | Low coverage | Fragile/conflict | 40.5% | 10.7% | 33.1% | 15.8% | 33.9% |
89
+
90
+ ## 3. Dataset Description
91
+
92
+ ### 3.1 Schema
93
+
94
+ | Column | Type | Description |
95
+ | --- | --- | --- |
96
+ | id | int | Unique identifier |
97
+ | sex | categorical (M/F) | Biological sex |
98
+ | age_months | float | Age in months (0-23.9) |
99
+ | region_type | categorical | Urban or rural |
100
+ | ses_quintile | int (1-5) | Socioeconomic status quintile (1=poorest) |
101
+ | maternal_education | categorical | None, primary, secondary, tertiary |
102
+ | distance_to_facility_km | float | Distance to nearest health facility |
103
+ | bcg, opv0-3, penta1-3, pcv1-3, rota1-2, ipv1, mcv1-2 | binary (0/1) | Vaccine dose received |
104
+ | total_basic_doses | int | Sum of BCG+Penta1-3+OPV1-3+MCV1 (max 8) |
105
+ | fully_immunised | binary | All age-appropriate vaccines received |
106
+ | dropout_penta1_penta3 | binary | Received Penta1 but not Penta3 |
107
+ | dropout_penta1_mcv1 | binary | Received Penta1 but not MCV1 |
108
+ | zero_dose | binary | No vaccines received at all |
109
+ | immunisation_status | categorical | fully_immunised / partially_immunised / zero_dose |
110
+
111
+ ## 4. Validation
112
+
113
+ ### 4.1 Diagnostic Plots
114
+
115
+ <p align="center">
116
+ <img src="validation_report.png" alt="Validation Report" width="100%">
117
+ </p>
118
+
119
+ ## 5. Usage
120
+
121
+ ### 5.1 Loading with HuggingFace `datasets`
122
+
123
+ ```python
124
+ from datasets import load_dataset
125
+
126
+ dataset = load_dataset("electricsheepafrica/synthetic-childhood-immunisation-coverage-dropout-WUENIC", "moderate_coverage")
127
+ df = dataset["train"].to_pandas()
128
+ ```
129
+
130
+ ### 5.2 Regenerating
131
+
132
+ ```bash
133
+ pip install numpy pandas matplotlib
134
+ python generate_dataset.py --all-scenarios --n 10000 --seed 42
135
+ python validate_dataset.py
136
+ ```
137
+
138
+ ## 6. Limitations
139
+
140
+ - **Synthetic**: Not real programme data. Not for programme evaluation.
141
+ - **No campaign vaccines**: Only routine EPI; does not model supplementary immunisation activities (SIAs).
142
+ - **Cross-sectional**: Single snapshot; does not capture timeliness or catch-up dynamics.
143
+ - **Simplified equity model**: Real equity determinants are more complex and context-specific.
144
+
145
+ ## 7. References
146
+
147
+ 1. WHO/UNICEF (2023). WUENIC Estimates of National Immunization Coverage.
148
+ 2. Gavi (2023). Zero-dose children: Key data and analytics.
149
+ 3. Restrepo-Méndez MC, et al. (2016). Inequalities in full immunization coverage. *Bull WHO*, 94:794-805.
150
+ 4. Arsenault C, et al. (2017). Equity in antenatal care quality. *Lancet Global Health*, 5(11):e1079-e1088.
151
+ 5. WHO (2022). Immunization Agenda 2030.
152
+ 6. DHS Program. Vaccination module, multiple countries 2015-2023.
153
+
154
+ ## Citation
155
+
156
+ ```bibtex
157
+ @dataset{esa_immunisation_2025,
158
+ title={Synthetic Childhood Immunisation Coverage and Dropout Dataset},
159
+ author={Electric Sheep Africa},
160
+ year={2025},
161
+ publisher={Hugging Face},
162
+ url={https://huggingface.co/datasets/electricsheepafrica/synthetic-childhood-immunisation-coverage-dropout-WUENIC}
163
+ }
164
+ ```
165
+
166
+ ## License
167
+
168
+ [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
data/immunisation_high_coverage.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/immunisation_low_coverage.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/immunisation_moderate_coverage.csv ADDED
The diff for this file is too large to render. See raw diff
 
generate_dataset.py ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Literature-Informed Synthetic Childhood Immunisation Coverage & Dropout Dataset
4
+ ===============================================================================
5
+
6
+ Generates realistic synthetic datasets of childhood immunisation records for
7
+ children aged 0-23 months in LMIC settings, with vaccine-specific coverage,
8
+ dropout indicators, and demographic/contextual variables.
9
+
10
+ Target population: Children aged 0-23 months eligible for routine EPI vaccines
11
+ in LMIC facility and community settings.
12
+
13
+ DAG (Sampling Order):
14
+ 1. sex (root)
15
+ 2. age_months (root)
16
+ 3. region_type (root: urban/rural)
17
+ 4. ses_quintile (root: 1-5)
18
+ 5. maternal_education (root)
19
+ 6. distance_to_facility_km (conditional on region_type)
20
+ 7. base_access_probability (conditional on ses, region, distance, education)
21
+ 8. Individual vaccine doses (conditional on age, access probability, schedule)
22
+ 9. Derived: fully_immunised, dropout indicators, zero-dose status
23
+
24
+ References:
25
+ -----------
26
+ [1] WHO/UNICEF (2023). WHO/UNICEF Estimates of National Immunization Coverage
27
+ (WUENIC). Geneva/New York.
28
+ [2] WHO (2023). Global Immunization Data. Immunization Dashboard.
29
+ [3] Gavi (2023). Zero-dose children: Key data and analytics.
30
+ [4] DHS Program. Demographic and Health Surveys, vaccination module,
31
+ multiple countries 2015-2023.
32
+ [5] Restrepo-Méndez MC, et al. (2016). Inequalities in full immunization
33
+ coverage: trends in low- and middle-income countries. Bull WHO, 94:794-805.
34
+ [6] WHO (2022). Immunization Agenda 2030. Geneva.
35
+ [7] Arsenault C, et al. (2017). Equity in antenatal care quality: an analysis
36
+ of 91 national household surveys. Lancet Global Health, 5(11):e1079-e1088.
37
+ [8] WHO (2023). WHO recommendations for routine immunization - summary tables.
38
+ """
39
+
40
+ import numpy as np
41
+ import pandas as pd
42
+ import argparse
43
+ import os
44
+
45
+ # ============================================================
46
+ # SECTION 1: Literature-Informed Parameters
47
+ # ============================================================
48
+
49
+ # --- EPI Schedule (WHO Expanded Programme on Immunization) ---
50
+ # Source: WHO (2023) Routine immunization summary tables
51
+ # Format: vaccine -> {dose: eligible_age_weeks}
52
+ EPI_SCHEDULE = {
53
+ 'bcg': {1: 0}, # At birth
54
+ 'opv': {0: 0, 1: 6, 2: 10, 3: 14}, # OPV0 at birth, then 6/10/14 weeks
55
+ 'penta': {1: 6, 2: 10, 3: 14}, # DTP-HepB-Hib at 6/10/14 weeks
56
+ 'pcv': {1: 6, 2: 10, 3: 14}, # Pneumococcal conjugate
57
+ 'rota': {1: 6, 2: 10}, # Rotavirus (2-dose schedule)
58
+ 'measles':{1: 39, 2: 65}, # MCV1 at 9 months, MCV2 at 15 months
59
+ 'ipv': {1: 14}, # Inactivated polio at 14 weeks
60
+ }
61
+
62
+ # Convert weeks to months for age eligibility
63
+ def weeks_to_months(w):
64
+ return w / 4.33
65
+
66
+ # --- Coverage Levels by Scenario ---
67
+ # Source: WUENIC 2023, DHS pooled estimates
68
+ # These are BASE coverage probabilities for each antigen (dose 1 or single dose)
69
+ SCENARIOS = {
70
+ 'high_coverage': {
71
+ 'description': 'Well-performing LMIC (e.g., Rwanda, Bangladesh urban)',
72
+ 'bcg_coverage': 0.96, # WUENIC 2023: 85-99%
73
+ 'penta1_coverage': 0.95, # WUENIC: 90-98%
74
+ 'penta3_coverage': 0.88, # WUENIC: 82-95%
75
+ 'mcv1_coverage': 0.90, # WUENIC: 85-95%
76
+ 'mcv2_coverage': 0.78, # WUENIC: 60-85%
77
+ 'zero_dose_rate': 0.03, # Gavi 2023: 2-5% in high-coverage
78
+ 'dropout_penta13': 0.07, # 5-10%
79
+ 'urban_pct': 0.45,
80
+ },
81
+ 'moderate_coverage': {
82
+ 'description': 'Average LMIC (e.g., Kenya, Ghana, Senegal)',
83
+ 'bcg_coverage': 0.89,
84
+ 'penta1_coverage': 0.87,
85
+ 'penta3_coverage': 0.78,
86
+ 'mcv1_coverage': 0.80,
87
+ 'mcv2_coverage': 0.55,
88
+ 'zero_dose_rate': 0.10, # Gavi 2023: 8-15%
89
+ 'dropout_penta13': 0.12,
90
+ 'urban_pct': 0.35,
91
+ },
92
+ 'low_coverage': {
93
+ 'description': 'Under-performing / conflict (e.g., CAR, South Sudan, Chad)',
94
+ 'bcg_coverage': 0.68,
95
+ 'penta1_coverage': 0.65,
96
+ 'penta3_coverage': 0.48,
97
+ 'mcv1_coverage': 0.52,
98
+ 'mcv2_coverage': 0.28,
99
+ 'zero_dose_rate': 0.25, # Gavi 2023: 20-35% in fragile states
100
+ 'dropout_penta13': 0.25,
101
+ 'urban_pct': 0.25,
102
+ },
103
+ }
104
+
105
+ # --- Equity Gradients ---
106
+ # Source: Restrepo-Méndez 2016, DHS equity analyses
107
+ # Coverage ratio: richest quintile / poorest quintile
108
+ # Typical equity ratio: 1.2-2.5x depending on setting
109
+ SES_COVERAGE_MULTIPLIER = {
110
+ 1: 0.65, # Poorest quintile
111
+ 2: 0.80,
112
+ 3: 1.00, # Middle (reference)
113
+ 4: 1.15,
114
+ 5: 1.30, # Richest quintile
115
+ }
116
+
117
+ EDUCATION_COVERAGE_MULTIPLIER = {
118
+ 'none': 0.70,
119
+ 'primary': 0.85,
120
+ 'secondary': 1.05,
121
+ 'tertiary': 1.20,
122
+ }
123
+
124
+ REGION_COVERAGE_MULTIPLIER = {
125
+ 'urban': 1.10,
126
+ 'rural': 0.90,
127
+ }
128
+
129
+ # Maternal education distribution by SES (DHS patterns)
130
+ EDUCATION_BY_SES = {
131
+ 1: {'none': 0.50, 'primary': 0.35, 'secondary': 0.13, 'tertiary': 0.02},
132
+ 2: {'none': 0.30, 'primary': 0.40, 'secondary': 0.25, 'tertiary': 0.05},
133
+ 3: {'none': 0.15, 'primary': 0.35, 'secondary': 0.40, 'tertiary': 0.10},
134
+ 4: {'none': 0.08, 'primary': 0.25, 'secondary': 0.47, 'tertiary': 0.20},
135
+ 5: {'none': 0.03, 'primary': 0.12, 'secondary': 0.45, 'tertiary': 0.40},
136
+ }
137
+
138
+
139
+ # ============================================================
140
+ # SECTION 2: Utility Functions
141
+ # ============================================================
142
+
143
+ def compute_individual_access(ses, region, education, distance, scenario_base, rng):
144
+ """Compute individual-level access probability from equity determinants."""
145
+ base = scenario_base
146
+ ses_mult = SES_COVERAGE_MULTIPLIER[ses]
147
+ edu_mult = EDUCATION_COVERAGE_MULTIPLIER[education]
148
+ reg_mult = REGION_COVERAGE_MULTIPLIER[region]
149
+ # Distance penalty: each km reduces probability slightly
150
+ dist_penalty = max(0, 1.0 - distance * 0.012)
151
+ # Individual random effect (unobserved factors)
152
+ individual_effect = rng.normal(1.0, 0.08)
153
+ p = base * ses_mult * edu_mult * reg_mult * dist_penalty * individual_effect
154
+ return np.clip(p, 0.01, 0.99)
155
+
156
+
157
+ def vaccine_received(age_months, eligible_age_months, access_prob, prev_dose_received, rng):
158
+ """Determine if a vaccine dose was received given age, eligibility, access."""
159
+ if age_months < eligible_age_months:
160
+ return 0 # Too young
161
+ if not prev_dose_received:
162
+ return 0 # Can't get dose 3 without dose 2 (sequential)
163
+ # Timeliness decay: probability decreases if very late
164
+ months_since_eligible = age_months - eligible_age_months
165
+ timeliness_factor = 1.0 if months_since_eligible < 3 else 0.90
166
+ p = access_prob * timeliness_factor
167
+ return 1 if rng.random() < p else 0
168
+
169
+
170
+ # ============================================================
171
+ # SECTION 3: Main Generator
172
+ # ============================================================
173
+
174
+ def generate_immunisation_dataset(n=10000, seed=42, scenario='moderate_coverage'):
175
+ rng = np.random.default_rng(seed)
176
+ sc = SCENARIOS[scenario]
177
+
178
+ # ── Step 1: Sex ──
179
+ sex = rng.choice(['M', 'F'], size=n, p=[0.512, 0.488])
180
+
181
+ # ── Step 2: Age (months, 0-23) ──
182
+ age_months = rng.uniform(0, 23.9, n)
183
+ age_months = np.round(age_months, 1)
184
+
185
+ # ── Step 3: Region type ──
186
+ region_type = rng.choice(['urban', 'rural'], size=n,
187
+ p=[sc['urban_pct'], 1 - sc['urban_pct']])
188
+
189
+ # ── Step 4: SES quintile ──
190
+ ses_quintile = rng.choice([1, 2, 3, 4, 5], size=n,
191
+ p=[0.20, 0.20, 0.20, 0.20, 0.20])
192
+
193
+ # ── Step 5: Maternal education (conditional on SES) ──
194
+ maternal_education = np.empty(n, dtype=object)
195
+ for i in range(n):
196
+ dist = EDUCATION_BY_SES[ses_quintile[i]]
197
+ maternal_education[i] = rng.choice(
198
+ list(dist.keys()), p=list(dist.values()))
199
+
200
+ # ── Step 6: Distance to facility ──
201
+ distance_km = np.zeros(n)
202
+ for i in range(n):
203
+ if region_type[i] == 'urban':
204
+ distance_km[i] = rng.exponential(2.0) # Mean 2km urban
205
+ else:
206
+ distance_km[i] = rng.exponential(8.0) # Mean 8km rural
207
+ distance_km = np.clip(np.round(distance_km, 1), 0.1, 80.0)
208
+
209
+ # ── Step 7: Individual access probability ──
210
+ # Base coverage used as the "system" level factor
211
+ base_cov = (sc['bcg_coverage'] + sc['penta1_coverage'] + sc['mcv1_coverage']) / 3.0
212
+
213
+ access_prob = np.zeros(n)
214
+ for i in range(n):
215
+ access_prob[i] = compute_individual_access(
216
+ ses_quintile[i], region_type[i], maternal_education[i],
217
+ distance_km[i], base_cov, rng)
218
+
219
+ # ── Step 8: Vaccine doses ──
220
+ # Zero-dose children: some children never enter the system
221
+ is_zero_dose = rng.random(n) < (sc['zero_dose_rate'] / access_prob)
222
+ is_zero_dose = is_zero_dose & (rng.random(n) < 0.5) # Soften to realistic rate
223
+
224
+ # BCG (birth dose)
225
+ bcg = np.zeros(n, dtype=int)
226
+ for i in range(n):
227
+ if is_zero_dose[i]:
228
+ continue
229
+ if age_months[i] >= 0:
230
+ bcg[i] = 1 if rng.random() < access_prob[i] * 1.05 else 0
231
+
232
+ # OPV (0, 1, 2, 3)
233
+ opv0 = np.zeros(n, dtype=int)
234
+ opv1 = np.zeros(n, dtype=int)
235
+ opv2 = np.zeros(n, dtype=int)
236
+ opv3 = np.zeros(n, dtype=int)
237
+ for i in range(n):
238
+ if is_zero_dose[i]:
239
+ continue
240
+ opv0[i] = vaccine_received(age_months[i], 0, access_prob[i] * 0.95, True, rng)
241
+ opv1[i] = vaccine_received(age_months[i], weeks_to_months(6),
242
+ access_prob[i], bool(opv0[i]) or rng.random() < 0.3, rng)
243
+ opv2[i] = vaccine_received(age_months[i], weeks_to_months(10),
244
+ access_prob[i] * 0.97, bool(opv1[i]), rng)
245
+ opv3[i] = vaccine_received(age_months[i], weeks_to_months(14),
246
+ access_prob[i] * 0.94, bool(opv2[i]), rng)
247
+
248
+ # Penta (1, 2, 3)
249
+ penta1 = np.zeros(n, dtype=int)
250
+ penta2 = np.zeros(n, dtype=int)
251
+ penta3 = np.zeros(n, dtype=int)
252
+ for i in range(n):
253
+ if is_zero_dose[i]:
254
+ continue
255
+ penta1[i] = vaccine_received(age_months[i], weeks_to_months(6),
256
+ access_prob[i], True, rng)
257
+ penta2[i] = vaccine_received(age_months[i], weeks_to_months(10),
258
+ access_prob[i] * 0.97, bool(penta1[i]), rng)
259
+ penta3[i] = vaccine_received(age_months[i], weeks_to_months(14),
260
+ access_prob[i] * 0.93, bool(penta2[i]), rng)
261
+
262
+ # PCV (1, 2, 3)
263
+ pcv1 = np.zeros(n, dtype=int)
264
+ pcv2 = np.zeros(n, dtype=int)
265
+ pcv3 = np.zeros(n, dtype=int)
266
+ for i in range(n):
267
+ if is_zero_dose[i]:
268
+ continue
269
+ pcv1[i] = vaccine_received(age_months[i], weeks_to_months(6),
270
+ access_prob[i], True, rng)
271
+ pcv2[i] = vaccine_received(age_months[i], weeks_to_months(10),
272
+ access_prob[i] * 0.97, bool(pcv1[i]), rng)
273
+ pcv3[i] = vaccine_received(age_months[i], weeks_to_months(14),
274
+ access_prob[i] * 0.93, bool(pcv2[i]), rng)
275
+
276
+ # Rotavirus (1, 2)
277
+ rota1 = np.zeros(n, dtype=int)
278
+ rota2 = np.zeros(n, dtype=int)
279
+ for i in range(n):
280
+ if is_zero_dose[i]:
281
+ continue
282
+ rota1[i] = vaccine_received(age_months[i], weeks_to_months(6),
283
+ access_prob[i], True, rng)
284
+ rota2[i] = vaccine_received(age_months[i], weeks_to_months(10),
285
+ access_prob[i] * 0.96, bool(rota1[i]), rng)
286
+
287
+ # IPV (1 dose at 14 weeks)
288
+ ipv1 = np.zeros(n, dtype=int)
289
+ for i in range(n):
290
+ if is_zero_dose[i]:
291
+ continue
292
+ ipv1[i] = vaccine_received(age_months[i], weeks_to_months(14),
293
+ access_prob[i], True, rng)
294
+
295
+ # Measles (MCV1 at 9mo, MCV2 at 15mo)
296
+ mcv1 = np.zeros(n, dtype=int)
297
+ mcv2 = np.zeros(n, dtype=int)
298
+ for i in range(n):
299
+ if is_zero_dose[i]:
300
+ continue
301
+ mcv1[i] = vaccine_received(age_months[i], 9.0,
302
+ access_prob[i] * 0.95, True, rng)
303
+ mcv2[i] = vaccine_received(age_months[i], 15.0,
304
+ access_prob[i] * 0.85, bool(mcv1[i]), rng)
305
+
306
+ # ── Step 9: Derived indicators ──
307
+ # Total doses received (out of basic schedule: BCG, Penta1-3, OPV1-3, MCV1 = 8)
308
+ total_basic_doses = bcg + penta1 + penta2 + penta3 + opv1 + opv2 + opv3 + mcv1
309
+
310
+ # Fully immunised for age (all age-appropriate vaccines received)
311
+ fully_immunised = np.zeros(n, dtype=int)
312
+ for i in range(n):
313
+ if age_months[i] < weeks_to_months(6):
314
+ # Only BCG expected
315
+ fully_immunised[i] = int(bcg[i] == 1)
316
+ elif age_months[i] < weeks_to_months(14):
317
+ # BCG + first round (Penta1, OPV1, PCV1, Rota1)
318
+ fully_immunised[i] = int(bcg[i] and penta1[i] and opv1[i])
319
+ elif age_months[i] < 9:
320
+ # All primary series
321
+ fully_immunised[i] = int(bcg[i] and penta3[i] and opv3[i] and pcv3[i])
322
+ elif age_months[i] < 15:
323
+ # Primary + MCV1
324
+ fully_immunised[i] = int(bcg[i] and penta3[i] and opv3[i] and mcv1[i])
325
+ else:
326
+ # Full schedule including MCV2
327
+ fully_immunised[i] = int(bcg[i] and penta3[i] and opv3[i] and mcv1[i] and mcv2[i])
328
+
329
+ # Dropout: Penta1 to Penta3
330
+ dropout_penta13 = np.zeros(n, dtype=int)
331
+ for i in range(n):
332
+ if penta1[i] == 1 and penta3[i] == 0 and age_months[i] >= weeks_to_months(14):
333
+ dropout_penta13[i] = 1
334
+
335
+ # Dropout: Penta1 to MCV1
336
+ dropout_penta1_mcv1 = np.zeros(n, dtype=int)
337
+ for i in range(n):
338
+ if penta1[i] == 1 and mcv1[i] == 0 and age_months[i] >= 9:
339
+ dropout_penta1_mcv1[i] = 1
340
+
341
+ # Zero-dose: no vaccines at all despite being old enough for BCG
342
+ zero_dose = ((bcg + opv0 + penta1 + pcv1 + rota1) == 0).astype(int)
343
+
344
+ # Immunisation status category
345
+ imm_status = np.where(
346
+ zero_dose == 1, 'zero_dose',
347
+ np.where(fully_immunised == 1, 'fully_immunised',
348
+ 'partially_immunised'))
349
+
350
+ # ── Assemble DataFrame ──
351
+ df = pd.DataFrame({
352
+ 'id': np.arange(1, n + 1),
353
+ 'sex': sex,
354
+ 'age_months': age_months,
355
+ 'region_type': region_type,
356
+ 'ses_quintile': ses_quintile,
357
+ 'maternal_education': maternal_education,
358
+ 'distance_to_facility_km': distance_km,
359
+ 'bcg': bcg,
360
+ 'opv0': opv0, 'opv1': opv1, 'opv2': opv2, 'opv3': opv3,
361
+ 'penta1': penta1, 'penta2': penta2, 'penta3': penta3,
362
+ 'pcv1': pcv1, 'pcv2': pcv2, 'pcv3': pcv3,
363
+ 'rota1': rota1, 'rota2': rota2,
364
+ 'ipv1': ipv1,
365
+ 'mcv1': mcv1, 'mcv2': mcv2,
366
+ 'total_basic_doses': total_basic_doses,
367
+ 'fully_immunised': fully_immunised,
368
+ 'dropout_penta1_penta3': dropout_penta13,
369
+ 'dropout_penta1_mcv1': dropout_penta1_mcv1,
370
+ 'zero_dose': zero_dose,
371
+ 'immunisation_status': imm_status,
372
+ })
373
+
374
+ # ── Print summary ──
375
+ # Filter to age-eligible for meaningful stats
376
+ elig_penta = df[df['age_months'] >= weeks_to_months(14) + 1]
377
+ elig_mcv1 = df[df['age_months'] >= 10]
378
+ elig_mcv2 = df[df['age_months'] >= 16]
379
+
380
+ print(f"\n{'='*60}")
381
+ print(f"Childhood Immunisation — {scenario} (n={n}, seed={seed})")
382
+ print(f"{'='*60}")
383
+ print(f"\nCoverage (age-eligible children):")
384
+ print(f" BCG: {df[df['age_months']>=1]['bcg'].mean()*100:.1f}%")
385
+ if len(elig_penta) > 0:
386
+ print(f" Penta1: {elig_penta['penta1'].mean()*100:.1f}%")
387
+ print(f" Penta3: {elig_penta['penta3'].mean()*100:.1f}%")
388
+ if len(elig_mcv1) > 0:
389
+ print(f" MCV1: {elig_mcv1['mcv1'].mean()*100:.1f}%")
390
+ if len(elig_mcv2) > 0:
391
+ print(f" MCV2: {elig_mcv2['mcv2'].mean()*100:.1f}%")
392
+ print(f"\nDropout (Penta1→Penta3): "
393
+ f"{elig_penta['dropout_penta1_penta3'].mean()*100:.1f}%" if len(elig_penta) > 0 else "")
394
+ print(f"Zero-dose (no vaccines, age≥1mo): "
395
+ f"{df[df['age_months']>=1]['zero_dose'].mean()*100:.1f}%")
396
+ print(f"Fully immunised for age: {df['fully_immunised'].mean()*100:.1f}%")
397
+
398
+ # Equity: coverage by SES quintile
399
+ if len(elig_penta) > 0:
400
+ print(f"\nPenta3 by SES quintile:")
401
+ for q in range(1, 6):
402
+ sub = elig_penta[elig_penta['ses_quintile'] == q]
403
+ if len(sub) > 0:
404
+ print(f" Q{q}: {sub['penta3'].mean()*100:.1f}%")
405
+
406
+ return df
407
+
408
+
409
+ # ============================================================
410
+ # SECTION 4: CLI Entry Point
411
+ # ============================================================
412
+
413
+ if __name__ == '__main__':
414
+ parser = argparse.ArgumentParser(
415
+ description='Generate synthetic childhood immunisation dataset')
416
+ parser.add_argument('--scenario', type=str, default='moderate_coverage',
417
+ choices=list(SCENARIOS.keys()))
418
+ parser.add_argument('--n', type=int, default=10000)
419
+ parser.add_argument('--seed', type=int, default=42)
420
+ parser.add_argument('--output', type=str, default=None)
421
+ parser.add_argument('--all-scenarios', action='store_true')
422
+ args = parser.parse_args()
423
+
424
+ os.makedirs('data', exist_ok=True)
425
+
426
+ if args.all_scenarios:
427
+ for sc_name in SCENARIOS:
428
+ df = generate_immunisation_dataset(n=args.n, seed=args.seed, scenario=sc_name)
429
+ out = os.path.join('data', f'immunisation_{sc_name}.csv')
430
+ df.to_csv(out, index=False)
431
+ print(f" → Saved to {out}\n")
432
+ else:
433
+ df = generate_immunisation_dataset(n=args.n, seed=args.seed, scenario=args.scenario)
434
+ out = args.output or os.path.join('data', f'immunisation_{args.scenario}.csv')
435
+ df.to_csv(out, index=False)
436
+ 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,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Validation & Diagnostic Visualization for Childhood Immunisation Dataset."""
3
+
4
+ import pandas as pd
5
+ import numpy as np
6
+ import matplotlib.pyplot as plt
7
+ import os
8
+
9
+ SCENARIOS = ['high_coverage', 'moderate_coverage', 'low_coverage']
10
+
11
+
12
+ def load_scenarios(data_dir='data'):
13
+ dfs = {}
14
+ for sc in SCENARIOS:
15
+ path = os.path.join(data_dir, f'immunisation_{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('Childhood Immunisation Coverage — Validation Report',
24
+ fontsize=16, fontweight='bold', y=0.98)
25
+
26
+ df = dfs.get('moderate_coverage', list(dfs.values())[0])
27
+ elig = df[df['age_months'] >= 4] # Old enough for primary series
28
+
29
+ # Panel 1: Immunisation status
30
+ ax = axes[0, 0]
31
+ status_counts = df['immunisation_status'].value_counts()
32
+ colors = {'fully_immunised': '#2ecc71', 'partially_immunised': '#f39c12',
33
+ 'zero_dose': '#e74c3c'}
34
+ order = ['fully_immunised', 'partially_immunised', 'zero_dose']
35
+ vals = [status_counts.get(s, 0) for s in order]
36
+ ax.bar(range(3), vals, color=[colors[s] for s in order])
37
+ ax.set_xticks(range(3))
38
+ ax.set_xticklabels(['Fully\nImmunised', 'Partially\nImmunised', 'Zero\nDose'])
39
+ for i, v in enumerate(vals):
40
+ ax.text(i, v + 50, f'{v/len(df)*100:.1f}%', ha='center', fontsize=10)
41
+ ax.set_ylabel('Count')
42
+ ax.set_title('Immunisation Status (Moderate Coverage)')
43
+
44
+ # Panel 2: Vaccine coverage cascade
45
+ ax = axes[0, 1]
46
+ vaccines = ['bcg', 'penta1', 'penta2', 'penta3', 'mcv1', 'mcv2']
47
+ elig_ages = [1, 2, 3, 4, 10, 16]
48
+ coverages = []
49
+ for v, min_age in zip(vaccines, elig_ages):
50
+ sub = df[df['age_months'] >= min_age]
51
+ coverages.append(sub[v].mean() * 100 if len(sub) > 0 else 0)
52
+ bars = ax.bar(range(len(vaccines)), coverages, color='#3498db', alpha=0.8)
53
+ ax.set_xticks(range(len(vaccines)))
54
+ ax.set_xticklabels([v.upper() for v in vaccines])
55
+ for i, v in enumerate(coverages):
56
+ ax.text(i, v + 1, f'{v:.0f}%', ha='center', fontsize=9)
57
+ ax.set_ylabel('Coverage (%)')
58
+ ax.set_title('Vaccine Coverage Cascade (age-eligible)')
59
+ ax.set_ylim(0, 105)
60
+
61
+ # Panel 3: Penta3 coverage by SES quintile across scenarios
62
+ ax = axes[1, 0]
63
+ x = np.arange(5)
64
+ width = 0.25
65
+ for i, sc in enumerate(SCENARIOS):
66
+ if sc not in dfs:
67
+ continue
68
+ d = dfs[sc]
69
+ elig_d = d[d['age_months'] >= 4]
70
+ rates = []
71
+ for q in range(1, 6):
72
+ sub = elig_d[elig_d['ses_quintile'] == q]
73
+ rates.append(sub['penta3'].mean() * 100 if len(sub) > 0 else 0)
74
+ ax.bar(x + i * width, rates, width, label=sc.replace('_', ' ').title(),
75
+ alpha=0.8)
76
+ ax.set_xticks(x + width)
77
+ ax.set_xticklabels([f'Q{q}' for q in range(1, 6)])
78
+ ax.set_ylabel('Penta3 Coverage (%)')
79
+ ax.set_title('Penta3 Coverage by Wealth Quintile')
80
+ ax.legend(fontsize=8)
81
+
82
+ # Panel 4: Coverage by urban/rural
83
+ ax = axes[1, 1]
84
+ for rt in ['urban', 'rural']:
85
+ sub = elig[elig['region_type'] == rt]
86
+ if len(sub) == 0:
87
+ continue
88
+ covs = [sub[v].mean() * 100 for v in ['bcg', 'penta1', 'penta3', 'mcv1']]
89
+ ax.plot(['BCG', 'Penta1', 'Penta3', 'MCV1'], covs,
90
+ 'o-', label=rt.title(), linewidth=2, markersize=8)
91
+ ax.set_ylabel('Coverage (%)')
92
+ ax.set_title('Coverage by Urban/Rural')
93
+ ax.legend(fontsize=10)
94
+ ax.set_ylim(0, 100)
95
+
96
+ # Panel 5: Distance vs total doses
97
+ ax = axes[2, 0]
98
+ sample = df.sample(min(3000, len(df)), random_state=42)
99
+ ax.scatter(sample['distance_to_facility_km'], sample['total_basic_doses'],
100
+ alpha=0.3, s=8, c='#3498db')
101
+ ax.set_xlabel('Distance to Facility (km)')
102
+ ax.set_ylabel('Total Basic Doses Received')
103
+ ax.set_title('Distance vs Doses Received')
104
+
105
+ # Panel 6: Cross-scenario zero-dose and fully immunised
106
+ ax = axes[2, 1]
107
+ metrics = ['zero_dose', 'fully_immunised']
108
+ x = np.arange(len(SCENARIOS))
109
+ width = 0.35
110
+ for i, m in enumerate(metrics):
111
+ rates = []
112
+ for sc in SCENARIOS:
113
+ if sc in dfs:
114
+ d = dfs[sc]
115
+ rates.append(d[d['age_months'] >= 1][m].mean() * 100)
116
+ else:
117
+ rates.append(0)
118
+ color = '#e74c3c' if m == 'zero_dose' else '#2ecc71'
119
+ ax.bar(x + i * width, rates, width, label=m.replace('_', ' ').title(),
120
+ color=color, alpha=0.8)
121
+ ax.set_xticks(x + width / 2)
122
+ ax.set_xticklabels([s.replace('_', '\n').title() for s in SCENARIOS], fontsize=8)
123
+ ax.set_ylabel('%')
124
+ ax.set_title('Zero-Dose & Fully Immunised Across Scenarios')
125
+ ax.legend(fontsize=9)
126
+
127
+ # Panel 7: Dropout rates across scenarios
128
+ ax = axes[3, 0]
129
+ for sc in SCENARIOS:
130
+ if sc not in dfs:
131
+ continue
132
+ d = dfs[sc]
133
+ elig_d = d[d['age_months'] >= 4]
134
+ if len(elig_d) == 0:
135
+ continue
136
+ p13 = elig_d['dropout_penta1_penta3'].mean() * 100
137
+ elig_mcv = d[d['age_months'] >= 10]
138
+ pm = elig_mcv['dropout_penta1_mcv1'].mean() * 100 if len(elig_mcv) > 0 else 0
139
+ ax.bar([f'{sc.replace("_", chr(10)).title()}\nPenta1→3',
140
+ f'{sc.replace("_", chr(10)).title()}\nPenta1→MCV1'],
141
+ [p13, pm], alpha=0.7)
142
+ ax.set_ylabel('Dropout Rate (%)')
143
+ ax.set_title('Dropout Rates')
144
+
145
+ # Panel 8: Coverage by maternal education
146
+ ax = axes[3, 1]
147
+ edu_order = ['none', 'primary', 'secondary', 'tertiary']
148
+ for v, color in [('penta3', '#3498db'), ('mcv1', '#e74c3c')]:
149
+ covs = []
150
+ for edu in edu_order:
151
+ sub = elig[elig['maternal_education'] == edu]
152
+ covs.append(sub[v].mean() * 100 if len(sub) > 0 else 0)
153
+ ax.plot(edu_order, covs, 'o-', label=v.upper(), linewidth=2,
154
+ markersize=8, color=color)
155
+ ax.set_xlabel('Maternal Education')
156
+ ax.set_ylabel('Coverage (%)')
157
+ ax.set_title('Coverage by Maternal Education')
158
+ ax.legend(fontsize=10)
159
+
160
+ plt.tight_layout(rect=[0, 0, 1, 0.97])
161
+ plt.savefig(output, dpi=150, bbox_inches='tight')
162
+ print(f'Saved validation report to {output}')
163
+ plt.close()
164
+
165
+
166
+ if __name__ == '__main__':
167
+ dfs = load_scenarios()
168
+ if not dfs:
169
+ print('No data files found in data/')
170
+ else:
171
+ make_report(dfs)
validation_report.png ADDED

Git LFS Details

  • SHA256: e07aae849c1bb1e9883020f73c78a06e62c27cd991d4f270fbd71cf4abf2beee
  • Pointer size: 131 Bytes
  • Size of remote file: 397 kB