Skip to main content

A Monte Carlo simulation for Cholera risk assessment โ€” evaluating transboundary infection risk from Bangladesh to India

Project description

๐Ÿฆ  Cholera Risk Assessment โ€” Monte Carlo Simulation

A Python package for quantitative risk analysis of transboundary cholera infection from Bangladesh to India, using stochastic Monte Carlo simulation.


๐Ÿ“ Model Overview

The model computes the compound probability of cholera-related mortality through a chain of six risk factors:

P_final = P1 ร— P2 ร— P3 ร— P4 ร— P5 ร— P6
Step Parameter Description Distribution
P1 Outbreak Probability Cholera outbreak in Bangladesh Poisson: 1 โˆ’ e^(โˆ’ฮปt), ฮป = 2779/(22ร—12)
P2 Infection Rate Human cholera infection probability Beta(1605, 24618)
P3 False Negative (BD) Missed cases in Bangladesh 1 โˆ’ Uniform(0.549, 0.906)
P4 False Negative (IN) Missed cases in India 1 โˆ’ Uniform(0.884, 0.999)
P5 Exposure Risk Unsafe water ร— unsafe sanitation 0.11 ร— 0.01 = 0.0011
P6 Mortality Case fatality rate 0.03

The simulation generates 10,000 (configurable) random samples and computes:

  • Expected Probability (mean)
  • 90% Confidence Interval (5thโ€“95th percentile)
  • Min/Max range
  • Sensitivity analysis via Spearman's rank correlation

๐Ÿ“ฆ Installation

# Clone the repository
git clone https://github.com/example/cholera-risk.git
cd cholera-risk

# Install the package
pip install .

# Or install in development mode
pip install -e .

# Or install dependencies only
pip install -r requirements.txt

๐Ÿš€ Quick Start

Using the Class API

from cholera_risk import CholeraSimulator

# Create simulator with 10,000 samples
sim = CholeraSimulator(n_samples=10000, seed=42)

# Run the Monte Carlo simulation
results = sim.run_simulation()

# Access results
print(f"Expected Risk: {results['summary']['expected_prob']:.6e}")
print(f"90% CI: [{results['summary']['ci_5']:.2e}, {results['summary']['ci_95']:.2e}]")

Using the Convenience Function

from cholera_risk.model import quick_risk_assessment

results = quick_risk_assessment(n_samples=50000, seed=123)
print(f"Risk: {results['summary']['expected_prob']:.6e}")

Generating Visualizations

from cholera_risk import CholeraSimulator
from cholera_risk.visualization import plot_all, print_summary

sim = CholeraSimulator(n_samples=10000, seed=42)
results = sim.run_simulation()

# Print formatted summary
print_summary(results)

# Generate all plots (histogram, sensitivity, scatter)
plot_all(results, save_dir="./output_plots/")

Custom Parameters

from cholera_risk.model import CholeraSimulator, SimulationConfig

# Customize epidemiological parameters
config = SimulationConfig(
    total_outbreaks=3000,
    observation_years=25,
    beta_alpha=2000,
    beta_beta=30000,
    case_fatality_rate=0.05,
)

sim = CholeraSimulator(n_samples=20000, seed=99, config=config)
results = sim.run_simulation()

๐Ÿงช Running Tests

# Run all tests
python -m pytest tests/ -v

# Run with coverage
python -m pytest tests/ -v --cov=cholera_risk --cov-report=term-missing

๐Ÿ“ Directory Structure

colera/
โ”œโ”€โ”€ cholera_risk/              # The actual Python package
โ”‚   โ”œโ”€โ”€ __init__.py            # Package init, exports CholeraSimulator
โ”‚   โ”œโ”€โ”€ model.py               # Core simulation logic (math & stats)
โ”‚   โ””โ”€โ”€ visualization.py       # Plotting functions (matplotlib/seaborn)
โ”œโ”€โ”€ tests/                     # Unit tests
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ test_model.py          # 25+ tests for correctness
โ”œโ”€โ”€ app.py                     # Original monolithic script (reference)
โ”œโ”€โ”€ index.php                  # PHP web application version
โ”œโ”€โ”€ README.md                  # This file
โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ””โ”€โ”€ setup.py                   # Package installation script

๐Ÿ“Š Output Example

=================================================================
   CHOLERA RISK ASSESSMENT โ€” Monte Carlo Simulation Results
=================================================================
  Samples:              10,000
  Random Seed:          42
  ฮป (Poisson rate):     10.5265
-----------------------------------------------------------------
  Expected Probability: 3.207426e-08
  Median:               2.450000e-08
  90% CI:               [3.16e-09, 7.74e-08]
  Minimum:              2.67e-10
  Maximum:              1.05e-07
-----------------------------------------------------------------
  Sensitivity Analysis (Spearman ฯ):
    P2 (Infection Rate): ฯ = 0.1234
    P3 (FN Bangladesh):  ฯ = 0.3456
    P4 (FN India):       ฯ = 0.5678
=================================================================

๐Ÿ”ฌ Methodology

  • Monte Carlo Simulation: Generates thousands of random scenarios by sampling each stochastic input from its probability distribution
  • Beta Distribution (P2): Models the uncertainty in human infection rates using Bayesian parameters derived from epidemiological data
  • Uniform Distributions (P3, P4): Represent the range of CholKit RDT diagnostic sensitivity
  • Spearman Rank Correlation: Non-parametric measure of how strongly each input drives variations in the output

๐Ÿ“ License

MIT License โ€” see LICENSE for details.


๐Ÿ‘ฅ Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cholera_risk-0.1.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cholera_risk-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file cholera_risk-0.1.0.tar.gz.

File metadata

  • Download URL: cholera_risk-0.1.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for cholera_risk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6e8ae4b5822b1b9df2d02fdbf1e6c45d4da6212b7a5573f295ac6e1f6b974d0d
MD5 f1ffe095927ec74201cfa623fc894529
BLAKE2b-256 1579fa5b00db7cf3cdce0df6cacfaaa58f7578b98ffd9d8549688e4884dcc2a3

See more details on using hashes here.

File details

Details for the file cholera_risk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cholera_risk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for cholera_risk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a48d0fe293452f3d20f51396f46015a6bfd24cd3934ce3e4c9ac1395199a67c
MD5 4861fbd97ea0e6283f253cff2410d28b
BLAKE2b-256 2d36f9f505ca707c966cae086394b000539ba3b24a364c6ca1bf68395185cbca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page