Description Details Active bindings Methods See Also Examples
Wrapper class for the model C struct (model.h).
Model used for running the simulation. Initialise the model by creating
a Parameters instance.
For a detailed explanation of the model, please read the Online Documentation
c_modelThe C model R pointer object (SWIG wrapped)
new()Model$new(params_object = NULL, params = NULL)
params_objectAn object of type Parameters or NULL
(for default params). The constructor will lock the parameter values (ie.
params_code will become read-only).
paramsA named list of parameters fo override (default NULL for no overrides).
finalize()Remove the C model to prevent leakage
Model$finalize()
get_param()Get a parameter value by name
Model$get_param(param)
paramname of param
value of stored param
update_running_params()A subset of parameters may be updated whilst the model is evaluating,
these correspond to events. This function throws an error if
param isn't safe to update.
Model$update_running_params(param, value)
paramname of parameter. See SAFE_UPDATE_PARAMS for
allowed parameter names
valuevalue of parameter
get_risk_score()Gets the value of the risk score parameter.
Wrapper for C API get_model_param_risk_score.
Model$get_risk_score(day, age_inf, age_sus)
dayInfection day
age_infInfector age group index, value between 0 and 8.
See AgeGroupEnum list
age_susSusceptible age group index, value between 0 and 8.
See AgeGroupEnum list
The risk value.
get_risk_score_household()Gets the value of the risk score household parameter.
Wrapper for C API get_model_param_risk_score_household.
Model$get_risk_score_household(age_inf, age_sus)
age_infInfector age group index, value between 0 and 8.
See AgeGroupEnum list
age_susSusceptible age group index, value between 0 and 8.
See AgeGroupEnum list
The risk value.
set_risk_score()Gets the value of the risk score parameter.
Wrapper for C API set_model_param_risk_score.
Model$set_risk_score(day, age_inf, age_sus, value)
dayInfection day
age_infInfector age group index, value between 0 and 8.
See AgeGroupEnum list
age_susSusceptible age group index, value between 0 and 8.
See AgeGroupEnum list
valueThe risk value
set_risk_score_household()Gets the value of the risk score household parameter.
Wrapper for C API set_model_param_risk_score_household.
Model$set_risk_score_household(age_inf, age_sus, value)
age_infInfector age group index, value between 0 and 8.
See AgeGroupEnum list
age_susSusceptible age group index, value between 0 and 8.
See AgeGroupEnum list
valueThe risk value.
add_user_network()Adds as bespoke user network from a dataframe of edges
the network is static with the exception of skipping
hospitalised and quarantined people.
Wrapper for C API add_user_network.
Model$add_user_network( df_network, interaction_type = 1, skip_hospitalised = TRUE, skip_quarantine = TRUE, construction = NETWORK_CONSTRUCTIONS[["BESPOKE"]], daily_fraction = 1, name = "user_network" )
df_networkNetwork data frame. List of edges, with 2 columns
ID_1 and ID_2
interaction_typeMust 0 (household), 1 (occupation), or 2 (random)
skip_hospitalisedIf TRUE, skip interaction if either
person is in hospital.
skip_quarantineIf TRUE, skip interaction if either person
is in quarantined
constructionThe method used for network construction. Must be a
number between 0 and 4 (inclusive).
See NETWORK_CONSTRUCTIONS.
daily_fractionThe fraction of edges on the network present each day (i.e. down-sampling the network). Must be a value between 0 and 1.
nameName of the network.
add_user_network_random()Adds a bespoke user random network from a dataframe of people and number of interactions. The network is regenerates each day, but the number of interactions per person is static. Hospitalsed and quarantined people can be skipped
Model$add_user_network_random( df_interactions, skip_hospitalised = TRUE, skip_quarantine = TRUE, name = "user_network" )
df_interactionsList of indviduals and interactions. Must be a
dataframe with 2 columns ID and N.
skip_hospitalisedSkip interaction if either person is in hospital. Must a logical value.
skip_quarantineSkip interaction if either person is in quarantined. Must a logical value.
nameThe name of the network.
get_network_by_id()Get a network.
Wrapper for C API get_network_by_id.
Model$get_network_by_id(network_id)
network_idThe network ID.
seed_infect_by_idx()Infects a new individual from an external source.
Wrapper for C API seed_infect_by_idx.
Model$seed_infect_by_idx(ID, strain_idx = 0, strain = NULL, network_id = -1)
IDThe ID of the individual.
strain_idxThe idx of the strain the person is infected with
strainStrain object.
network_idThe network ID.
TRUE on success, FALSE otherwise.
add_new_strain()Adds a new strain (variant)
Wrapper for C API add_new_strain.
Model$add_new_strain( transmission_multiplier = 1, hospitalised_fraction = NA, hospitalised_fraction_multiplier = 1 )
transmission_multiplierThe relative transmission rate of the strain
hospitalised_fractionthe fraction of symptomatic (not mild) who progress to hospital [default: None is no change)]
hospitalised_fraction_multiplierThe relative transmission rate of hospitalised patients.
Strain A Strain object representing this strain
set_cross_immunity_matrix()Set the cross_immunity matrix
Wrapper for C API set_cross_immunity_probability.
Model$set_cross_immunity_matrix(cross_immunity)
cross_immunitythe cross immunity matrix
get_network_ids()Get the list of network IDs
Wrapper for C API get_network_ids.
Model$get_network_ids()
The list of the network IDs.
get_network_info()Get network info.
Model$get_network_info()
The network info as a dataframe. The columns are the network properties and each row is a network.
add_vaccine()Add a new vaccine.
Wrapper for C API add_vaccine.
Model$add_vaccine( full_efficacy = 1, symptoms_efficacy = 1, severe_efficacy = 1, time_to_protect = 14, vaccine_protection_period = 1000 )
full_efficacyProbability that the person is successfully vaccinated
(must be 0 <= efficacy <= 1).
symptoms_efficacyProbability that the person is successfully vaccinated
against getting symptoms (must be 0 <= efficacy <= 1).
severe_efficacyProbability that the person is successfully vaccinated
against getting severer symptoms (must be 0 <= efficacy <= 1).
time_to_protectDelay before it takes effect (in days).
vaccine_protection_periodThe duration of the vaccine before it wanes.
Vaccine object
vaccinate_individual()Vaccinate an individual.
Wrapper for C API intervention_vaccinate_by_idx.
Model$vaccinate_individual(ID, vaccine)
IDThe ID of the individual (must be 0 <= ID <= n_total).
vaccineThe of vaccine object to be given
Logical value, TRUE if vaccinated FALSE otherwise.
vaccinate_schedule()Schedule an age-group vaccionation
Wrapper for C API intervention_vaccinate_age_group.
Model$vaccinate_schedule(schedule)
scheduleAn instance of VaccineSchedule.
The total number of people vaccinated.
get_individuals()Gets information about all individuals. Wrapper for
C API get_individuals.
Model$get_individuals()
DataFrame of basic individual information.
get_transmissions()Gets information about all transmission events. Wrapper for
C API get_transmissions.
Model$get_transmissions()
DataFrame of transmission information.
delete_network()Delete a network.
Wrapper for C API delete_network.
Model$delete_network(network)
networkThe network to delete.
TRUE on success, FALSE on failure.
get_app_users()Get all app users. Wrapper for C API get_app_users.
Model$get_app_users()
All app users.
set_app_users()Sets specific users to have or not have the app.
Wrapper for C API set_app_users. Throws error on failure.
Model$set_app_users(df_app_users)
df_app_usersA dataframe which includes the names
c("ID", "app_user").
one_time_step()Move the model through one time step.
Wrapper for C API one_time_step.
Model$one_time_step()
results()A dataframe of all the time-series results in the simulation so far.Concatanates the return of one_time_step_results from all steps so far.
Model$results()
A dataframe of the time-series results
run()Runs simulation to the end (specified by the parameter end_time)
Model$run(n_steps = NULL, verbose = TRUE)
n_stepsNumber of simulation steps to run. NULL means that
the simulation runs until the end (get_param("end_time")).
verbose- whether to display progress information (DEFAULT=TRUE)
Null
one_time_step_results()Get the results from one-time step.
Model$one_time_step_results()
A vector with names (i.e. dictionary).
write_output_files()Write output files.
Wrapper for C API write_output_files.
Model$write_output_files()
write_individual_file()Write output files
Wrapper for C API write_individual_file.
Model$write_individual_file()
write_interactions_file()Wrapper for C API write_interactions.
Model$write_interactions_file()
write_trace_tokens_timeseries()Wrapper for C API write_trace_tokens_ts.
Model$write_trace_tokens_timeseries(init = FALSE)
initIf TRUE, overwrite the output file and write the
column names at the start of the file. If FALSE, append a new
to the output file.
write_trace_tokens()Wrapper for C API write_trace_tokens.
Model$write_trace_tokens()
write_transmissions()Wrapper for C API write_transmissions.
Model$write_transmissions()
write_quarantine_reasons()Wrapper for C API write_quarantine_reasons.
Model$write_quarantine_reasons()
write_occupation_network()Wrapper for C API write_occupation_network.
Model$write_occupation_network(idx)
idxNetwork index.
write_household_network()Wrapper for C API write_household_network.
Model$write_household_network()
write_random_network()Wrapper for C API write_random_network.
Model$write_random_network()
print_individual()Wrapper for C API print_individual.
Model$print_individual(idx)
idxIndividual index.
NETWORK_CONSTRUCTIONS
the C model R pointer object
check the C model still exists
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # Create a model using the baseline parameters included in the package.
# Note: This initialisation can take a few seconds.
model <- Model.new( params = list( n_total = 10000, manual_trace_on = 1) )
# Get a parameter
Model.get_param(model, 'manual_trace_on')
# Change (update) a parameter
Model.update_running_params(model, 'manual_trace_on', 0)
if (!is.null(model)) {
# Set / get risk scores. Score are values between 0 and 1.
day <- 1
infectors <- AgeGroupEnum[['_10_19']]
susceptible <- AgeGroupEnum[['_60_69']]
model$get_risk_score( day, infectors, susceptible )
model$set_risk_score( day, infectors, susceptible, 0.5 )
model$get_risk_score_household( infectors, susceptible )
model$set_risk_score_household( infectors, susceptible, 0.5 )
# Getting a network
nw <- model$get_network_by_id(3)
# Set / get app users
users <- model$get_app_users()
users[['app_user']] <- as.integer(!users[['app_user']]) # reverse values
model$set_app_users(users)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.