"""Generate synthetic disability rights & social protection dataset for SSA. Research-based parameterization: - UN CRPD: 46 of 54 African countries ratified; implementation gaps in legislation, accessibility, employment, education. - World Bank: Disability associated with 20% higher poverty; social protection coverage <10% for persons with disabilities in SSA. - African Disability Protocol: Adopted 2018; disability allowances, employment quotas, inclusive education mandated but poorly enforced. """ from __future__ import annotations from pathlib import Path import numpy as np import pandas as pd SEED = 42 N_PER_SCENARIO = 10_000 YEAR_RANGE = np.arange(2010, 2025) YEAR_WEIGHTS = np.linspace(0.85, 1.3, len(YEAR_RANGE)) YEAR_WEIGHTS = YEAR_WEIGHTS / YEAR_WEIGHTS.sum() SCENARIOS = { "urban_formal_sector": { "setting_probs": {"capital_city": 0.35, "large_town": 0.25, "industrial_zone": 0.20, "commercial_centre": 0.20}, "disability_probs": {"physical_mobility": 0.28, "visual": 0.15, "hearing": 0.12, "intellectual": 0.12, "mental_health": 0.12, "multiple": 0.12, "other": 0.09}, "social_protection_pct": 0.15, "employment_rate": 0.20, "school_completion_pct": 0.40, "dpo_membership_pct": 0.12, "legal_awareness_pct": 0.20, }, "periurban_informal": { "setting_probs": {"peri_urban": 0.35, "small_town": 0.25, "informal_settlement": 0.25, "trading_centre": 0.15}, "disability_probs": {"physical_mobility": 0.30, "visual": 0.14, "hearing": 0.12, "intellectual": 0.12, "mental_health": 0.12, "multiple": 0.12, "other": 0.08}, "social_protection_pct": 0.06, "employment_rate": 0.10, "school_completion_pct": 0.20, "dpo_membership_pct": 0.05, "legal_awareness_pct": 0.08, }, "rural_subsistence": { "setting_probs": {"rural_village": 0.40, "farming_community": 0.25, "pastoral_area": 0.15, "remote_community": 0.20}, "disability_probs": {"physical_mobility": 0.30, "visual": 0.15, "hearing": 0.12, "intellectual": 0.12, "mental_health": 0.10, "multiple": 0.12, "other": 0.09}, "social_protection_pct": 0.03, "employment_rate": 0.05, "school_completion_pct": 0.08, "dpo_membership_pct": 0.02, "legal_awareness_pct": 0.03, }, } SCENARIO_FILES = { "urban_formal_sector": "drsp_urban.csv", "periurban_informal": "drsp_periurban.csv", "rural_subsistence": "drsp_rural.csv", } def _choice(rng, prob_map): keys = list(prob_map.keys()) weights = np.array(list(prob_map.values()), dtype=float) weights = weights / weights.sum() return rng.choice(keys, p=weights) def _simulate_scenario(name, params, seed): rng = np.random.default_rng(seed) records = [] for idx in range(N_PER_SCENARIO): year = int(rng.choice(YEAR_RANGE, p=YEAR_WEIGHTS)) setting = _choice(rng, params["setting_probs"]) age = int(np.clip(rng.normal(30, 18), 0, 80)) sex = rng.choice(["male", "female"], p=[0.48, 0.52]) is_child = int(age < 18) disability_type = _choice(rng, params["disability_probs"]) severity = rng.choice(["mild", "moderate", "severe"], p=[0.30, 0.40, 0.30]) # Social protection disability_registered = int(rng.random() < 0.15) disability_card = int(disability_registered and rng.random() < 0.50) cash_transfer = int(rng.random() < params["social_protection_pct"]) disability_grant = int(cash_transfer and rng.random() < 0.40) health_insurance = int(rng.random() < 0.08) fee_waiver = int(rng.random() < 0.05) food_assistance = int(rng.random() < 0.10) # Education ever_attended_school = int(rng.random() < (0.70 if not is_child else 0.55)) school_completed = int(ever_attended_school and rng.random() < params["school_completion_pct"]) inclusive_education = int(is_child and rng.random() < 0.10) special_education = int(is_child and rng.random() < 0.05) out_of_school = int(is_child and not ever_attended_school) # Employment & livelihood employed = int(age >= 18 and rng.random() < params["employment_rate"]) formal_employment = int(employed and rng.random() < 0.20) informal_employment = int(employed and not formal_employment) self_employed = int(age >= 18 and not employed and rng.random() < 0.15) employment_quota_benefited = int(formal_employment and rng.random() < 0.03) vocational_training = int(age >= 15 and rng.random() < 0.05) income_below_poverty = int(rng.random() < 0.55) # Rights & participation crpd_aware = int(rng.random() < params["legal_awareness_pct"]) disability_legislation_aware = int(rng.random() < params["legal_awareness_pct"] * 1.2) dpo_member = int(rng.random() < params["dpo_membership_pct"]) voted_last_election = int(age >= 18 and rng.random() < 0.30) accessible_polling_station = int(voted_last_election and rng.random() < 0.15) community_participation = int(rng.random() < 0.20) # Discrimination & abuse discrimination_experienced = int(rng.random() < 0.40) abuse_experienced = int(rng.random() < 0.15) denied_service = int(rng.random() < 0.12) reported_discrimination = int(discrimination_experienced and rng.random() < 0.05) legal_remedy_accessed = int(reported_discrimination and rng.random() < 0.10) # Barriers stigma = int(rng.random() < 0.45) poverty_barrier = int(income_below_poverty) no_documentation = int(not disability_registered) awareness_barrier = int(not crpd_aware and not disability_legislation_aware) transport_barrier = int(rng.random() < 0.40) # Outcomes wellbeing = rng.choice(["good", "moderate", "poor"], p=[0.15, 0.35, 0.50] if not cash_transfer else [0.25, 0.40, 0.35]) social_inclusion = int(community_participation or dpo_member or employed) record = { "record_id": f"{name[:3].upper()}-{idx:05d}", "scenario": name, "year": year, "setting": setting, "age": age, "sex": sex, "disability_type": disability_type, "severity": severity, "disability_registered": disability_registered, "disability_card": disability_card, "cash_transfer": cash_transfer, "health_insurance": health_insurance, "ever_attended_school": ever_attended_school, "school_completed": school_completed, "out_of_school": out_of_school, "employed": employed, "formal_employment": formal_employment, "self_employed": self_employed, "income_below_poverty": income_below_poverty, "crpd_aware": crpd_aware, "dpo_member": dpo_member, "voted_last_election": voted_last_election, "accessible_polling_station": accessible_polling_station, "discrimination_experienced": discrimination_experienced, "abuse_experienced": abuse_experienced, "reported_discrimination": reported_discrimination, "stigma": stigma, "transport_barrier": transport_barrier, "wellbeing": wellbeing, "social_inclusion": social_inclusion, } records.append(record) return pd.DataFrame(records) def main(): output_dir = Path("data") output_dir.mkdir(parents=True, exist_ok=True) for idx, (name, params) in enumerate(SCENARIOS.items()): df = _simulate_scenario(name, params, SEED + idx * 211) df.to_csv(output_dir / SCENARIO_FILES[name], index=False) print(f"Saved {name} -> {SCENARIO_FILES[name]}") if __name__ == "__main__": main()