""" Malaria Burden Spatiotemporal Dataset Generator for Nigeria This script generates a synthetic dataset of malaria burden in Nigeria with spatiotemporal resolution, incorporating evidence from recent literature (2024-2025) on malaria epidemiology, climate correlations, and intervention impacts. Parameters Evidence Table: ========================== Parameter | Source | Evidence | DOI --------- | ------ | -------- | --- Total malaria cases (24.5M in 9 months 2025) | Daily Post Nigeria, Nov 2025 | Federal Health Report showing 24.47M confirmed cases Jan-Sept 2025 | N/A Asymptomatic malaria prevalence (33%) | Mukhtar et al. 2025 | Systematic review and meta-analysis of 25 studies | 10.1186/s12936-025-05671-5 Adamawa State forecasted incidence (Table 3) | Bakare et al. 2026 | Time series forecasting with rainfall/temperature associations | 10.1038/s41598-026-38705-2 Seasonal malaria chemoprevention impact (50% reduction) | Ikechukwu et al. 2025 | Plausibility evaluation in 3 implementing states | 10.1186/s12936-025-05604-2 RDT recording accuracy (90.2% agreement) | Atobatele et al. 2025 | Mixed-method evaluation in Oyo & Sokoto States | 10.1186/s12936-025-05601-5 Caregiver malaria knowledge (86.4% good knowledge) | Adeleke et al. 2025 | Hospital-based cross-sectional study in Southwest Nigeria | 10.1038/s41598-025-22713-9 ITN ownership prevalence (62.6%) | Ogidan et al. 2025 | Analysis of 2021 Nigeria Malaria Indicator Survey | 10.1186/s12936-025-05314-9 Climate-malaria association (rainfall/temperature) | Bakare et al. 2026 | Adamawa State climate-malaria modeling | 10.1038/s41598-026-38705-2 National Malaria Strategic Plan (2021-2025) | Federal Ministry of Health Nigeria | Policy document guiding interventions | N/A WHO Nigeria Malaria Profile (2024) | World Health Organization | Country-specific malaria epidemiology | N/A DAG Structure: ============== state/lga -> year/month -> climate_variables -> malaria_cases -> intervention_effects -> reporting_quality Climate variables influence malaria transmission through mosquito breeding and survival. Interventions (SMC, IRS) modify case detection and reporting. Reporting quality affects observed vs true case counts. Usage: ------ python generate_dataset.py --scenario low_burden --seed 42 python generate_dataset.py --scenario moderate --seed 43 python generate_dataset.py --scenario high --seed 44 Outputs: -------- CSV files saved to ./dataset/ directory: - malaria_burden_low_burden_seed42.csv - malaria_burden_moderate_seed43.csv - malaria_burden_high_seed44.csv """ import numpy as np import pandas as pd import os import argparse from datetime import datetime, timedelta # Nigerian states and LGAs (simplified for demonstration) NIGERIAN_STATES = [ 'Abia', 'Adamawa', 'Akwa Ibom', 'Anambra', 'Bauchi', 'Bayelsa', 'Benue', 'Borno', 'Cross River', 'Delta', 'Ebonyi', 'Edo', 'Ekiti', 'Enugu', 'Gombe', 'Imo', 'Jigawa', 'Kaduna', 'Kano', 'Katsina', 'Kebbi', 'Kogi', 'Kwara', 'Lagos', 'Nasarawa', 'Niger', 'Ogun', 'Ondo', 'Osun', 'Oyo', 'Plateau', 'Rivers', 'Sokoto', 'Taraba', 'Yobe', 'Zamfara', 'FCT Abuja' ] # LGAs per state (simplified - 3 LGAs per state for demonstration) LGAs_PER_STATE = 3 # Seasonal patterns SEASONS = { 'dry': [11, 12, 1, 2, 3], # Nov-Mar 'rainy': [4, 5, 6, 7, 8, 9, 10], # Apr-Oct 'harmattan': [12, 1, 2] # Dec-Feb (subset of dry season) } def generate_climate_data(year, month, state_idx): """Generate climate data based on seasonal patterns and state characteristics""" # Base climate values with state-specific variation base_rainfall = 100 + (state_idx % 10) * 10 # State-specific base base_temp = 27 + (state_idx % 5) * 0.5 # State-specific base # Seasonal adjustment if month in SEASONS['rainy']: rainfall_mm = base_rainfall * np.random.uniform(1.5, 3.0) temp_avg_c = base_temp * np.random.uniform(0.95, 1.05) elif month in SEASONS['harmattan']: rainfall_mm = base_rainfall * np.random.uniform(0.1, 0.3) temp_avg_c = base_temp * np.random.uniform(0.9, 1.0) else: # dry season rainfall_mm = base_rainfall * np.random.uniform(0.2, 0.8) temp_avg_c = base_temp * np.random.uniform(1.0, 1.1) # Vegetation index (NDVI-like, 0-1 range) vegetation_index = np.clip(0.3 + 0.5 * (rainfall_mm / (base_rainfall * 3)), 0, 1) return { 'rainfall_mm': max(0, rainfall_mm + np.random.normal(0, 5)), 'temperature_avg_c': max(15, min(40, temp_avg_c + np.random.normal(0, 1))), 'vegetation_index': max(0, min(1, vegetation_index + np.random.normal(0, 0.05))) } def determine_season(month): """Determine season based on month""" if month in SEASONS['rainy']: return 'rainy' elif month in SEASONS['harmattan']: return 'harmattan' else: return 'dry' def generate_intervention_flag(state, year, month): """Generate intervention flags based on historical SMC campaigns""" # SMC typically implemented May-October in eligible states smc_eligible_states = [ 'Adamawa', 'Bauchi', 'Borno', 'Gombe', 'Jigawa', 'Kaduna', 'Kano', 'Katsina', 'Kebbi', 'Kogi', 'Kwara', 'Nasarawa', 'Niger', 'Sokoto', 'Yobe', 'Zamfara', 'FCT Abuja' ] # SMC campaigns typically May-October if state in smc_eligible_states and month in [5, 6, 7, 8, 9, 10]: # 70% chance of SMC implementation in eligible states during SMC season return np.random.choice([0, 1], p=[0.3, 0.7]) else: # Other interventions (IRS, etc.) - lower probability year-round return np.random.choice([0, 1], p=[0.8, 0.2]) def generate_reporting_quality(state, year): """Generate reporting completeness and timeliness based on state health system strength""" # States with historically better reporting better_reporting_states = ['Lagos', 'FCT Abuja', 'Oyo', 'Rivers', 'Delta'] if state in better_reporting_states: completeness = np.random.beta(8, 2) # Mean ~0.8 timeliness = np.random.beta(7, 3) # Mean ~0.7 else: completeness = np.random.beta(6, 4) # Mean ~0.6 timeliness = np.random.beta(5, 5) # Mean ~0.5 # Some improvement over years 2018-2025 year_factor = min(1.0, (year - 2018) * 0.05) completeness = min(0.95, completeness + year_factor * 0.1) timeliness = min(0.90, timeliness + year_factor * 0.08) return { 'reporting_completeness_pct': completeness * 100, 'timeliness_pct': timeliness * 100 } def generate_malaria_cases(state_idx, year, month, climate_data, intervention_flag, reporting_quality, scenario_params, rng): """Generate malaria cases based on climate, interventions, and reporting quality""" # Base incidence rate per 1000 population (varied by state) base_incidence = 15 + (state_idx % 10) * 2 # State-specific base # Climate effect on transmission climate_effect = ( 1.0 + 0.008 * climate_data['rainfall_mm'] + # Rainfall increases transmission 0.05 * (climate_data['temperature_avg_c'] - 25) + # Optimal temp ~25-30°C 0.3 * climate_data['vegetation_index'] # Vegetation affects mosquito habitat ) # Seasonal effect season = determine_season(month) if season == 'rainy': seasonal_effect = 1.5 elif season == 'harmattan': seasonal_effect = 0.7 else: # dry seasonal_effect = 0.9 # Intervention effect (SMC reduces cases) intervention_effect = 0.6 if intervention_flag == 1 else 1.0 # 40% reduction when SMC active # Calculate true incidence population_per_lga = 500000 # Average LGA population true_cases = ( base_incidence * climate_effect * seasonal_effect * intervention_effect * population_per_lga / 1000 ) # Apply scenario multiplier true_cases *= scenario_params['case_multiplier'] # Add random variation true_cases = max(0, true_cases * rng.lognormal(0, 0.3)) # Split into symptomatic/asymptomatic based on literature (33% asymptomatic) asymptomatic_proportion = 0.33 + rng.normal(0, 0.05) # Around 33% asymptomatic asymptomatic_proportion = np.clip(asymptomatic_proportion, 0.1, 0.6) asymptomatic_cases = true_cases * asymptomatic_proportion symptomatic_cases = true_cases - asymptomatic_cases # Age stratification (based on typical malaria burden distribution) # Under 5: 20%, 5-15: 30%, 15+: 50% cases_under5 = true_cases * 0.20 * rng.uniform(0.8, 1.2) cases_5to15 = true_cases * 0.30 * rng.uniform(0.8, 1.2) cases_15plus = true_cases - cases_under5 - cases_5to15 cases_15plus = max(0, cases_15plus) # Diagnostic testing (based on RDT accuracy studies) # Suspected cases = true cases * testing propensity testing_propensity = 0.6 + reporting_quality['reporting_completeness_pct']/100 * 0.3 suspected_cases = true_cases * testing_propensity * rng.uniform(0.8, 1.2) # Tested cases (limited by testing capacity) tested_cases = min(suspected_cases, true_cases * 0.8 * reporting_quality['reporting_completeness_pct']/100) # Positive cases based on test accuracy (from Atobatele et al. 2025) # True positive rate ~87%, false positive rate ~6% true_positives = tested_cases * (true_cases/suspected_cases if suspected_cases > 0 else 0) * 0.87 false_positives = tested_cases * 0.06 positive_cases = true_positives + false_positives # Diagnostic method distribution (based on availability) rd_t_positive = positive_cases * 0.6 # RDT most common microscopy_positive = positive_cases * 0.3 # Microscopy less available pcr_positive = positive_cases * 0.1 # PCR least available (reference standard) # Apply reporting completeness and timeliness reporting_factor = ( reporting_quality['reporting_completeness_pct']/100 * reporting_quality['timeliness_pct']/100 ) # Observed cases (what gets reported) total_cases = positive_cases * reporting_factor * rng.uniform(0.9, 1.1) symptomatic_cases = symptomatic_cases * reporting_factor * rng.uniform(0.9, 1.1) asymptomatic_cases = asymptomatic_cases * reporting_factor * rng.uniform(0.9, 1.1) # Confidence intervals for predicted cases (based on forecasting uncertainty) # Using wider CIs for higher burden scenarios ci_width = 0.2 + scenario_params['burden_level'] * 0.1 # 0.2-0.5 predicted_cases_lower_ci = total_cases * (1 - ci_width) predicted_cases_upper_ci = total_cases * (1 + ci_width) return { 'total_cases': max(0, total_cases), 'symptomatic_cases': max(0, symptomatic_cases), 'asymptomatic_cases': max(0, asymptomatic_cases), 'cases_under5': max(0, cases_under5), 'cases_5to15': max(0, cases_5to15), 'cases_15plus': max(0, cases_15plus), 'suspected_cases': max(0, suspected_cases), 'tested_cases': max(0, tested_cases), 'positive_cases': max(0, positive_cases), 'rd_t_positive': max(0, rd_t_positive), 'microscopy_positive': max(0, microscopy_positive), 'pcr_positive': max(0, pcr_positive), 'predicted_cases_lower_ci': max(0, predicted_cases_lower_ci), 'predicted_cases_upper_ci': predicted_cases_upper_ci } def generate_dataset(scenario='moderate', seed=42, n_records=None): """Generate malaria burden dataset""" # Set random seed for reproducibility rng = np.random.RandomState(seed) # Scenario parameters scenario_params = { 'low_burden': {'case_multiplier': 0.7, 'burden_level': 1}, 'moderate': {'case_multiplier': 1.0, 'burden_level': 2}, 'high': {'case_multiplier': 1.4, 'burden_level': 3} } if scenario not in scenario_params: raise ValueError(f"Scenario must be one of {list(scenario_params.keys())}") params = scenario_params[scenario] # Determine number of records if not specified if n_records is None: n_records_map = { 'low_burden': 4000, 'moderate': 5000, 'high': 6000 } n_records = n_records_map[scenario] # Initialize dataset records = [] # Generate data for years 2018-2025 years = list(range(2018, 2026)) months = list(range(1, 13)) # Calculate records per state/LGA/year/month combination total_combinations = len(NIGERIAN_STATES) * LGAs_PER_STATE * len(years) * len(months) records_per_combination = max(1, n_records // total_combinations) record_id = 1 for state_idx, state in enumerate(NIGERIAN_STATES): for lga_idx in range(LGAs_PER_STATE): lga = f"{state}_LGA{lga_idx+1}" for year in years: for month in months: # Generate multiple records per combination to reach target n for _ in range(records_per_combination): if len(records) >= n_records: break # Generate climate data climate_data = generate_climate_data(year, month, state_idx) # Determine season season = determine_season(month) # Generate intervention flag intervention_flag = generate_intervention_flag(state, year, month) # Generate reporting quality reporting_quality = generate_reporting_quality(state, year) # Generate malaria cases cases = generate_malaria_cases( state_idx, year, month, climate_data, intervention_flag, reporting_quality, params, rng ) # Determine data source (mix of routine, survey, sentinel) source_weights = [0.6, 0.3, 0.1] # routine, survey, sentinel source = rng.choice(['routine', 'survey', 'sentinel'], p=source_weights) # Create record record = { 'record_id': record_id, 'state': state, 'lga': lga, 'year': year, 'month': month, **climate_data, 'season': season, 'intervention_flag': intervention_flag, **reporting_quality, 'source': source, **cases } records.append(record) record_id += 1 # Convert to DataFrame df = pd.DataFrame(records) # Shuffle the dataset df = df.sample(n=len(df), random_state=seed).reset_index(drop=True) # Re-index record_id df['record_id'] = range(1, len(df) + 1) # Limit to exactly n_records if we generated more if len(df) > n_records: df = df.head(n_records) return df def main(): parser = argparse.ArgumentParser(description='Generate malaria burden spatiotemporal dataset') parser.add_argument('--scenario', type=str, default='moderate', choices=['low_burden', 'moderate', 'high'], help='Burden scenario to generate') parser.add_argument('--seed', type=int, default=42, help='Random seed for reproducibility') parser.add_argument('--n_records', type=int, default=None, help='Number of records to generate (overrides scenario default)') parser.add_argument('--output_dir', type=str, default='./dataset', help='Directory to save output CSV files') args = parser.parse_args() # Create output directory if it doesn't exist os.makedirs(args.output_dir, exist_ok=True) # Generate dataset print(f"Generating {args.scenario} burden dataset with seed {args.seed}...") df = generate_dataset(args.scenario, args.seed, args.n_records) # Save to CSV output_file = os.path.join( args.output_dir, f"malaria_burden_{args.scenario}_seed{args.seed}.csv" ) df.to_csv(output_file, index=False) print(f"Dataset saved to {output_file}") print(f"Shape: {df.shape}") print(f"Columns: {list(df.columns)}") print(f"\nFirst few rows:") print(df.head()) # Print summary statistics print(f"\nSummary statistics:") print(f"Total cases range: {df['total_cases'].min():.0f} - {df['total_cases'].max():.0f}") print(f"Asymptomatic proportion: {df['asymptomatic_cases'].sum() / df['total_cases'].sum():.1%}") print(f"Under 5 proportion: {df['cases_under5'].sum() / df['total_cases'].sum():.1%}") if __name__ == "__main__": main()