Estimate asymptomatic cases in Italy during the COVID-19 pandemic

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
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)

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)
head(asy)

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

res <- merge(df, asy)
head(res)

Alternatively, we can directly use a tidyverse-compatible syntax:

library(dplyr)
res <- df %>%
  mutate(lower = estimate_asympto(date, new_cases, new_deaths, "lower")$lower,
         upper = estimate_asympto(date, new_cases, new_deaths, "upper")$upper)
head(res)

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

library(ggplot2)
ggplot(res, 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()


Try the asymptor package in your browser

Any scripts or data that you put into this service are public.

asymptor documentation built on Oct. 5, 2022, 9:06 a.m.