The DiseasyObservables module is responsible for interfacing with the available diseasystores and provide
disease data to the models.
The module primarily acts as a convenience wrapper around the diseasystores. The observables and stratifications
will therefore depend on the data made available by the diseasystores.
See vignette("diseasy-observables")
Value
A new instance of the DiseasyBaseModule R6 class.
Super class
diseasy::DiseasyBaseModule -> DiseasyObservables
Active bindings
diseasystore(
character)
The set diseasystore to get DiseasyObservables for. Read-only.start_date(
Date)
Study period start. Read only.end_date(
Date)
Study period end. Read only.last_queryable_date(
Date)
The latest date that can be queried. Read-only.ds(
Diseasystore*)
The currently loaded diseasystore which provides the features. Read-only.available_observables(
character)
The currently available observables in the loaded diseasystore. Read-only.available_stratifications(
character)
The currently available stratifications in the loaded diseasystore. Read-only.synthetic_observables(
character)
The synthetic features defined in the module. Read-only.slice_ts(
Dateorcharacter)
Date or timestamp (parsable byas.POSIXct) to slice the (time-versioned) data on. Read only.conn(
DBIConnectionorfunction)
A database connection or function that opens a database connection. Read only.
Methods
Method new()
Creates a new instance of the DiseasyObservables R6 class.
Usage
DiseasyObservables$new(
diseasystore = NULL,
start_date = NULL,
end_date = NULL,
last_queryable_date = NULL,
conn = diseasyoption("conn", class = "DiseasyObservables"),
slice_ts = NULL,
...
)Arguments
diseasystore(
characterordiseasystore)
Either the name of or an instance of the feature store to get data from.start_date(
Date)
Study period start. Used as default values for$get_observation().end_date(
Date)
Study period end. Used as default values for$get_observation().last_queryable_date(
Date)
Enforce a limit on data that can be pulled (not after this date).conn(
DBIConnectionorfunction)
A database connection or function that opens a database connection.slice_ts(
Dateorcharacter)
Date or timestamp (parsable byas.POSIXct) to slice the (time-versioned) data on....Parameters sent to
DiseasyBaseModuleR6 constructor.
Returns
A new instance of the DiseasyObservables R6 class.
Method get_observation()
Retrieve an "observable" in the data set corresponding to the set diseasystore.
By default, the internal values for start_date and end_date are used to return data,
but these can be overwritten.
The results are cached for faster retrieval at subsequent calls.
Usage
DiseasyObservables$get_observation(
observable,
stratification = NULL,
start_date = self %.% start_date,
end_date = self %.% end_date,
respect_last_queryable_date = TRUE
)Arguments
observable(
character)
The observable to provide data or prediction for.stratification(
list(quosures) orNULL)
Userlang::quos(...)to specify stratification. If given, expressions in stratification evaluated to give the stratification level.start_date(
Date)
Study period start.end_date(
Date)
Study period end.respect_last_queryable_date(
logical)
Should the module be able to return data past$last_queryable_date?
Method stratification_names()
Get the names of the stratifications.
Examples
# Create observables module using the Simulist data
obs <- DiseasyObservables$new(
diseasystore = "Simulist",
conn = DBI::dbConnect(duckdb::duckdb())
)
# See available observables
print(obs$available_observables)
#> [1] "n_positive" "n_admission" "n_hospital"
print(obs$available_stratifications)
#> [1] "birth" "age" "sex"
# Get data for one observable
obs$get_observation(
"n_hospital",
start_date = as.Date("2020-03-01"),
end_date = as.Date("2020-03-05")
)
#> # A tibble: 5 × 2
#> date n_hospital
#> <date> <dbl>
#> 1 2020-03-01 317
#> 2 2020-03-02 306
#> 3 2020-03-03 298
#> 4 2020-03-04 290
#> 5 2020-03-05 275
rm(obs)
