| |
| """ |
| Literature-Informed Epilepsy & Neurological Disorders Dataset |
| ============================================================== |
| |
| Generates realistic synthetic records of epilepsy patients in |
| sub-Saharan Africa, including seizure type, diagnosis, AED access, |
| treatment gap, stigma, and outcomes. |
| |
| References (web-searched): |
| ----------- |
| [1] PMC 2012. Epilepsy treatment SSA closing the gap. |
| Prevalence highest in LMIC. >80% not receiving care. |
| [2] PMC 2024. Epilepsy in Africa multifaceted perspective. |
| Phenobarbital only drug widely available. Treatment gap. |
| [3] Lancet Neurology. <0.1 neurologists per 100K in SSA. |
| [4] WHO 2024. Epilepsy fact sheet. 50M worldwide. 80% LMIC. |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| import argparse |
| import os |
|
|
| SCENARIOS = { |
| 'neurology_clinic': { |
| 'description': 'Urban neurology clinic with neurologist, EEG, ' |
| 'CT/MRI, multiple AEDs, surgical evaluation ' |
| '(e.g., university hospitals SA, Kenya, Nigeria)', |
| 'neurologist_available': True, |
| 'eeg_available': True, |
| 'ct_mri_available': True, |
| 'aed_variety': True, |
| 'surgery_available': True, |
| 'treatment_gap': 0.25, |
| }, |
| 'district_hospital': { |
| 'description': 'District hospital with clinical officer, ' |
| 'phenobarbital only, no EEG, no imaging ' |
| '(e.g., district hospitals Malawi, Uganda)', |
| 'neurologist_available': False, |
| 'eeg_available': False, |
| 'ct_mri_available': False, |
| 'aed_variety': False, |
| 'surgery_available': False, |
| 'treatment_gap': 0.55, |
| }, |
| 'rural_health_centre': { |
| 'description': 'Rural health centre, nurse-led, phenobarbital ' |
| 'often stocked out, traditional healers primary ' |
| '(e.g., rural DRC, Niger, CAR)', |
| 'neurologist_available': False, |
| 'eeg_available': False, |
| 'ct_mri_available': False, |
| 'aed_variety': False, |
| 'surgery_available': False, |
| 'treatment_gap': 0.80, |
| }, |
| } |
|
|
|
|
| def generate_dataset(n=10000, seed=42, scenario='district_hospital'): |
| rng = np.random.default_rng(seed) |
| sc = SCENARIOS[scenario] |
|
|
| records = [] |
|
|
| for idx in range(n): |
| rec = {'id': idx + 1} |
|
|
| |
| rec['age'] = max(1, min(85, int(rng.exponential(22) + 5))) |
| rec['sex'] = rng.choice(['M', 'F'], p=[0.52, 0.48]) |
| rec['child'] = 1 if rec['age'] < 15 else 0 |
| rec['urban'] = 1 if rng.random() < 0.30 else 0 |
| rec['education'] = rng.choice( |
| ['none', 'primary', 'secondary', 'tertiary'], |
| p=[0.30, 0.30, 0.28, 0.12]) |
| rec['employed'] = 1 if rng.random() < 0.30 else 0 |
| rec['hiv_positive'] = 1 if rng.random() < 0.06 else 0 |
|
|
| |
| rec['seizure_type'] = rng.choice( |
| ['generalised_tonic_clonic', 'focal', 'focal_to_bilateral', |
| 'absence', 'myoclonic', 'unknown'], |
| p=[0.40, 0.20, 0.15, 0.08, 0.05, 0.12]) |
| if rec['child']: |
| rec['seizure_type'] = rng.choice( |
| ['generalised_tonic_clonic', 'focal', 'absence', |
| 'myoclonic', 'febrile_seizure', 'unknown'], |
| p=[0.30, 0.15, 0.12, 0.08, 0.20, 0.15]) |
|
|
| rec['seizure_frequency_month'] = max(0, int(rng.exponential(3))) |
| rec['age_at_onset'] = max(0, min(rec['age'], int(rng.exponential(12) + 2))) |
| rec['duration_years'] = max(0, rec['age'] - rec['age_at_onset']) |
| rec['status_epilepticus_history'] = 1 if rng.random() < 0.08 else 0 |
|
|
| rec['etiology'] = rng.choice( |
| ['unknown', 'perinatal_injury', 'cns_infection', 'traumatic_brain_injury', |
| 'cerebrovascular', 'brain_tumor', 'genetic', 'febrile'], |
| p=[0.35, 0.15, 0.12, 0.10, 0.08, 0.05, 0.05, 0.10]) |
| if rec['child']: |
| rec['etiology'] = rng.choice( |
| ['unknown', 'perinatal_injury', 'cns_infection', 'febrile', 'genetic'], |
| p=[0.30, 0.25, 0.15, 0.20, 0.10]) |
|
|
| |
| rec['clinical_diagnosis_only'] = 1 |
| rec['eeg_done'] = 0 |
| if sc['eeg_available']: |
| rec['eeg_done'] = 1 if rng.random() < 0.45 else 0 |
| rec['ct_done'] = 0 |
| rec['mri_done'] = 0 |
| if sc['ct_mri_available']: |
| rec['ct_done'] = 1 if rng.random() < 0.35 else 0 |
| rec['mri_done'] = 1 if rng.random() < 0.15 else 0 |
| if rec['eeg_done'] or rec['ct_done'] or rec['mri_done']: |
| rec['clinical_diagnosis_only'] = 0 |
|
|
| rec['neurologist_seen'] = 0 |
| if sc['neurologist_available']: |
| rec['neurologist_seen'] = 1 if rng.random() < 0.55 else 0 |
|
|
| rec['misdiagnosed_as_spiritual'] = 1 if rng.random() < 0.25 else 0 |
|
|
| |
| rec['in_treatment_gap'] = 1 if rng.random() < sc['treatment_gap'] else 0 |
|
|
| rec['aed_prescribed'] = 'none' |
| if not rec['in_treatment_gap']: |
| if sc['aed_variety']: |
| rec['aed_prescribed'] = rng.choice( |
| ['phenobarbital', 'carbamazepine', 'valproate', |
| 'phenytoin', 'levetiracetam', 'lamotrigine'], |
| p=[0.20, 0.25, 0.20, 0.10, 0.15, 0.10]) |
| else: |
| rec['aed_prescribed'] = rng.choice( |
| ['phenobarbital', 'carbamazepine', 'none'], |
| p=[0.65, 0.15, 0.20]) |
|
|
| rec['aed_affordable'] = 0 |
| if rec['aed_prescribed'] != 'none': |
| rec['aed_affordable'] = 1 if rng.random() < 0.50 else 0 |
|
|
| rec['aed_adherent'] = 0 |
| if rec['aed_prescribed'] != 'none' and rec['aed_affordable']: |
| rec['aed_adherent'] = 1 if rng.random() < 0.55 else 0 |
|
|
| rec['aed_stock_out_experienced'] = 0 |
| if rec['aed_prescribed'] != 'none': |
| stockout_p = 0.10 if sc['aed_variety'] else (0.25 if scenario == 'district_hospital' else 0.45) |
| rec['aed_stock_out_experienced'] = 1 if rng.random() < stockout_p else 0 |
|
|
| rec['traditional_healer_consulted'] = 1 if rng.random() < 0.40 else 0 |
| rec['faith_healing_sought'] = 1 if rng.random() < 0.30 else 0 |
|
|
| rec['surgery_evaluated'] = 0 |
| rec['surgery_performed'] = 0 |
| if sc['surgery_available'] and rec['seizure_frequency_month'] > 4: |
| rec['surgery_evaluated'] = 1 if rng.random() < 0.10 else 0 |
| if rec['surgery_evaluated']: |
| rec['surgery_performed'] = 1 if rng.random() < 0.20 else 0 |
|
|
| rec['referred_specialist'] = 0 |
| if not sc['neurologist_available'] and rec['seizure_frequency_month'] > 4: |
| rec['referred_specialist'] = 1 if rng.random() < 0.15 else 0 |
| rec['referral_completed'] = 0 |
| if rec['referred_specialist']: |
| rec['referral_completed'] = 1 if rng.random() < 0.20 else 0 |
|
|
| |
| rec['stigma_experienced'] = 1 if rng.random() < 0.50 else 0 |
| rec['school_exclusion'] = 0 |
| if rec['child'] and rec['stigma_experienced']: |
| rec['school_exclusion'] = 1 if rng.random() < 0.30 else 0 |
| rec['employment_discrimination'] = 0 |
| if not rec['child'] and rec['stigma_experienced']: |
| rec['employment_discrimination'] = 1 if rng.random() < 0.35 else 0 |
| rec['marriage_affected'] = 0 |
| if rec['age'] >= 15 and rec['stigma_experienced']: |
| rec['marriage_affected'] = 1 if rng.random() < 0.25 else 0 |
| rec['depression_comorbid'] = 1 if rng.random() < 0.25 else 0 |
| rec['anxiety_comorbid'] = 1 if rng.random() < 0.20 else 0 |
| rec['conceals_diagnosis'] = 1 if rng.random() < 0.45 else 0 |
|
|
| |
| rec['seizure_free_12m'] = 0 |
| if rec['aed_adherent']: |
| rec['seizure_free_12m'] = 1 if rng.random() < 0.45 else 0 |
| elif rec['aed_prescribed'] != 'none' and not rec['aed_adherent']: |
| rec['seizure_free_12m'] = 1 if rng.random() < 0.10 else 0 |
|
|
| rec['seizure_related_injury'] = 1 if rng.random() < 0.15 else 0 |
| rec['seizure_related_burn'] = 1 if rec['seizure_related_injury'] and rng.random() < 0.30 else 0 |
| rec['seizure_related_drowning'] = 1 if rec['seizure_related_injury'] and rng.random() < 0.10 else 0 |
|
|
| rec['died'] = 0 |
| if rec['status_epilepticus_history'] and rng.random() < 0.05: |
| rec['died'] = 1 |
| elif rec['in_treatment_gap'] and rng.random() < 0.02: |
| rec['died'] = 1 |
|
|
| rec['quality_of_life_impaired'] = 0 |
| if rec['seizure_frequency_month'] > 2 or rec['stigma_experienced'] or rec['depression_comorbid']: |
| rec['quality_of_life_impaired'] = 1 if rng.random() < 0.65 else 0 |
|
|
| records.append(rec) |
|
|
| df = pd.DataFrame(records) |
|
|
| print(f"\n{'='*65}") |
| print(f"Epilepsy — {scenario} (n={n}, seed={seed})") |
| print(f"{'='*65}") |
| print(f"\n Treatment gap: {df['in_treatment_gap'].mean()*100:.1f}%") |
| print(f" AED prescribed: {(df['aed_prescribed']!='none').mean()*100:.1f}%") |
| print(f" Seizure-free 12m: {df['seizure_free_12m'].mean()*100:.1f}%") |
| print(f" Stigma: {df['stigma_experienced'].mean()*100:.1f}%") |
| print(f" Traditional healer: {df['traditional_healer_consulted'].mean()*100:.1f}%") |
|
|
| return df |
|
|
|
|
| if __name__ == '__main__': |
| parser = argparse.ArgumentParser( |
| description='Generate epilepsy dataset') |
| parser.add_argument('--scenario', type=str, default='district_hospital', |
| choices=list(SCENARIOS.keys())) |
| parser.add_argument('--n', type=int, default=10000) |
| parser.add_argument('--seed', type=int, default=42) |
| parser.add_argument('--output', type=str, default=None) |
| parser.add_argument('--all-scenarios', action='store_true') |
| args = parser.parse_args() |
|
|
| os.makedirs('data', exist_ok=True) |
|
|
| if args.all_scenarios: |
| for sc_name in SCENARIOS: |
| df = generate_dataset(n=args.n, seed=args.seed, scenario=sc_name) |
| out = os.path.join('data', f'epilepsy_{sc_name}.csv') |
| df.to_csv(out, index=False) |
| print(f" -> Saved to {out}\n") |
| else: |
| df = generate_dataset(n=args.n, seed=args.seed, scenario=args.scenario) |
| out = args.output or os.path.join('data', f'epilepsy_{args.scenario}.csv') |
| df.to_csv(out, index=False) |
| print(f" -> Saved to {out}") |
|
|