These functions allow getting and setting the contact matrix for measles mixing models. The contact matrix specifies the mixing patterns between different population groups.
Usage
get_contact_matrix(model)
# Default S3 method
get_contact_matrix(model)
# S3 method for class 'epiworld_measlesmixing'
get_contact_matrix(model)
# S3 method for class 'epiworld_measlesmixingriskquarantine'
get_contact_matrix(model)
set_contact_matrix(model, value)
# Default S3 method
set_contact_matrix(model, value)
# S3 method for class 'epiworld_measlesmixing'
set_contact_matrix(model, value)
# S3 method for class 'epiworld_measlesmixingriskquarantine'
set_contact_matrix(model, value)Value
get_contact_matrix()returns a numeric matrix representing the contact rates between population groups.set_contact_matrix()returns the model object invisibly (called for its side effects).
Details
Entry [i, j] of the contact matrix represents the expected number of
contacts that an individual in group i has with individuals in group j
during a time step.
These functions are currently only available for:
Other mixing models in epiworld will have these methods available in the near future.
Examples
# Create entities for three population groups
e1 <- entity("Population 1", 1000, as_proportion = FALSE)
e2 <- entity("Population 2", 1000, as_proportion = FALSE)
e3 <- entity("Population 3", 1000, as_proportion = FALSE)
# Create an identity contact matrix (no mixing between groups)
cmatrix <- diag(3) * 15
N <- 3000
# Create a measles mixing model
model <- ModelMeaslesMixing(
n = N,
prevalence = 1 / N,
transmission_rate = 0.9,
vax_efficacy = 0.97,
vax_reduction_recovery_rate = 0.8,
incubation_period = 10,
prodromal_period = 3,
rash_period = 7,
contact_matrix = cmatrix,
hospitalization_rate = 0.1,
hospitalization_period = 10,
days_undetected = 2,
quarantine_period = 14,
quarantine_willingness = 0.9,
isolation_willingness = 0.8,
isolation_period = 10,
prop_vaccinated = 0.95,
contact_tracing_success_rate = 0.8,
contact_tracing_days_window = 4
)
# Add entities to the model
model |>
add_entity(e1) |>
add_entity(e2) |>
add_entity(e3)
# Get the contact matrix (note: requires running the model first)
set.seed(123)
run(model, ndays = 10)
#> _________________________________________________________________________
#> |||||||Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> |||||||
original_matrix <- get_contact_matrix(model)
print(original_matrix)
#> [,1] [,2] [,3]
#> [1,] 15 0 0
#> [2,] 0 15 0
#> [3,] 0 0 15
# Create a new contact matrix
new_matrix <- matrix(
c(12, 1.5, 1.5,
2, 11, 2,
2.25, 2.25, 10.5),
nrow = 3, byrow = TRUE
)
# Set the new contact matrix
set_contact_matrix(model, new_matrix)
# Verify the change
updated_matrix <- get_contact_matrix(model)
print(updated_matrix)
#> [,1] [,2] [,3]
#> [1,] 12.00 1.50 1.5
#> [2,] 2.00 11.00 2.0
#> [3,] 2.25 2.25 10.5