The DiseasyRegions module is responsible for handling geographic regions
included in the model.
See the vignette("diseasy-regions") for examples of use.
Value
A new instance of the DiseasyRegions R6 class.
Super class
DiseasyBaseModule -> DiseasyRegions
Active bindings
regions(
character())
The geographic regions of interest. Read only.adjacency(
data.frame(1))
The adjacency (connectedness) of the regions. Effectively, theadjacencyis a long-form of the adjacency-matrix
Thedata.framemust include the following columns:
-from(character): Region identifier.
-to(character): Region identifier.
-adjacency(numeric): Strength of the connectedness.
Read only.infection_flow_matrix(
matrix)
The "Theta" matrix (seevignette("diseasy-regions")) that describes flow of infections between regions.demography(
data.frame(1))
The demography of the population per region.
Thedata.framemust include the following columns:
*region(character) Region identifier.
*...Optional additional stratification columns (e.g. sex, ethnicity).
*population(numeric) Number of individuals in the group. Read only.
Methods
Inherited methods
DiseasyRegions$new()
Creates a new instance of the DiseasyRegions R6 class.
Usage
DiseasyRegions$new(regions = NULL, adjacency = NULL, demography = NULL, ...)Arguments
regions(
character())
The geographic regions of interest. The specified regions must be available in thedemographyandadjacencydata.adjacency(
data.frame(1))
The adjacency (connectedness) of the regions. Effectively, theadjacencyis a long-form of the adjacency-matrix
Thedata.framemust include the following columns:
-from(character): Region identifier.
-to(character): Region identifier.
-adjacency(numeric): Strength of the connectedness.
Thefromandtocolumns must contain the same set of regions. For "movement" inputs, rows are normalised before deriving the Theta matrix. For "infection-flow" inputs, values are interpreted directly as the Theta matrix.demography(
data.frame(1))
The demography of the population per region.
Thedata.framemust include the following columns:
*region(character) Region identifier.
*...Optional additional stratification columns (e.g. sex, ethnicity).
*population(numeric) Number of individuals in the group....Parameters sent to
DiseasyBaseModuleR6 constructor.
DiseasyRegions$set_regions()
Sets the geographic regions of interest.
Arguments
regions(
character())
The geographic regions of interest. The specified regions must be available in thedemographyandadjacencydata.
DiseasyRegions$set_adjacency()
Sets the region adjacency data.
Usage
DiseasyRegions$set_adjacency(adjacency, type = c("movement", "infection-flow"))Arguments
adjacency(
data.frame(1))
The adjacency (connectedness) of the regions. Effectively, theadjacencyis a long-form of the adjacency-matrix
Thedata.framemust include the following columns:
-from(character): Region identifier.
-to(character): Region identifier.
-adjacency(numeric): Strength of the connectedness.
Thefromandtocolumns must contain the same set of regions. For "movement" inputs, rows are normalised before deriving the Theta matrix. For "infection-flow" inputs, values are interpreted directly as the Theta matrix.type(
character)
The type of adjacency provided ("movement" versus "infection-flow"). Seevignette("diseasy-regions")for details.
DiseasyRegions$set_demography()
Sets the demography data for all regions.
Arguments
demography(
data.frame(1))
The demography of the population per region.
Thedata.framemust include the following columns:
*region(character) Region identifier.
*...Optional additional stratification columns (e.g. sex, ethnicity).
*population(numeric) Number of individuals in the group.
DiseasyRegions$validate_configuration()
Check whether regions, adjacency, and demography are mutually consistent.
Arguments
regions(
character())
The geographic regions of interest. The specified regions must be available in thedemographyandadjacencydata.adjacency(
data.frame(1))
The adjacency (connectedness) of the regions. Effectively, theadjacencyis a long-form of the adjacency-matrix
Thedata.framemust include the following columns:
-from(character): Region identifier.
-to(character): Region identifier.
-adjacency(numeric): Strength of the connectedness.
Thefromandtocolumns must contain the same set of regions. For "movement" inputs, rows are normalised before deriving the Theta matrix. For "infection-flow" inputs, values are interpreted directly as the Theta matrix.demography(
data.frame(1))
The demography of the population per region.
Thedata.framemust include the following columns:
*region(character) Region identifier.
*...Optional additional stratification columns (e.g. sex, ethnicity).
*population(numeric) Number of individuals in the group.
DiseasyRegions$region_filter()
Create a logical filter for values matching one or more regions.
The generic implementation uses exact matching. DiseasyRegionsNuts
overrides this method with hierarchical NUTS prefix matching.
Arguments
values(
character())
Values to filter, typically region identifiers.regions(
character()orNULL)
Region identifiers to match against. Defaults to the currently selected regions. IfNULL, all values are matched.
Returns
A logical() vector with the same length as values.
DiseasyRegions$adjacency_to_theta()
Converts long form adjacency to the "Theta" infection matrix.
Usage
DiseasyRegions$adjacency_to_theta(
adjacency,
type = c("movement", "infection-flow")
)Arguments
adjacency(
data.frame(1))
The adjacency (connectedness) of the regions. Effectively, theadjacencyis a long-form of the adjacency-matrix
Thedata.framemust include the following columns:
-from(character): Region identifier.
-to(character): Region identifier.
-adjacency(numeric): Strength of the connectedness.
Thefromandtocolumns must contain the same set of regions. For "movement" inputs, rows are normalised before deriving the Theta matrix. For "infection-flow" inputs, values are interpreted directly as the Theta matrix.type(
character)
The type of adjacency provided ("movement" versus "infection-flow"). Seevignette("diseasy-regions")for details.
Examples
# Create simple demography for three generic regions.
demography <- data.frame(
region = c("north", "north", "south", "south", "east", "east"),
age_group = rep(c("0-17", "18+"), times = 3),
population = c(100, 300, 80, 220, 60, 140)
)
# Adjacency is a long-form representation of connectedness.
adjacency <- data.frame(
from = c("north", "north", "north", "south", "south", "south", "east", "east", "east"),
to = c("north", "south", "east", "north", "south", "east", "north", "south", "east"),
adjacency = c(0.7, 0.2, 0.1, 0.1, 0.8, 0.1, 0.1, 0.3, 0.6)
)
# Restrict the model scope to two regions.
region <- DiseasyRegions$new(
regions = c("north", "south"),
adjacency = adjacency,
demography = demography
)
# Active bindings return data for configured regions.
region %.% regions
#> [1] "north" "south"
region %.% demography
#> region age_group population
#> 1 north 0-17 100
#> 2 north 18+ 300
#> 3 south 0-17 80
#> 4 south 18+ 220
region %.% adjacency
#> from to adjacency
#> 1 north north 0.7
#> 2 north south 0.2
#> 3 south north 0.1
#> 4 south south 0.8
# Update the configured regional scope.
region$set_regions(regions = c("north", "south", "east"))
region$describe()
#> # DiseasyRegions #############################################
#> Regions: east, north, south
#> Total population: 900
#> Theta matrix: Max eigenvalue 1.06
rm(region, demography, adjacency)
