#!/usr/bin/env python3 """ Literature-Informed Synthetic Adolescent Sexual & Reproductive Health Dataset ============================================================================= Generates realistic synthetic records of adolescents aged 10-24 years accessing SRH services in sub-Saharan African settings, including contraception, STI screening, pregnancy, antenatal care, and psychosocial outcomes. Target population: Adolescents and young people (10-24 years) accessing facility-based and community SRH services across SSA. DAG (Sampling Order): 1. age, sex, education, marital_status (roots) 2. sexually_active, age_at_first_sex 3. contraception: type, access, source 4. pregnancy: current, history, outcome 5. sti_screening: HIV, syphilis, chlamydia 6. anc_attendance (if pregnant) 7. psychosocial: GBV, depression screen, support 8. service_outcome References: ----------- [1] WHO (2023). Adolescent health fact sheet. 1.2M adolescent deaths/yr; leading causes: road injury, HIV, self-harm. 21M pregnancies in girls 15-19 in developing regions. [2] Darroch JE, et al. (Guttmacher 2016). Adding it up: costs of meeting contraceptive needs of adolescents in SSA. Unmet need for contraception 60% among 15-19 year olds. [3] DHS/MICS compilations. Median age at first sex: 16-17 years (SSA). Adolescent birth rate: 101/1000 (SSA) vs 44/1000 global. 4+ ANC visits: 50-60% among adolescents. [4] Chandra-Mouli V, et al. (J Adolesc Health 2015). Contraception for adolescents in SSA: systematic review. Modern contraceptive prevalence rate (mCPR) 8-15% among 15-19 in SSA. [5] UNAIDS (2023). Adolescent girls/young women: 4,000 new HIV infections/week in SSA among 15-24 year old women. [6] WHO (2020). Global accelerated action for the health of adolescents (AA-HA!). Comprehensive SRH package. [7] Neal S, et al. (Lancet Glob Health 2020). Adolescent pregnancy outcomes in SSA: higher maternal/neonatal mortality in <18 years. [8] Palermo T, et al. (J Adolesc Health 2019). GBV among adolescents: ~30% of women in SSA experience physical/sexual violence. """ import numpy as np import pandas as pd import argparse import os # ============================================================ # SECTION 1: Literature-Informed Parameters # ============================================================ SCENARIOS = { 'youth_friendly_clinic': { 'description': 'Dedicated youth-friendly SRH clinic with trained ' 'providers, comprehensive services (e.g., Lovelife SA, ' 'Marie Stopes urban clinics)', 'sexually_active_15_19': 0.45, 'sexually_active_20_24': 0.80, 'modern_contraceptive_use': 0.35, # [4] higher in YF clinics 'condom_use_last_sex': 0.50, 'hiv_testing_uptake': 0.70, 'hiv_prevalence_15_24_f': 0.04, 'hiv_prevalence_15_24_m': 0.015, 'sti_prevalence': 0.12, 'adolescent_pregnancy_rate': 0.08, 'anc_4plus_visits': 0.65, 'gbv_prevalence': 0.20, 'depression_screen_positive': 0.18, 'unmet_need_contraception': 0.30, }, 'public_health_facility': { 'description': 'General public health facility, some adolescent ' 'services (e.g., district hospitals Kenya, Tanzania)', 'sexually_active_15_19': 0.40, 'sexually_active_20_24': 0.78, 'modern_contraceptive_use': 0.18, 'condom_use_last_sex': 0.35, 'hiv_testing_uptake': 0.50, 'hiv_prevalence_15_24_f': 0.05, 'hiv_prevalence_15_24_m': 0.02, 'sti_prevalence': 0.15, 'adolescent_pregnancy_rate': 0.12, 'anc_4plus_visits': 0.50, 'gbv_prevalence': 0.28, 'depression_screen_positive': 0.22, 'unmet_need_contraception': 0.50, }, 'rural_limited_access': { 'description': 'Rural setting, limited SRH services, high unmet ' 'need (e.g., rural DRC, Niger, northern Nigeria)', 'sexually_active_15_19': 0.50, # Higher due to early marriage 'sexually_active_20_24': 0.85, 'modern_contraceptive_use': 0.08, 'condom_use_last_sex': 0.15, 'hiv_testing_uptake': 0.25, 'hiv_prevalence_15_24_f': 0.03, 'hiv_prevalence_15_24_m': 0.01, 'sti_prevalence': 0.18, 'adolescent_pregnancy_rate': 0.20, 'anc_4plus_visits': 0.30, 'gbv_prevalence': 0.35, 'depression_screen_positive': 0.28, 'unmet_need_contraception': 0.65, }, } def generate_dataset(n=10000, seed=42, scenario='public_health_facility'): rng = np.random.default_rng(seed) sc = SCENARIOS[scenario] records = [] for idx in range(n): rec = {'id': idx + 1} # ── Step 1: Demographics ── r = rng.random() if r < 0.15: rec['age_years'] = rng.integers(10, 15) elif r < 0.50: rec['age_years'] = rng.integers(15, 18) elif r < 0.80: rec['age_years'] = rng.integers(18, 21) else: rec['age_years'] = rng.integers(21, 25) rec['sex'] = rng.choice(['F', 'M'], p=[0.65, 0.35]) # More females access SRH if rec['age_years'] < 15: rec['education_level'] = rng.choice( ['primary', 'lower_secondary', 'none'], p=[0.50, 0.35, 0.15]) elif rec['age_years'] < 18: rec['education_level'] = rng.choice( ['lower_secondary', 'upper_secondary', 'primary', 'none'], p=[0.40, 0.30, 0.20, 0.10]) else: rec['education_level'] = rng.choice( ['upper_secondary', 'tertiary', 'lower_secondary', 'primary', 'none'], p=[0.30, 0.20, 0.25, 0.15, 0.10]) if rec['age_years'] < 15: rec['marital_status'] = 'never_married' elif rec['age_years'] < 18: rec['marital_status'] = rng.choice( ['never_married', 'married', 'cohabiting'], p=[0.75, 0.15, 0.10]) else: rec['marital_status'] = rng.choice( ['never_married', 'married', 'cohabiting', 'divorced_separated'], p=[0.45, 0.30, 0.15, 0.10]) # Rural: earlier marriage if scenario == 'rural_limited_access' and rec['age_years'] >= 15: if rec['marital_status'] == 'never_married' and rng.random() < 0.15: rec['marital_status'] = 'married' # ── Step 2: Sexual Activity [3] ── if rec['age_years'] < 13: rec['sexually_active'] = 0 elif rec['age_years'] < 15: rec['sexually_active'] = 1 if rng.random() < 0.10 else 0 elif rec['age_years'] < 20: rec['sexually_active'] = 1 if rng.random() < sc['sexually_active_15_19'] else 0 else: rec['sexually_active'] = 1 if rng.random() < sc['sexually_active_20_24'] else 0 if rec['marital_status'] in ('married', 'cohabiting'): rec['sexually_active'] = 1 rec['age_at_first_sex'] = -1 if rec['sexually_active']: lo = 14 hi = max(lo + 1, min(rec['age_years'] + 1, 22)) rec['age_at_first_sex'] = max(12, min(rec['age_years'], rng.integers(lo, hi))) rec['number_sexual_partners_12mo'] = 0 if rec['sexually_active']: rec['number_sexual_partners_12mo'] = max(1, rng.poisson(1.3)) # ── Step 3: Contraception [2][4] ── rec['using_modern_contraceptive'] = 0 rec['contraceptive_method'] = 'none' rec['condom_last_sex'] = 0 rec['unmet_need_contraception'] = 0 if rec['sexually_active']: if rng.random() < sc['modern_contraceptive_use']: rec['using_modern_contraceptive'] = 1 rec['contraceptive_method'] = rng.choice( ['injectable', 'implant', 'oral_pill', 'male_condom', 'iud', 'female_condom'], p=[0.30, 0.25, 0.20, 0.15, 0.05, 0.05]) else: rec['unmet_need_contraception'] = 1 if rng.random() < sc['unmet_need_contraception'] else 0 rec['condom_last_sex'] = 1 if rng.random() < sc['condom_use_last_sex'] else 0 # ── Step 4: Pregnancy [3][7] ── rec['currently_pregnant'] = 0 rec['ever_pregnant'] = 0 rec['number_pregnancies'] = 0 rec['pregnancy_outcome_last'] = 'not_applicable' rec['anc_visits'] = 0 rec['anc_4plus'] = 0 rec['delivery_location'] = 'not_applicable' if rec['sex'] == 'F' and rec['sexually_active']: preg_prob = sc['adolescent_pregnancy_rate'] if rec['age_years'] < 16: preg_prob *= 0.5 elif rec['age_years'] > 20: preg_prob *= 1.3 if rec['using_modern_contraceptive']: preg_prob *= 0.10 rec['currently_pregnant'] = 1 if rng.random() < preg_prob else 0 rec['ever_pregnant'] = rec['currently_pregnant'] # Previous pregnancies if rec['age_years'] >= 16: if rng.random() < preg_prob * 2: rec['ever_pregnant'] = 1 rec['number_pregnancies'] = min(rng.poisson(1.0) + 1, 5) if rec['ever_pregnant'] and not rec['currently_pregnant']: rec['pregnancy_outcome_last'] = rng.choice( ['live_birth', 'miscarriage', 'stillbirth', 'abortion'], p=[0.70, 0.12, 0.05, 0.13]) if rec['currently_pregnant'] or rec['ever_pregnant']: rec['anc_visits'] = max(0, rng.poisson(3.0)) rec['anc_4plus'] = 1 if rec['anc_visits'] >= 4 else 0 if not rec['currently_pregnant'] and rec['ever_pregnant']: rec['delivery_location'] = rng.choice( ['health_facility', 'home', 'tba'], p=[0.55, 0.30, 0.15]) # ── Step 5: STI/HIV Screening [5] ── rec['hiv_tested_12mo'] = 0 rec['hiv_status'] = 'unknown' rec['sti_screened'] = 0 rec['sti_positive'] = 0 rec['sti_type'] = 'none' if rec['sexually_active']: rec['hiv_tested_12mo'] = 1 if rng.random() < sc['hiv_testing_uptake'] else 0 if rec['hiv_tested_12mo']: if rec['sex'] == 'F': hiv_prob = sc['hiv_prevalence_15_24_f'] else: hiv_prob = sc['hiv_prevalence_15_24_m'] rec['hiv_status'] = 'positive' if rng.random() < hiv_prob else 'negative' rec['sti_screened'] = 1 if rng.random() < 0.30 else 0 if rec['sti_screened']: if rng.random() < sc['sti_prevalence']: rec['sti_positive'] = 1 rec['sti_type'] = rng.choice( ['chlamydia', 'gonorrhoea', 'syphilis', 'trichomoniasis', 'hpv'], p=[0.30, 0.25, 0.10, 0.20, 0.15]) # ── Step 6: Psychosocial [8] ── rec['gbv_screened'] = 1 if rng.random() < 0.40 else 0 rec['gbv_positive'] = 0 if rec['gbv_screened']: gbv_prob = sc['gbv_prevalence'] if rec['sex'] == 'F': gbv_prob *= 1.5 rec['gbv_positive'] = 1 if rng.random() < min(gbv_prob, 0.50) else 0 rec['depression_screened'] = 1 if rng.random() < 0.35 else 0 rec['depression_positive'] = 0 if rec['depression_screened']: rec['depression_positive'] = 1 if rng.random() < sc['depression_screen_positive'] else 0 rec['peer_support_accessed'] = 1 if rng.random() < 0.25 else 0 # ── Step 7: Service Outcome ── rec['received_srh_counselling'] = 1 if rng.random() < 0.60 else 0 rec['referred_to_higher_level'] = 0 if rec['sti_positive'] or rec['gbv_positive'] or (rec['hiv_status'] == 'positive'): rec['referred_to_higher_level'] = 1 if rng.random() < 0.50 else 0 if rec['currently_pregnant'] and rec['age_years'] < 16: rec['referred_to_higher_level'] = 1 if rng.random() < 0.70 else 0 rec['satisfaction'] = rng.choice( ['very_satisfied', 'satisfied', 'neutral', 'dissatisfied'], p=[0.15, 0.45, 0.25, 0.15]) records.append(rec) df = pd.DataFrame(records) # ── Print Summary ── print(f"\n{'='*65}") print(f"Adolescent SRH — {scenario} (n={n}, seed={seed})") print(f"{'='*65}") print(f"\n Female: {(df['sex']=='F').mean()*100:.1f}%") print(f" Sexually active: {df['sexually_active'].mean()*100:.1f}%") print(f" Modern contraceptive use (sexually active): " f"{df[df['sexually_active']==1]['using_modern_contraceptive'].mean()*100:.1f}%") print(f" Condom last sex: {df[df['sexually_active']==1]['condom_last_sex'].mean()*100:.1f}%") print(f" Unmet need: {df[df['sexually_active']==1]['unmet_need_contraception'].mean()*100:.1f}%") females = df[df['sex'] == 'F'] print(f"\n Currently pregnant (F): {females['currently_pregnant'].mean()*100:.1f}%") print(f" Ever pregnant (F): {females['ever_pregnant'].mean()*100:.1f}%") preg = females[females['ever_pregnant'] == 1] if len(preg) > 0: print(f" ANC 4+: {preg['anc_4plus'].mean()*100:.1f}%") print(f"\n HIV tested (sexually active): " f"{df[df['sexually_active']==1]['hiv_tested_12mo'].mean()*100:.1f}%") tested = df[df['hiv_tested_12mo'] == 1] if len(tested) > 0: print(f" HIV+: {(tested['hiv_status']=='positive').mean()*100:.1f}%") print(f" STI positive: {df[df['sti_screened']==1]['sti_positive'].mean()*100:.1f}%") print(f"\n GBV positive: {df[df['gbv_screened']==1]['gbv_positive'].mean()*100:.1f}%") print(f" Depression screen+: {df[df['depression_screened']==1]['depression_positive'].mean()*100:.1f}%") return df if __name__ == '__main__': parser = argparse.ArgumentParser( description='Generate synthetic adolescent SRH dataset') parser.add_argument('--scenario', type=str, default='public_health_facility', 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'adolescent_srh_{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'adolescent_srh_{args.scenario}.csv') df.to_csv(out, index=False) print(f" → Saved to {out}")