#!/usr/bin/env python3 """ Literature-Informed Pharmaceutical Regulatory Capacity Dataset ================================================================ Each record = ONE national medicines regulatory authority (NMRA) assessment. Sources (v2.0): [1] WHO Global Benchmarking Tool (GBT). Maturity Levels ML1-ML4. Only 4 African NRAs at ML3+ (Tanzania, Ghana, Nigeria, Egypt). [2] WHO (2023). 54 African countries, ~30% have basic regulatory capacity (ML2+). Most at ML1 (no formal system). [3] African Medicines Regulatory Harmonization (AMRH) initiative. AU/NEPAD driving harmonization across RECs. [4] Lancet Commission on Essential Medicines (2017). Regulatory capacity directly correlates with SF medicine prevalence. [5] WHO (2022). Global landscape of NRA maturity. 67% of LICs at ML1, only 7% of LICs at ML3+. """ import numpy as np import pandas as pd import argparse import os REGULATORY_FUNCTIONS = [ 'registration_marketing_authorization', 'pharmacovigilance', 'market_surveillance_control', 'licensing_establishment', 'regulatory_inspection', 'laboratory_access_testing', 'clinical_trial_oversight', 'import_export_control', 'lot_release_biologicals', ] SCENARIOS = { 'ml3_ml4_advanced': { 'maturity_level': 'ML3_ML4', 'staff_total': 250, 'budget_usd_millions': 8.0, 'registered_products': 8000, 'inspection_coverage': 0.70, 'PMS_sample_rate': 0.15, 'sf_detection_rate': 0.08, 'dossier_backlog_months': 6, 'WHO_listed_authority': True, 'AMRH_participation': True, 'digital_systems': True, 'lab_ISO_accredited': True, }, 'ml2_developing': { 'maturity_level': 'ML2', 'staff_total': 80, 'budget_usd_millions': 1.5, 'registered_products': 3000, 'inspection_coverage': 0.25, 'PMS_sample_rate': 0.05, 'sf_detection_rate': 0.22, 'dossier_backlog_months': 18, 'WHO_listed_authority': False, 'AMRH_participation': True, 'digital_systems': False, 'lab_ISO_accredited': False, }, 'ml1_minimal': { 'maturity_level': 'ML1', 'staff_total': 15, 'budget_usd_millions': 0.2, 'registered_products': 500, 'inspection_coverage': 0.05, 'PMS_sample_rate': 0.01, 'sf_detection_rate': 0.40, 'dossier_backlog_months': 36, 'WHO_listed_authority': False, 'AMRH_participation': False, 'digital_systems': False, 'lab_ISO_accredited': False, }, } def generate_dataset(n=10000, seed=42, scenario='ml2_developing'): rng = np.random.default_rng(seed) sc = SCENARIOS[scenario] records = [] for idx in range(n): rec = {'id': idx + 1} rec['country_id'] = f"NRA_{rng.integers(1, 55):03d}" rec['maturity_level'] = sc['maturity_level'] rec['WHO_region'] = rng.choice( ['AFRO_West', 'AFRO_East', 'AFRO_Central', 'AFRO_Southern'], p=[0.35, 0.30, 0.20, 0.15]) rec['country_income'] = rng.choice( ['low_income', 'lower_middle', 'upper_middle'], p=[0.55, 0.35, 0.10] if scenario == 'ml1_minimal' else ([0.25, 0.50, 0.25] if scenario == 'ml2_developing' else [0.05, 0.35, 0.60])) rec['population_millions'] = round(np.clip( rng.lognormal(3.0, 0.8), 1, 220), 1) rec['staff_total'] = max(3, int(rng.poisson(sc['staff_total']))) rec['pharmacists_on_staff'] = max(1, int(rec['staff_total'] * np.clip( rng.normal(0.40, 0.10), 0.15, 0.70))) rec['staff_per_million_pop'] = round(rec['staff_total'] / rec['population_millions'], 2) rec['budget_usd_millions'] = round(max(0.01, rng.lognormal( np.log(sc['budget_usd_millions']), 0.4)), 2) rec['budget_per_capita_usd'] = round( rec['budget_usd_millions'] * 1e6 / (rec['population_millions'] * 1e6), 4) rec['donor_funding_share'] = round(np.clip( rng.beta(2, 5) if scenario == 'ml3_ml4_advanced' else (rng.beta(3, 3) if scenario == 'ml2_developing' else rng.beta(5, 2)), 0, 0.95), 2) rec['registered_products'] = max(50, int(rng.poisson(sc['registered_products']))) rec['new_registrations_per_year'] = max(5, int(rng.poisson( sc['registered_products'] * 0.08))) rec['dossier_backlog_months'] = max(1, int(rng.exponential( sc['dossier_backlog_months'] * 0.7))) rec['median_registration_days'] = max(30, int(rng.normal( 90 if scenario == 'ml3_ml4_advanced' else (360 if scenario == 'ml2_developing' else 720), 60))) rec['inspection_coverage_pct'] = round(np.clip( rng.normal(sc['inspection_coverage'] * 100, 10), 1, 95), 1) rec['inspections_per_year'] = max(1, int(rng.poisson( sc['inspection_coverage'] * sc['registered_products'] * 0.01))) rec['GMP_compliant_manufacturers_pct'] = round(np.clip( rng.normal(60 if scenario == 'ml3_ml4_advanced' else (25 if scenario == 'ml2_developing' else 5), 12), 0, 95), 1) rec['PMS_samples_tested_per_year'] = max(0, int(rng.poisson( sc['PMS_sample_rate'] * sc['registered_products']))) rec['PMS_failure_rate_pct'] = round(np.clip( rng.normal(sc['sf_detection_rate'] * 100, 5), 1, 60), 1) rec['market_surveillance_active'] = 1 if rec['PMS_samples_tested_per_year'] > 50 else 0 rec['pharmacovigilance_centre'] = 1 if rng.random() < ( 0.95 if scenario == 'ml3_ml4_advanced' else (0.50 if scenario == 'ml2_developing' else 0.10)) else 0 rec['AEFI_reporting_rate_per_million'] = max(0, int(rng.poisson( 50 if scenario == 'ml3_ml4_advanced' else (10 if scenario == 'ml2_developing' else 1)))) rec['ADR_reports_per_year'] = max(0, int(rng.poisson( 500 if scenario == 'ml3_ml4_advanced' else (50 if scenario == 'ml2_developing' else 5)))) rec['clinical_trial_oversight'] = 1 if rng.random() < ( 0.90 if scenario == 'ml3_ml4_advanced' else (0.30 if scenario == 'ml2_developing' else 0.05)) else 0 rec['active_clinical_trials'] = max(0, int(rng.poisson( 80 if scenario == 'ml3_ml4_advanced' else (15 if scenario == 'ml2_developing' else 1)))) rec['WHO_listed_authority'] = 1 if sc['WHO_listed_authority'] else 0 rec['AMRH_participation'] = 1 if sc['AMRH_participation'] or rng.random() < 0.30 else 0 rec['digital_registration_system'] = 1 if sc['digital_systems'] else ( 1 if rng.random() < 0.15 else 0) rec['lab_ISO_17025_accredited'] = 1 if sc['lab_ISO_accredited'] else ( 1 if rng.random() < 0.05 else 0) rec['import_control_functional'] = 1 if rng.random() < ( 0.85 if scenario == 'ml3_ml4_advanced' else (0.40 if scenario == 'ml2_developing' else 0.10)) else 0 rec['sf_prevalence_estimated_pct'] = round(np.clip( rng.normal(sc['sf_detection_rate'] * 100, 5), 1, 60), 1) rec['regulatory_actions_per_year'] = max(0, int(rng.poisson( 100 if scenario == 'ml3_ml4_advanced' else (15 if scenario == 'ml2_developing' else 2)))) rec['product_recalls_per_year'] = max(0, int(rng.poisson( 20 if scenario == 'ml3_ml4_advanced' else (3 if scenario == 'ml2_developing' else 0.5)))) rec['year'] = rng.choice([2020, 2021, 2022, 2023, 2024], p=[0.10, 0.15, 0.20, 0.25, 0.30]) # Regulatory function scores (0-100) for func in REGULATORY_FUNCTIONS: base = 70 if scenario == 'ml3_ml4_advanced' else ( 35 if scenario == 'ml2_developing' else 10) rec[f'score_{func}'] = int(np.clip(rng.normal(base, 12), 0, 100)) rec['overall_regulatory_score'] = int(np.mean( [rec[f'score_{func}'] for func in REGULATORY_FUNCTIONS])) records.append(rec) df = pd.DataFrame(records) print(f"\n{'='*65}") print(f"Regulatory Capacity — {scenario} (n={n}, seed={seed})") print(f"{'='*65}") print(f" Maturity: {sc['maturity_level']}") print(f" Avg staff: {df['staff_total'].mean():.0f}") print(f" Avg budget: ${df['budget_usd_millions'].mean():.1f}M") print(f" SF prevalence: {df['sf_prevalence_estimated_pct'].mean():.1f}%") print(f" Overall reg score: {df['overall_regulatory_score'].mean():.0f}/100") return df if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--all-scenarios', action='store_true') parser.add_argument('--n', type=int, default=10000) parser.add_argument('--seed', type=int, default=42) args = parser.parse_args() os.makedirs('data', exist_ok=True) if args.all_scenarios: for sc in SCENARIOS: df = generate_dataset(n=args.n, seed=args.seed, scenario=sc) df.to_csv(os.path.join('data', f'reg_capacity_{sc}.csv'), index=False) print(f" -> Saved\n") else: df = generate_dataset(n=args.n, seed=args.seed) df.to_csv(os.path.join('data', 'reg_capacity_ml2_developing.csv'), index=False)