Example on Italy data during the COVID-19 pandemic

library(asymptor)

Let’s start by loading the example data. It’s bundled in the package but originally comes from https://github.com/GoogleCloudPlatform/covid-19-open-data (Apache License 2.0).

df <- readRDS(system.file("extdata", "covid19_italy.rds", package = "asymptor"))
head(df)
#>         date new_cases new_deaths
#> 1 2019-12-31         0          0
#> 2 2020-01-01         0          0
#> 3 2020-01-02         0          0
#> 4 2020-01-03         0          0
#> 5 2020-01-04         0          0
#> 6 2020-01-05         0          0

We can feed this data directly to the estimate_asympto() function. This function requires 3 columns, labelled as date, new_cases, new_deaths, containing the daily counts (not the cumulated total!)

asy <- estimate_asympto(df$date, df$new_cases, df$new_deaths)

We may want to visualise these estimations alongside the empirical data. So, we start by merging the two datasets:

df <- merge(df, asy)

Then, we can the ggplot2 package to plot the result:

library(ggplot2)
ggplot(df, aes(x = date)) +
  geom_line(aes(y = new_cases+lower), col = "grey30") +
  geom_ribbon(aes(ymin = new_cases+lower, 
                  ymax = new_cases+upper), 
              fill = "grey30") +
  geom_line(aes(y = new_cases), color = "red") +
  labs(title = "Estimated total vs detected cases of COVID-19 in Italy",
       y = "Cases") +
  theme_minimal()
#> Warning: Removed 1 row(s) containing missing values (geom_path).