Skip to content

DeKhaos/covid-modeling

Repository files navigation

What is it?

covid-modeling is a repository built with the purpose of fetching latest data, processing and modeling Covid-19 for reference and decision support. It is designed to be simple yet concrete so sufficient information can be retrieved. Users can modify criterias parameters to their desire, which will affect how processing and modeling steps will be done. Since creator is from Vietnam, a little more in-depth analysis is carried out for Vietnam.

covid-modeling is built as a local machine application, it uses browser UI and Dash to launch. Most of the working processes will happen on local machine without interactions with a server, except for downloading initial databases. The purpose of this is for faster calculation since the application will depend only on the local machine and remove the necessary of data transferring between user and server, which can sometime become a bottleneck for the application.

Alt Text

How to use?

There are 2 ways to use this repository:

  • Use the given notebooks in the repository to work directly with if you want more control over parameters, the methodology is the same as the web application. Put the notebooks in a same folder and run it step by step (Collection>Preparation>Modeling), the all process results will be returned in database directory.
  • Use the web application by running main.py for simple user interaction, it will cache the latest server databases to your local machine (which might take a while to create caches). After that, users can try to gather latest data (server is only updated weekly), change how to process raw data & modeling.

Installation

After copy the repository to your local machine, it is recommended to create a new environment to work with and install all required packages from requirement.txt.

  • For Conda distribution users:

Create new environment:

conda create --name <env_name>

Activate environment:

conda activate <env_name>

Download required packages:

pip install -r requirement.txt

Make new directory (for repository storage):

mkdir <repository_directory>

Change to directory:

cd <repository_directory>

Create new environment:

python -m venv <env_name>

Activate environment:

If iOS: source <env_name>/bin/activate, if Window: .<env_name>\Scripts\activate

Download required packages:

pip install -r requirement.txt
  • Application start up:

After copy the repository and installation environment, we activate the environment and run the main script python main.py from a command prompt within the repository, copy the URL pop up in the command prompt to a browser to start the application.

Limitation

Due to background_callback of Dash is incompatible with conversion step to executive file, it's currently not possible to run the application directly as an executable file. Therefore, unfamiliar users have to set up their own Python environment for the application to work. If anyone can help me set up PyInstaller or similar modules for Dash app, feel free to contact me.

Methodology

Many groups of scientists have development complex models to predict the pattern of virus infection. Some of which are too complicated for normal people to understand, so a simple SVID model was built and applied in this repository.

A ordinary differential equation system is built to estimate the spread of Covid-19 virus base on the following information.

The population will be broken down into 4 groups (S+V+I+D=N):

  • Susceptible (S): The main population which is susceptible to the disease without any protection (person).
  • Vaccinated (V): The population which has been vaccinated or recovers from the disease and has protection against the disease to some degree (person).
  • Infectious (I): The infected population, whom can infect the non-infected population (person).
  • Dead (D): The population which passes away due to the disease (disease-induced mortality) (person).
  • Affected population (N): The total population which is affected by the disease (person).

The ODE (ordinary differential equation) model:

$$\begin{align} &\frac{dS}{dt} = \frac{-\beta SI}{N} - (\alpha+\mu)S + \alpha_0V +\pi p \\\ &\frac{dV}{dt} = \frac{-\beta_vVI}{N} -(\alpha_0 + \mu)V + \theta I + \alpha S + \pi(1-p) \\\ &\frac{dI}{dt} = -(\mu +\gamma +\theta)I + \frac{(\beta S + \beta_V V)I}{N} \\\ &\frac{dD}{dt} = -\mu D + \gamma I \end{align}$$

With initial conditions as follows:

$$\begin{align} &S_0 \ge 0 \\\ &V_0 \ge 0 \\\ &I_0 \ge 0 \\\ &D_0 \ge0 \end{align}$$

And model parameter as follows:

$\pi$: recruitment rate $(person/time)$
$p$: recruitment non-vaccinated percent (%)
$\alpha$: vaccination rate $(time^{-1})$
$\alpha_0$: disminissing rate of vaccine effectiveness $(time^{-1})$
$\beta$: transmission rate $(person/time)$
$\mu$: natural death rate $(time^{-1})$
$\gamma$: Covid-19 death rate $(time^{-1})$
$\theta$: post-infected immunity rate $(time^{-1})$
$\beta_v = \beta(1-\eta)$: vaccinated tranmission rate $(person/time)$

By solving the ODE system we can get the stability points:

$$\begin{align} &\frac{dS}{dt} = 0 \\\ &\frac{dV}{dt} = 0 \\\ &\frac{dI}{dt} = 0 \\\ &\frac{dD}{dt} = 0 \end{align}$$

The stability of typical equilibria of smooth ODEs is determined by the sign of real part of eigenvalues of the Jacobian matrix. An equilibrium is asymptotically stable if all eigenvalues have negative real parts; it is unstable if at least one eigenvalue has positive real part.

$$J=D_xf = f_x = \frac{\partial f_i}{\partial x_j} = \begin{pmatrix} \frac{\partial f_1}{\partial x_1} & \frac{\partial f_1}{\partial x_2} & \ldots & \frac{\partial f_1}{\partial x_n} \\\ \frac{\partial f_2}{\partial x_1} & \frac{\partial f_2}{\partial x_2} & \ldots & \frac{\partial f_2}{\partial x_n} \\\ \vdots & \vdots & \ddots & \vdots \\\ \frac{\partial f_n}{\partial x_1} & \frac{\partial f_n}{\partial x_2} & \ldots & \frac{\partial f_n}{\partial x_n} \end{pmatrix}$$

From there, we can possibly have two answers:

  • Disease free equilibrium (DFE): The point at which the population is disease-free,where as:
$$\begin{align} &S = \frac{\alpha_0\pi + p\mu\pi}{\alpha\mu + \alpha_0\mu +\mu^2} \\\ &V = \frac{\alpha\pi + (1-p)\mu\pi}{\alpha\mu + \alpha_0\mu + \mu^2} \\\ &I=0 \\\ &D=0 \\\ &R_0 = \frac{\alpha\beta_v + \alpha_0\beta + p\beta\mu + \beta_v\mu}{(\gamma + \mu + \theta)(\alpha + \alpha_0 + \mu) + p\beta_v\mu} \lt 1 \end{align}$$
  • Endemic Equilibrium (EE): The point at which the disease is at equilibrium point (the disease is not totally eradicated and remains in the population).
$$\begin{align} &S^*\geq 0 \\\ &V^*\geq 0 \\\ &I^*\geq 0 \\\ &D^*\geq 0 \\\ &R_0 = \frac{\alpha\beta_v + \alpha_0\beta + p\beta\mu + \beta_v\mu}{(\gamma + \mu + \theta)(\alpha + \alpha_0 + \mu)+p\beta_v\mu} \gt 1 \end{align}$$

*where: $R_0$ is The Basic Reproduction Number that describes the transmissability or contagiousness of an infectious disease. If $R_0&lt;1$, the disease will eventually die out and vice versa.

Data modeling

Since model parameters is time depedent and susceptible to external forces, it seems more appropriate to use forecasted parameters for model predictions instead of constant values. There are currently 2 method used to estimate the model parameters: SARIMA and regression.

The model will show users the current state of of the disease, future prediction for a set period of time and other information such as: daily case infected, daily recovery case, etc.
E.g:

example_1
example_2

Disclaimer

This is a personal project made with 💖 from Kha Nguyen Minh. It is used for acadamic and reference purposes. Creator have no influence and takes no responsibility for decisions made by agencies using this repository.

References

Data sources:

Model methodology references: The repository was inspired by some of the references shown below.

Model parameters: Some references on how to calculate model parameter of ODE systems from real|processed database

Python model references:

SARIMA model references: