lisphilar / covid19-sir

CovsirPhy: Python library for COVID-19 analysis with phase-dependent SIR-derived ODE models.
https://lisphilar.github.io/covid19-sir/
Apache License 2.0
109 stars 44 forks source link

[New] property Scenario.today as the reference date to determine past/future phases #622

Closed lisphilar closed 3 years ago

lisphilar commented 3 years ago

Summary of this new feature

As discussed in #560, the reference date to determine whether a phase is a past phase or a future phase is necessary for Scenario class. This property Scenario.today will enable us to perform retrospective analysis more effectively.

Let's say we have JHU-type data from 01Jan2020 to 31Dec2020. The following scripts will perform parameter estimation with the records from 01Jan to 30Nov, and predict parameter values from 01Dec to 31Dec. Finally, forecasted number of cases from 01Dec to 31Dec will be compared with actual number of cases from 01Dec to 31Dec.

snl = cs.Scenario(...)
snl.first_date = "01Jan2020"
snl.last_date = "31Dec2020"
snl.today = "30Nov2020"
snl.trend()
snl.estimate(cs.SIRF)
snl.fit_predict(oxcgrt_data, delay=31)
snl.history("Infected")

In version 2.16.2, property .today above is set to the same date as .last_date. This means actual records from 01Dec2020 to 31Dec2020 are removed from the figure of .history(). .today should be independent to show actual values from 01Dec to 31Dec.

lisphilar commented 3 years ago

Additionally, Scenario.timepoints(first_date=None, last_date=None, today=None) will be added.

lisphilar commented 3 years ago
Inglezos commented 3 years ago

I have some quick questions about the today/timepoints feature:

  1. The today property does not apply a limit in trends/records/pcr plots right? I mean that if for example I have snl.timepoints(today="1Apr2021", last_date="10Apr2021"), the plot of trends and records will be up to last_date, not only up to today.
  2. PCRData.positive_rate() has option for last date? Because I think even with set timepoints, it still plots data up to today.

[Update: merged multiple comments into single]

lisphilar commented 3 years ago

Could you provide all codes?

Inglezos commented 3 years ago

Yes, just a typical scenario analysis for Italy for example:

import covsirphy as cs

data_loader = cs.DataLoader(directory="kaggle/input")
jhu_data = data_loader.jhu()
population_data = data_loader.population()
oxcgrt_data = data_loader.oxcgrt()
pcr_data = data_loader.pcr()

country = "Italy"
ita_scenario = cs.Scenario(jhu_data, population_data, country)
ita_scenario.register(extras=[oxcgrt_data])
ita_scenario.timepoints(today="1Apr2021", last_date="10Apr2021")
pcr_data.positive_rate(country)
_ = ita_scenario.trend()
ita_scenario.estimate(cs.SIRF)
lisphilar commented 3 years ago