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.
If no scenario is provided, the module will provide non-informative activity information: - Openness is always 1. - The contact matrices are uniform and, when summed, the largest eigenvalue is 1.
See vignette("diseasy-activity") for examples of use.
Value
A new instance of the DiseasyActivity R6 class.
Super class
DiseasyBaseModule -> DiseasyActivity
Active bindings
scenario_matrix(
matrixarray)
A reduced view of the internal state of restrictions (showing only used activity units). Read-only.risk_matrix(
matrixarray)
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
*countscontains the age stratified contact counts across the arenas of the basis (e.g. 'work', 'home', 'school', 'other')
*proportioncontains a list of the proportion of population in each age-group
*demographycontains adata.framewith 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
*descriptioncontains information about the source of the contact basis. Read only.
Methods
Inherited methods
DiseasyActivity$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
*countscontains the age stratified contact counts across the arenas of the basis (e.g. 'work', 'home', 'school', 'other')
*proportioncontains a list of the proportion of population in each age-group
*demographycontains adata.framewith 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
*descriptioncontains information about the source of the contact basis....Parameters sent to
DiseasyBaseModuleR6 constructor
DiseasyActivity$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
DiseasyActivity$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
*countscontains the age stratified contact counts across the arenas of the basis (e.g. 'work', 'home', 'school', 'other')
*proportioncontains a list of the proportion of population in each age-group
*demographycontains adata.framewith 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
*descriptioncontains information about the source of the contact basis.
DiseasyActivity$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.frameis given to date argumentclosing(
character())
Names of activities to close on given date. Omitted ifdata.frameis given to date argument
DiseasyActivity$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
DiseasyActivity$crop_scenario()
Helper function to crop the scenario matrix in time
DiseasyActivity$get_scenario_activities()
Return list containing the active activity units on dates where there are changes.
DiseasyActivity$get_scenario_openness()
Return openness [0 ; 1] for all age groups and activities on all dates.
DiseasyActivity$get_scenario_contacts()
Return contacts across age groups and activities on all dates.
DiseasyActivity$map_population()
The function computes the proportion of population in the new and old age groups.
DiseasyActivity$rescale_contacts_to_rates()
Re-scale from contacts to rates per individual to fractional population. @details If the contact matrix is \(\beta_{i,j}\) and the population is \(N_j\), then this function returns the rescaled elements \(\left(sum_j N_j\right) \beta_{i,j} / N_j\).
DiseasyActivity$reset_scenario()
Resets the scenario in the module. NOTE: Called automatically when setting/changing activity units.
DiseasyActivity$plot()
Plot the first set of contact matrices of the scenario as well as the "openness" over time.
Usage
DiseasyActivity$plot(
age_cuts_lower = NULL,
weights = rep(1, 4),
contacts_date = NULL
)Arguments
age_cuts_lower(
numeric)
vector of ages defining the lower bound for each age group. IfNULL, age groups of contact_basis is used.weights(
numeric(4))
vector of weights for the four types of contacts. IfNULL, no weighting is done.contacts_date(
Date(1))
The date to plot contact matrix for (default is earliest contact matrix).
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)
