Usage: quickest tour

Open In Colab

Thank you for using CovsirPhy!!
This is the quickest tour to get an overview of CovsirPhy.
  • Download datasets

  • Parameter estimation with phase-dependent SIR-derived models

  • Simulate the number of cases

Preparation

Prepare the packages.

[1]:
# !pip install covsirphy --upgrade
from pprint import pprint
import covsirphy as cs
cs.__version__
[1]:
'2.20.3-gamma'

Dataset preparation

Download the datasets to “../input” directory and load them. If “../input” directory has the datasets, DataLoader will load the local files. If the datasets were updated in remote servers, DataLoader will update the local files automatically. Please refer to Usage: datasets for the details.

[2]:
# Standard users and developers
data_loader = cs.DataLoader("../input")
# The number of cases and population values
jhu_data = data_loader.jhu()

We can select the following countries.

[3]:
pprint(jhu_data.countries(), compact=True)
['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola',
 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Australia', 'Austria',
 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus',
 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia',
 'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria',
 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde',
 'Central African Republic', 'Chad', 'Chile', 'China', 'Colombia', 'Comoros',
 'Costa Rica', "Cote d'Ivoire", 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic',
 'Democratic Republic of the Congo', 'Denmark', 'Djibouti', 'Dominica',
 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea',
 'Eritrea', 'Estonia', 'Ethiopia', 'Fiji', 'Finland', 'France', 'Gabon',
 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guam',
 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Holy See',
 'Honduras', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq',
 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan',
 'Kenya', 'Kiribati', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia',
 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania',
 'Luxembourg', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta',
 'Marshall Islands', 'Mauritania', 'Mauritius', 'Mexico', 'Moldova', 'Monaco',
 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia',
 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria',
 'North Macedonia', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan',
 'Palestine', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines',
 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Republic of the Congo',
 'Romania', 'Russia', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia',
 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino',
 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles',
 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands',
 'Somalia', 'South Africa', 'South Korea', 'South Sudan', 'Spain', 'Sri Lanka',
 'Sudan', 'Suriname', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Taiwan',
 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo',
 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Uganda', 'Ukraine',
 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay',
 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands, U.S.',
 'Yemen', 'Zambia', 'Zimbabwe']

Start scenario analysis

As an example, we will analysis the number of cases in Italy using Scenario class. To initialize this class, we need to specify the country name.

[4]:
snl = cs.Scenario(country="Italy", province=None)
snl.register(jhu_data)

Check records

Let’s see the records at first. Scenario.records() method return the records as a pandas dataframe and show a line plot. Some kind of complement will be done for analysis, if necessary.

[5]:
df = snl.records()
df.tail()
_images/usage_quickest_10_0.png
[5]:
Date Infected Fatal Recovered
468 2021-06-06 192272 126523 3913633
469 2021-06-07 188453 126588 3918657
470 2021-06-08 181726 126690 3927176
471 2021-06-09 174935 126767 3936088
472 2021-06-10 169309 126855 3943704

S-R trend analysis

S-R trend analysis finds the change points of SIR-derived ODE parameters. This is a significant step of analysis because we assume that ODE parameter values will be changed phase by phase (not daily basis, not constant through the outbreak).
Details will be explained in Usage: phases.
[6]:
_ = snl.trend()
_images/usage_quickest_12_0.png

Summarize the phases.

  • Type: “Past” or “Future”

  • Start: start date of the phases

  • End: end date of the phases

  • Population: total population in the phases

[7]:
snl.summary()
[7]:
Type Start End Population
0th Past 24Feb2020 03Mar2020 60421760
1st Past 04Mar2020 12Mar2020 60421760
2nd Past 13Mar2020 26Mar2020 60421760
3rd Past 27Mar2020 10Apr2020 60421760
4th Past 11Apr2020 20Apr2020 60421760
5th Past 21Apr2020 29Apr2020 60421760
6th Past 30Apr2020 07May2020 60421760
7th Past 08May2020 17May2020 60421760
8th Past 18May2020 26May2020 60421760
9th Past 27May2020 03Jun2020 60421760
10th Past 04Jun2020 12Jun2020 60421760
11th Past 13Jun2020 22Jun2020 60421760
12th Past 23Jun2020 30Jun2020 60421760
13th Past 01Jul2020 08Jul2020 60421760
14th Past 09Jul2020 22Jul2020 60421760
15th Past 23Jul2020 04Aug2020 60421760
16th Past 05Aug2020 12Aug2020 60421760
17th Past 13Aug2020 21Aug2020 60421760
18th Past 22Aug2020 02Sep2020 60421760
19th Past 03Sep2020 17Sep2020 60421760
20th Past 18Sep2020 25Sep2020 60421760
21st Past 26Sep2020 04Oct2020 60421760
22nd Past 05Oct2020 14Oct2020 60421760
23rd Past 15Oct2020 23Oct2020 60421760
24th Past 24Oct2020 02Nov2020 60421760
25th Past 03Nov2020 10Nov2020 60421760
26th Past 11Nov2020 25Nov2020 60421760
27th Past 26Nov2020 03Dec2020 60421760
28th Past 04Dec2020 15Dec2020 60421760
29th Past 16Dec2020 23Dec2020 60421760
30th Past 24Dec2020 04Jan2021 60421760
31st Past 05Jan2021 14Jan2021 60421760
32nd Past 15Jan2021 26Jan2021 60421760
33rd Past 27Jan2021 04Feb2021 60421760
34th Past 05Feb2021 16Feb2021 60421760
35th Past 17Feb2021 03Mar2021 60421760
36th Past 04Mar2021 11Mar2021 60421760
37th Past 12Mar2021 21Mar2021 60421760
38th Past 22Mar2021 31Mar2021 60421760
39th Past 01Apr2021 13Apr2021 60421760
40th Past 14Apr2021 23Apr2021 60421760
41st Past 24Apr2021 05May2021 60421760
42nd Past 06May2021 13May2021 60421760
43rd Past 14May2021 24May2021 60421760
44th Past 25May2021 01Jun2021 60421760
45th Past 02Jun2021 10Jun2021 60421760

Hyperparameter estimation of ODE models

Here, we will estimate the parameter values of SIR-derived models. As an example, we use SIR-F model. Details of models will be explained in Usage: SIR-derived models.

[8]:
# Default value of timeout is 180 sec
snl.estimate(cs.SIRF, timeout=30)

<SIR-F model: parameter estimation>
Running optimization with 4 CPUs...
         9th phase (27May2020 - 03Jun2020): finished  341 trials in 0 min 10 sec
        10th phase (04Jun2020 - 12Jun2020): finished  181 trials in 0 min  5 sec
        11th phase (13Jun2020 - 22Jun2020): finished  184 trials in 0 min  5 sec
         0th phase (24Feb2020 - 03Mar2020): finished  710 trials in 0 min 25 sec
        12th phase (23Jun2020 - 30Jun2020): finished  138 trials in 0 min  5 sec
         3rd phase (27Mar2020 - 10Apr2020): finished  775 trials in 0 min 30 sec
         6th phase (30Apr2020 - 07May2020): finished  771 trials in 0 min 30 sec
        13th phase (01Jul2020 - 08Jul2020): finished  146 trials in 0 min  5 sec
         7th phase (08May2020 - 17May2020): finished  138 trials in 0 min  5 sec
        14th phase (09Jul2020 - 22Jul2020): finished  141 trials in 0 min  5 sec
         8th phase (18May2020 - 26May2020): finished  146 trials in 0 min  5 sec
        15th phase (23Jul2020 - 04Aug2020): finished  145 trials in 0 min  5 sec
        16th phase (05Aug2020 - 12Aug2020): finished  146 trials in 0 min  5 sec
         4th phase (11Apr2020 - 20Apr2020): finished  616 trials in 0 min 25 sec
         1st phase (04Mar2020 - 12Mar2020): finished  668 trials in 0 min 30 sec
        18th phase (22Aug2020 - 02Sep2020): finished  674 trials in 0 min 30 sec
        17th phase (13Aug2020 - 21Aug2020): finished  696 trials in 0 min 30 sec
         5th phase (21Apr2020 - 29Apr2020): finished  663 trials in 0 min 30 sec
         2nd phase (13Mar2020 - 26Mar2020): finished  646 trials in 0 min 30 sec
        27th phase (26Nov2020 - 03Dec2020): finished  104 trials in 0 min  5 sec
        28th phase (04Dec2020 - 15Dec2020): finished  124 trials in 0 min  5 sec
        29th phase (16Dec2020 - 23Dec2020): finished  113 trials in 0 min  5 sec
        19th phase (03Sep2020 - 17Sep2020): finished  596 trials in 0 min 30 sec
        20th phase (18Sep2020 - 25Sep2020): finished  132 trials in 0 min  5 sec
        21st phase (26Sep2020 - 04Oct2020): finished  581 trials in 0 min 30 sec
        30th phase (24Dec2020 - 04Jan2021): finished  261 trials in 0 min 10 sec
        33rd phase (27Jan2021 - 04Feb2021): finished  145 trials in 0 min  5 sec
        24th phase (24Oct2020 - 02Nov2020): finished  588 trials in 0 min 30 sec
        34th phase (05Feb2021 - 16Feb2021): finished  171 trials in 0 min  5 sec
        22nd phase (05Oct2020 - 14Oct2020): finished  723 trials in 0 min 30 sec
        31st phase (05Jan2021 - 14Jan2021): finished  721 trials in 0 min 30 sec
        25th phase (03Nov2020 - 10Nov2020): finished  709 trials in 0 min 30 sec
        32nd phase (15Jan2021 - 26Jan2021): finished  156 trials in 0 min  5 sec
        35th phase (17Feb2021 - 03Mar2021): finished  698 trials in 0 min 30 sec
        36th phase (04Mar2021 - 11Mar2021): finished  120 trials in 0 min  5 sec
        37th phase (12Mar2021 - 21Mar2021): finished  147 trials in 0 min  5 sec
        23rd phase (15Oct2020 - 23Oct2020): finished  678 trials in 0 min 30 sec
        42nd phase (06May2021 - 13May2021): finished  157 trials in 0 min  5 sec
        26th phase (11Nov2020 - 25Nov2020): finished  668 trials in 0 min 30 sec
        39th phase (01Apr2021 - 13Apr2021): finished  675 trials in 0 min 30 sec
        43rd phase (14May2021 - 24May2021): finished  147 trials in 0 min  5 sec
        45th phase (02Jun2021 - 10Jun2021): finished  160 trials in 0 min  5 sec
        40th phase (14Apr2021 - 23Apr2021): finished  147 trials in 0 min  5 sec
        44th phase (25May2021 - 01Jun2021): finished  148 trials in 0 min  5 sec
        38th phase (22Mar2021 - 31Mar2021): finished  732 trials in 0 min 30 sec
        41st phase (24Apr2021 - 05May2021): finished  203 trials in 0 min  5 sec
Completed optimization. Total: 3 min  8 sec

History of reproduction number

Let’s see the history of parameter values. Reproduction number is here.

[9]:
_ = snl.history(target="Rt")
_images/usage_quickest_18_0.png

History of parameters

History of each parameter. Values will be divided by the values in 0th phase.

[10]:
_ = snl.history_rate()
_images/usage_quickest_20_0.png

Simulate the number of cases

How many cases will be in 30 days if the parameter values will not be changed from today?

[11]:
# Add a phase with 30 days from the date of the last record
snl.add(days=30)
_ = snl.simulate()
_images/usage_quickest_22_0.png
Next, please see Usage: scenario analysis to find details of datasets and how to perform scenario analysis.
Thank you!