Skip to contents
library(diseasy)
#> Loading required package: diseasystore
#> 
#> Attaching package: 'diseasy'
#> The following objects are masked from 'package:diseasystore':
#> 
#>     %.%, diseasyoption

Introduction

The DiseasyObservables module is the module responsible for providing disease data to the models. The module is primarily a wrapper around diseasystores which means the available data will depend on the specific diseasystore being used.

Configuring the module

The module needs some configuration to be initialized. Some of these can be set through options. Primarily, we need to specify the diseasystore

obs <- DiseasyObservables$new(
  conn = DBI::dbConnect(RSQLite::SQLite())
)
# NOTE: Alternatively we could set options("diseasy.conn" = ...)

obs$set_diseasystore(diseasystore = "Google COVID-19")

To see the data that comes with the underlying diseasystore we can query the module.

obs$available_observables
#> [1] "n_population" "n_hospital"   "n_deaths"     "n_positive"   "n_icu"       
#> [6] "n_ventilator"
obs$available_stratifications
#> [1] "age_group"       "country_id"      "country"         "region_id"      
#> [5] "region"          "subregion_id"    "subregion"       "min_temperature"
#> [9] "max_temperature"

To check the current status of the module, the $describe() method can be used:

obs$describe()
#> # DiseasyObservables interface ######################################
#> diseasystore set to: Google COVID-19
#> Study period is not set
#> last_queryable_date is not set

Getting observations

We can query the model to give the data for a given observable in a given time frame:

obs$get_observation(observable = "n_population",
                    start_date = as.Date("2020-03-01"),
                    end_date = as.Date("2020-05-01"))
#> # A tibble: 62 × 2
#>   date       n_population
#>   <date>            <dbl>
#> 1 2020-03-01    630535711
#> 2 2020-03-02    630535711
#> 3 2020-03-03    630535711
#> 4 2020-03-04    630535711
#> 5 2020-03-05    630535711
#> # ℹ 57 more rows

# NOTE: "target_conn" is a SQLite data base which has "numeric" as the "date" type.
# NOTE: The population here is not stratified, so covers all countries in the Google data

If we want to stratify our data, we supply the stratification argument. This argument is designed to be flexible, but it means they need to be wrapped in rlang::quos(). We will see below, why that is.

obs$get_observation(observable = "n_hospital",
                    stratification = rlang::quos(age_group),
                    start_date = as.Date("2020-03-01"),
                    end_date = as.Date("2020-05-01"))
#> # A tibble: 620 × 3
#>   date       age_group n_hospital
#>   <date>     <chr>          <dbl>
#> 1 2020-03-01 00-09              0
#> 2 2020-03-02 00-09              1
#> 3 2020-03-03 00-09              0
#> 4 2020-03-04 00-09              2
#> 5 2020-03-05 00-09              2
#> # ℹ 615 more rows

Since the stratification is flexible, we can programmatically stratify:

obs$get_observation(observable = "n_hospital",
                    stratification = rlang::quos(young_age_groups =
                                                   age_group %in% c("00-09", "10-19")),
                    start_date = as.Date("2020-03-01"),
                    end_date = as.Date("2020-05-01"))
#> # A tibble: 124 × 3
#>   date       young_age_groups n_hospital
#>   <date>                <int>      <dbl>
#> 1 2020-03-01                0          2
#> 2 2020-03-02                0          5
#> 3 2020-03-03                0          5
#> 4 2020-03-04                0         10
#> 5 2020-03-05                0          6
#> # ℹ 119 more rows

# NOTE: "target_conn" is a SQLite data base which has "numeric" as the "boolean" type.