| """Generate synthetic mental health & psychosocial disability dataset for SSA. |
| |
| Research-based parameterization: |
| - WHO Mental Health Atlas: Treatment gap 76-85% in SSA; <0.1 |
| psychiatrists per 100K; mental health budget <1% of health budget. |
| - Lancet Commission: 1 in 4 people affected by mental disorders; |
| depression, psychosis, epilepsy, substance use most common in SSA. |
| - SSA context: Widespread chaining/confinement; traditional/faith |
| healing common first contact; high stigma; limited community MH. |
| """ |
|
|
| 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_mental_health": { |
| "setting_probs": {"psychiatric_hospital": 0.25, "general_hospital_MH": 0.25, |
| "community_MH_centre": 0.20, "private_practice": 0.30}, |
| "condition_probs": {"depression": 0.25, "psychosis_schizophrenia": 0.20, |
| "bipolar": 0.08, "anxiety": 0.12, "PTSD": 0.08, |
| "substance_use": 0.10, "epilepsy": 0.08, "other": 0.09}, |
| "treatment_access_pct": 0.25, |
| "medication_available_pct": 0.40, |
| "psychosocial_support_pct": 0.15, |
| "psychiatrist_available": 0.20, |
| }, |
| "district_integrated": { |
| "setting_probs": {"district_hospital": 0.30, "health_centre": 0.25, |
| "community_programme": 0.20, "faith_healer": 0.25}, |
| "condition_probs": {"depression": 0.20, "psychosis_schizophrenia": 0.20, |
| "epilepsy": 0.15, "substance_use": 0.12, |
| "anxiety": 0.08, "PTSD": 0.08, "bipolar": 0.07, |
| "other": 0.10}, |
| "treatment_access_pct": 0.10, |
| "medication_available_pct": 0.20, |
| "psychosocial_support_pct": 0.05, |
| "psychiatrist_available": 0.03, |
| }, |
| "rural_traditional": { |
| "setting_probs": {"traditional_healer": 0.30, "faith_healer": 0.25, |
| "home_confinement": 0.20, "health_post": 0.15, |
| "community": 0.10}, |
| "condition_probs": {"psychosis_schizophrenia": 0.25, "epilepsy": 0.20, |
| "depression": 0.15, "substance_use": 0.12, |
| "PTSD": 0.08, "anxiety": 0.05, "bipolar": 0.05, |
| "other": 0.10}, |
| "treatment_access_pct": 0.03, |
| "medication_available_pct": 0.05, |
| "psychosocial_support_pct": 0.02, |
| "psychiatrist_available": 0.005, |
| }, |
| } |
|
|
| SCENARIO_FILES = { |
| "urban_mental_health": "mhpd_urban.csv", |
| "district_integrated": "mhpd_district.csv", |
| "rural_traditional": "mhpd_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(32, 14), 10, 75)) |
| sex = rng.choice(["male", "female"], p=[0.45, 0.55]) |
|
|
| condition = _choice(rng, params["condition_probs"]) |
| severity = rng.choice(["mild", "moderate", "severe"], |
| p=[0.25, 0.40, 0.35]) |
| duration_years = int(np.clip(rng.exponential(5), 0, 30)) |
| comorbid_physical = int(rng.random() < 0.25) |
|
|
| |
| treatment_received = int(rng.random() < params["treatment_access_pct"]) |
| medication = int(treatment_received and rng.random() < params["medication_available_pct"]) |
| psychotherapy = int(treatment_received and rng.random() < 0.10) |
| psychosocial_support = int(rng.random() < params["psychosocial_support_pct"]) |
| psychiatrist_seen = int(rng.random() < params["psychiatrist_available"]) |
| nurse_mh_trained = int(treatment_received and rng.random() < 0.15) |
| traditional_healer_consulted = int(rng.random() < 0.50) |
| faith_healer_consulted = int(rng.random() < 0.35) |
|
|
| |
| chained_confined = int(severity == "severe" and |
| condition in ("psychosis_schizophrenia", "bipolar") and |
| rng.random() < 0.15) |
| involuntary_admission = int(severity == "severe" and treatment_received and rng.random() < 0.10) |
| physical_restraint = int(chained_confined or (involuntary_admission and rng.random() < 0.20)) |
| abuse_experienced = int(rng.random() < 0.12) |
|
|
| |
| functional_disability = rng.choice(["none", "mild", "moderate", "severe"], |
| p=[0.10, 0.25, 0.35, 0.30]) |
| unable_to_work = int(functional_disability in ("moderate", "severe") and rng.random() < 0.50) |
| social_isolation = int(rng.random() < 0.40) |
| self_care_difficulty = int(severity == "severe" and rng.random() < 0.35) |
| homelessness = int(severity == "severe" and rng.random() < 0.08) |
|
|
| |
| stigma = int(rng.random() < 0.55) |
| cost_barrier = int(rng.random() < 0.50) |
| no_services = int(rng.random() < 0.45) |
| awareness_barrier = int(rng.random() < 0.40) |
|
|
| |
| symptom_improvement = int(treatment_received and rng.random() < 0.40) |
| community_participation = int(rng.random() < (0.35 if symptom_improvement else 0.12)) |
| caregiver_burden = int(severity in ("moderate", "severe") and rng.random() < 0.55) |
| suicide_attempt = int(condition in ("depression", "bipolar", "PTSD") and rng.random() < 0.04) |
|
|
| treatment_gap = int(not treatment_received) |
|
|
| record = { |
| "record_id": f"{name[:3].upper()}-{idx:05d}", |
| "scenario": name, |
| "year": year, |
| "setting": setting, |
| "age": age, |
| "sex": sex, |
| "condition": condition, |
| "severity": severity, |
| "duration_years": duration_years, |
| "treatment_received": treatment_received, |
| "medication": medication, |
| "psychosocial_support": psychosocial_support, |
| "psychiatrist_seen": psychiatrist_seen, |
| "traditional_healer_consulted": traditional_healer_consulted, |
| "faith_healer_consulted": faith_healer_consulted, |
| "chained_confined": chained_confined, |
| "abuse_experienced": abuse_experienced, |
| "functional_disability": functional_disability, |
| "unable_to_work": unable_to_work, |
| "social_isolation": social_isolation, |
| "homelessness": homelessness, |
| "stigma": stigma, |
| "cost_barrier": cost_barrier, |
| "no_services": no_services, |
| "symptom_improvement": symptom_improvement, |
| "community_participation": community_participation, |
| "caregiver_burden": caregiver_burden, |
| "suicide_attempt": suicide_attempt, |
| "treatment_gap": treatment_gap, |
| } |
| 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() |
|
|