The DiseasyActivity
module is responsible for handling the societal activity.
By providing a contact_basis
, activity_units
and a scenario
to the module, the
module provides activity matrices throughout the scenario (with flexible age-groupings)
as well as the overall "activity" level in society.
The contact_basis
contains information about:
- contact matrices (contact rates between age groups)
- population (size and proportion of population in age groups)
The activity_units
projects restrictions, guidelines and other changes in activity into smaller "units" that are
independently "opened" or "closed". Opening (closing) a activity unit means the activity described in the unit is
(in)active.
The scenario
contains information on when different activity_units
are opened and closed
See vignette("diseasy-activity") for examples of use.
Super class
diseasy::DiseasyBaseModule
-> DiseasyActivity
Active bindings
scenario_matrix
(
matrix
array
)
A reduced view of the internal state of restrictions (showing only used activity units). Read-only.risk_matrix
(
matrix
array
)
A reduced view of the internal state of overall risk multipliers. Read-only.contact_basis
(
list(list())
)
A nested list with all the needed information for the contact_basis
*counts
contains the age stratified contact counts across the arenas of the basis (e.g. 'work', 'home', 'school', 'other')
*proportion
contains a list of the proportion of population in each age-group
*demography
contains adata.frame
with the columns
*age
(integer()
) 1-year age group
*population
(numeric()
) size of population in age group
*proportion
(numeric()
) proportion of total population in age group
*description
contains information about the source of the contact basis. Read only.
Methods
Method new()
Creates a new instance of the DiseasyActivity
R6 class.
Usage
DiseasyActivity$new(
base_scenario = "closed",
activity_units = NULL,
contact_basis = NULL,
...
)
Arguments
base_scenario
(
character(1)
)
Baseline scenario. Must be either fully "open" or "closed" or "dk_reference"activity_units
(
list(list())
)
A nested list of all possible 'units' of activity that can be opened or closed.contact_basis
(
list(list())
)
A nested list with all the needed information for the contact_basis
*counts
contains the age stratified contact counts across the arenas of the basis (e.g. 'work', 'home', 'school', 'other')
*proportion
contains a list of the proportion of population in each age-group
*demography
contains adata.frame
with the columns
*age
(integer()
) 1-year age group
*population
(numeric()
) size of population in age group
*proportion
(numeric()
) proportion of total population in age group
*description
contains information about the source of the contact basis....
Parameters sent to
DiseasyBaseModule
R6 constructor
Method set_activity_units()
Sets the list of all possible "units" of activity that can be opened or closed
Arguments
activity_units
(
list(list())
)
A nested list of all possible 'units' of activity that can be opened or closed.
Details
Each element in the activity_units list should be a list with the following elements:
activity: a programmatic short hand for activity (character, snake_case),
label: a human readable label for activity (character),
home: numeric/vector with number(s) in [0, 1]
work: numeric/vector with number(s) in [0, 1]
school: numeric/vector with number(s) in [0, 1]
other: numeric/vector with number(s) in [0, 1]
risk: numeric greater than zero
If a single number is provider, the number is applied across all age-groups If a vector is provided, the vector must match the number of age groups in the contact_basis
Method set_contact_basis()
Sets the contact matrix basis the activity is computed from
Arguments
contact_basis
(
list(list())
)
A nested list with all the needed information for the contact_basis
*counts
contains the age stratified contact counts across the arenas of the basis (e.g. 'work', 'home', 'school', 'other')
*proportion
contains a list of the proportion of population in each age-group
*demography
contains adata.frame
with the columns
*age
(integer()
) 1-year age group
*population
(numeric()
) size of population in age group
*proportion
(numeric()
) proportion of total population in age group
*description
contains information about the source of the contact basis.
Method change_activity()
Adds the specified openings and closings to the scenario
Arguments
date
(
Date()
|data.frame
)
Either a vector of dates when activity changes or a data.frame with columns 'date', 'opening' and 'closing'opening
(
character()
)
Names of activities to open on given date. Omitted ifdata.frame
is given to date argumentclosing
(
character()
)
Names of activities to close on given date. Omitted ifdata.frame
is given to date argument
Method change_risk()
Sets the overall risk of types of activity
Arguments
date
(
Date()
)
Dates where risk changes. The first argument can also be a data.frame with columns "date", "type" and "risk"type
(
character(1)
)
Name of activity type to change. Must be in "work", "school", "home" and "other"risk
(
numeric(1)
)
Relative risk for the given type from the given date
Method crop_scenario()
Helper function to crop the scenario matrix in time
Method get_scenario_activities()
Return list
containing the active activity units on dates where there are changes.
Method get_scenario_openness()
Return openness [0 ; 1] for all age groups and activities on all dates.
Arguments
age_cuts_lower
(
numeric
)
vector of ages defining the lower bound for each age group. If NULL (default), age groups of contact_basis is used.weights
(
numeric(4)
)
vector of weights for the four types of contacts. If NULL (default), no weighting is done. The weights are normalized before applying.
Method get_scenario_contacts()
Return contacts across age groups and activities on all dates.
Method rescale_counts_to_rates()
Re-scale from contacts to rates per individual to fractional population.
Method reset_scenario()
Resets the scenario in the module. NOTE: Called automatically when setting/changing activity units.
Examples
# Activity module with Danish reference scenario
act <- DiseasyActivity$new(base_scenario = "dk_reference",
activity_units = dk_activity_units,
contact_basis = contact_basis %.% DK)
# Get contact matrices
contact_matrices <- act$get_scenario_activities()
# Configuring a custom scenario in another country (using Danish activity units)
scenario <- data.frame(date = as.Date(character(0)),
opening = character(0),
closing = character(0)) |>
dplyr::add_row(date = as.Date("2020-01-01"), opening = "baseline", closing = NA) |>
dplyr::add_row(date = as.Date("2020-03-12"), opening = NA, closing = "baseline") |>
dplyr::add_row(date = as.Date("2020-03-12"), opening = "lockdown_2020", closing = NA)
act$set_contact_basis(contact_basis %.% GB) # Use the "Great Britain" contact_basis
act$set_activity_units(dk_activity_units)
act$change_activity(scenario)
# Get societal "openness"
openness <- act$get_scenario_openness()
rm(act)