GithubHelp home page GithubHelp logo

evgenyneu / covid19 Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 26.86 MB

A naive Stan model of confirmed COVID-19 cases that uses logistic function.

License: The Unlicense

Python 82.42% Stan 7.05% TeX 10.53%

covid19's Introduction

Using logistic function to model number of COVID-19 confirmed cases in Stan and Python

This is a Stan model for analysing time series of confirmed cases of Coronavirus (COVID-19). It uses logistic function, which I described in this blog post.

⚠️⚠️⚠️WARNING ⚠️⚠️⚠️

This is a simple model that was done for educational purposes only. It is almost certainly very inaccurate and can not be used to predict the spread of the disease.

How the model works

The program does the following:

  • Downloads new data on confirmed COVID-19 cases from Johns Hopkins University Github's repository.

  • Runs Stan model that uses logistic function.

  • Creates a plot showing observed data with round orange markers and the model with blue line. The bright shaded region indicates model's uncertainty and corresponds to 95% DHPI (highest posterior density interval).

As new data become available daily, I will be running this script and adding the new plots to plots directory. This way we can see the changes in the data and the model with time.

Modelling COVID-19 confirmed cases with logistic function, observed cases

Extrapolating the data

Attention, the following plot was made for fun and is complete nonsense because it was bade with unrealistic model assumptions, which are described below. The plot also extrapolates the data way far into the future, which is silly.

Modelling COVID-19 confirmed cases with logistic function, extrapolated

Assumptions

In the model we make the following assumptions:

  • The number of cases can be modelled with logistic function.

  • The virus is able to infect fixed number of people in total. However, it will be very interesting to make it a free parameter and let Stan estimate its distribution instead.

  • All people who are infected with COVID-19 are reported.

Exclusion of China

The model does not include the data for China because the number of confirmed cases have levelled off, as shown below. Assuming these data are correct, this could indicate that the spread of the disease is under control. Well done, China!

Modelling COVID-19 confirmed cases in China with logistic function, observed cases

Setup

In order to run the model, download and install all required software with the following steps.

1. Install python libraries

First, install Python 3.7 or newer, and then run:

pip install tarpan

If you are having issues with running the code, use pip install -Iv tarpan==0.3.9 instead.

2. Install Stan

install_cmdstan

Usage

To run the code, first, download this repository:

git clone https://github.com/evgenyneu/covid19.git
cd covid19

Finally, run the Python script:

python code/run_model.py

The script will run the model and save plots into the plots directory.

Data source

The data are taken from Johns Hopkins University Github's repository.

Learning stats

If you want to learn more about Stan and statistical programming, I would highly recommend Statistical Rethinking textbook by Richard McElreath.

The unlicense

This work is in public domain.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.