Skip to content

CHANDMX20/SIR_Model_Sim_COVID19

Repository files navigation

MACS341FINALPROJECT

Participants

SIR model simulation for COVID-19 dynamics

file : Changing the disease dynamics.py

This code simulates the spread of COVID-19 using the SIR (Susceptible-Infected-Recovered) model, which divides the population into three compartments: susceptible, infected, and recovered. The model assumes that people can transition between compartments based on certain parameters, such as the infection rate and recovery rate.

The simulation considers three different strategies for controlling the spread of COVID-19, each with different values for the infection rate and recovery rate. The strategies are:

  1. Strategy 1: lower infection rate (beta = 0.25) while keeping the recovery rate constant (gamma = 0.1)
  2. Strategy 2: higher recovery rate (gamma = 0.125) while keeping the infection rate constant (beta = 0.3)
  3. Strategy 3: increase the proportion of the population initially immune to the disease (by setting S0 to 90% of the population), while keeping the infection and recovery rates constant.

The code defines two functions: SIR_model calculates the differential equations for the SIR model, and simulate_SIR_model runs the simulation for the given set of parameters and number of days.
The results of the simulation are plotted in two figures:
  1. A line plot of the percentage of the population that is infectious over time for each strategy.
  2. A line plot of the cumulative percentage of the population that has been infected over time for each strategy, scaled by a factor of 10.

The figures illustrate how different strategies can affect the spread of the disease, as well as the overall impact on the population.

Herd Immunity Plot

file: Herd immunity by R nought.py

This Python script produces a plot that shows the percentage of the population that needs to be immune in order to achieve herd immunity, as a function of the basic reproduction number (R0) of a disease. The plot is generated using the Matplotlib library and NumPy library.

Prerequisites

This script requires the following Python libraries to be installed:

  • Matplotlib
  • numpy

  • You can install these packages using pip:
    $ pip install numpy matplotlib

    Getting Started

    To run the script, simply execute the following command in your terminal:

    python3 Herd_immunity_by_R_nought.py

    Parameters

    The script defines a single functionherd_immunity that takes one parameter r_0, which represents the basic reproduction number of a disease. The function returns the fraction of the population that needs to be immune in order to achieve herd immunity.


    The script also defines an array r_0_vals that contains a range of values for the basic reproduction number, and computes the corresponding values for the fraction of the population that needs to be immune using the herd_immunity function.

    Output

    The script produces a plot that shows the percentage of the population that needs to be immune in order to achieve herd immunity as a function of the basic reproduction number of a disease. The plot has the following characteristics:

  • The x-axis represents the basic reproduction number (R0).
  • The y-axis represents the fraction of the population that needs to be immune for herd immunity.
  • The title of the plot is "Percentage of Population Needed for Herd Immunity by R0".
  • The x-axis label is "R0".
  • The y-axis label is "Fraction Immune for Herd Immunity".
  • The y-axis limits are set to range from 0 to 1.


  • SIR Simulation - outputs CSV file and plots most infected day

    file : most infected date.py

    This code simulates the spread of an infectious disease using the SIR (Susceptible-Infected-Recovered) model. The simulation calculates the number of susceptible, infected, and recovered individuals over time, assuming a fixed population size, transmission rate (beta), and recovery rate (gamma).

    Getting Started

    To run the simulation, you need to have Python3 installed on your computer, as well as the following packages:

  • numpy
  • pandas
  • matplotlib

  • You can install these packages using pip:

    $ pip install numpy pandas matplotlib

    To run the simulation, simply execute the following command in your terminal:

    python3 most_infected _date.py

    Parameters

    The simulation has the following parameters:


    The script will save the results of the simulation to an Excel file named sir_simulation_results.xlsx, and will also generate a plot showing the most infected day as a function of the initial infected rate.

    1. beta: The transmissioin rate, representing the rate at which susceptible individuals become infected upon contact with infected individuals.
    2. gamma: The recovery rate, representing the rate at which infected individuals recover and become immune.
    3. population: The total size of the population.
    4. days: The number of days to simulate.
    5. initial_infection_rates: An array of initial infection rates to simulate, expressed as a percentage of the population.

    Output

    The simulation outputs a DataFrame containing the following columns:

    1. Initial Infected Rate: The initial infection rate used in the simulation, expressed as a percentage of the population.
    2. Most Infected Day: The day with the highest number of infected individuals.
    3. Infected Cases Per Day: An array of the number of infected individuals per day.
    The results are saved to an Excel file named sir_simulation_results.xlsx.

    Plot

    The simulation also generates a plot showing the most infected day as a function of the initial infected rate. The plot has the following axis labels:

  • x-axis: Initial Infected Rate (%)
  • y-axis: Most Infected Day
  • title: Most Infected Day vs. Initial Infected Rate


  • Standard SIR model simulator GUI

    file : SIRtest.py

    SIRtest.py is a GUI file that allows you to check various results with graphs while modifying various parameters of the SIR standard model.

    The tkinter, matplotlib, and numpy packages are required to run this file. numpy and matplotlib are installed by default with Python installed, so no other additional work is required, but tkinter must be installed separately. The tkinter can be installed in the following ways.

    Step 1: Check Python Installation

    Make sure you have Python installed on your computer. You can download Python from the official Python website at https://www.python.org/downloads/. Follow the installation instructions for your operating system.

    Step 2: Open a Command Prompt or Terminal

    Open a command prompt (on Windows) or terminal (on macOS or Linux) on your computer. You can do this by searching for "Command Prompt" or "Terminal" in the search bar or by navigating to the appropriate application in your system's programs.

    Step 3: Install tkinter

    Enter the following command in the command prompt or terminal to install tkinter using the Python package manager pip:
    For Windows:

      $ pip install tk
    


    For macOS/Linux:

      $ pip3 install tk
    

    Note: If you're using a virtual environment, make sure it's activated before running the above command.

    Step 4: Verify tkinter Installation

    After the installation is complete, you can verify that tkinter is installed by opening a Python interactive shell or an Integrated Development Environment (IDE) that supports Python, and then typing the following command: import tkinter If you don't see any errors, then tkinter is successfully installed on your system.



    License

    This project is licensed under the MIT License - see the LICENSE.md file for details.

    About

    SIR Simulation and Herd-Immunity Analysis for COVID-19 dynamics.

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

     
     
     

    Contributors

    Languages