Model: R6Class Model

Description Details Active bindings Methods See Also Examples

Description

Wrapper class for the model C struct (model.h).

Details

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

Active bindings

c_model

The C model R pointer object (SWIG wrapped)

Methods

Public methods


Method new()

Usage
Model$new(params_object = NULL, params = NULL)
Arguments
params_object

An object of type Parameters or NULL (for default params). The constructor will lock the parameter values (ie. params_code will become read-only).

params

A named list of parameters fo override (default NULL for no overrides).


Method finalize()

Remove the C model to prevent leakage

Usage
Model$finalize()

Method get_param()

Get a parameter value by name

Usage
Model$get_param(param)
Arguments
param

name of param

Returns

value of stored param


Method 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.

Usage
Model$update_running_params(param, value)
Arguments
param

name of parameter. See SAFE_UPDATE_PARAMS for allowed parameter names

value

value of parameter


Method get_risk_score()

Gets the value of the risk score parameter. Wrapper for C API get_model_param_risk_score.

Usage
Model$get_risk_score(day, age_inf, age_sus)
Arguments
day

Infection day

age_inf

Infector age group index, value between 0 and 8. See AgeGroupEnum list

age_sus

Susceptible age group index, value between 0 and 8. See AgeGroupEnum list

Returns

The risk value.


Method get_risk_score_household()

Gets the value of the risk score household parameter. Wrapper for C API get_model_param_risk_score_household.

Usage
Model$get_risk_score_household(age_inf, age_sus)
Arguments
age_inf

Infector age group index, value between 0 and 8. See AgeGroupEnum list

age_sus

Susceptible age group index, value between 0 and 8. See AgeGroupEnum list

Returns

The risk value.


Method set_risk_score()

Gets the value of the risk score parameter. Wrapper for C API set_model_param_risk_score.

Usage
Model$set_risk_score(day, age_inf, age_sus, value)
Arguments
day

Infection day

age_inf

Infector age group index, value between 0 and 8. See AgeGroupEnum list

age_sus

Susceptible age group index, value between 0 and 8. See AgeGroupEnum list

value

The risk value


Method set_risk_score_household()

Gets the value of the risk score household parameter. Wrapper for C API set_model_param_risk_score_household.

Usage
Model$set_risk_score_household(age_inf, age_sus, value)
Arguments
age_inf

Infector age group index, value between 0 and 8. See AgeGroupEnum list

age_sus

Susceptible age group index, value between 0 and 8. See AgeGroupEnum list

value

The risk value.


Method 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.

Usage
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"
)
Arguments
df_network

Network data frame. List of edges, with 2 columns ID_1 and ID_2

interaction_type

Must 0 (household), 1 (occupation), or 2 (random)

skip_hospitalised

If TRUE, skip interaction if either person is in hospital.

skip_quarantine

If TRUE, skip interaction if either person is in quarantined

construction

The method used for network construction. Must be a number between 0 and 4 (inclusive). See NETWORK_CONSTRUCTIONS.

daily_fraction

The fraction of edges on the network present each day (i.e. down-sampling the network). Must be a value between 0 and 1.

name

Name of the network.


Method 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

Usage
Model$add_user_network_random(
  df_interactions,
  skip_hospitalised = TRUE,
  skip_quarantine = TRUE,
  name = "user_network"
)
Arguments
df_interactions

List of indviduals and interactions. Must be a dataframe with 2 columns ID and N.

skip_hospitalised

Skip interaction if either person is in hospital. Must a logical value.

skip_quarantine

Skip interaction if either person is in quarantined. Must a logical value.

name

The name of the network.


Method get_network_by_id()

Get a network. Wrapper for C API get_network_by_id.

Usage
Model$get_network_by_id(network_id)
Arguments
network_id

The network ID.


Method seed_infect_by_idx()

Infects a new individual from an external source. Wrapper for C API seed_infect_by_idx.

Usage
Model$seed_infect_by_idx(ID, strain_idx = 0, strain = NULL, network_id = -1)
Arguments
ID

The ID of the individual.

strain_idx

The idx of the strain the person is infected with

strain

Strain object.

network_id

The network ID.

Returns

TRUE on success, FALSE otherwise.


Method add_new_strain()

Adds a new strain (variant) Wrapper for C API add_new_strain.

Usage
Model$add_new_strain(
  transmission_multiplier = 1,
  hospitalised_fraction = NA,
  hospitalised_fraction_multiplier = 1
)
Arguments
transmission_multiplier

The relative transmission rate of the strain

hospitalised_fraction

the fraction of symptomatic (not mild) who progress to hospital [default: None is no change)]

hospitalised_fraction_multiplier

The relative transmission rate of hospitalised patients.

Returns

Strain A Strain object representing this strain


Method set_cross_immunity_matrix()

Set the cross_immunity matrix Wrapper for C API set_cross_immunity_probability.

Usage
Model$set_cross_immunity_matrix(cross_immunity)
Arguments
cross_immunity

the cross immunity matrix


Method get_network_ids()

Get the list of network IDs Wrapper for C API get_network_ids.

Usage
Model$get_network_ids()
Returns

The list of the network IDs.


Method get_network_info()

Get network info.

Usage
Model$get_network_info()
Returns

The network info as a dataframe. The columns are the network properties and each row is a network.


Method add_vaccine()

Add a new vaccine. Wrapper for C API add_vaccine.

Usage
Model$add_vaccine(
  full_efficacy = 1,
  symptoms_efficacy = 1,
  severe_efficacy = 1,
  time_to_protect = 14,
  vaccine_protection_period = 1000
)
Arguments
full_efficacy

Probability that the person is successfully vaccinated (must be 0 <= efficacy <= 1).

symptoms_efficacy

Probability that the person is successfully vaccinated against getting symptoms (must be 0 <= efficacy <= 1).

severe_efficacy

Probability that the person is successfully vaccinated against getting severer symptoms (must be 0 <= efficacy <= 1).

time_to_protect

Delay before it takes effect (in days).

vaccine_protection_period

The duration of the vaccine before it wanes.

Returns

Vaccine object


Method vaccinate_individual()

Vaccinate an individual. Wrapper for C API intervention_vaccinate_by_idx.

Usage
Model$vaccinate_individual(ID, vaccine)
Arguments
ID

The ID of the individual (must be 0 <= ID <= n_total).

vaccine

The of vaccine object to be given

Returns

Logical value, TRUE if vaccinated FALSE otherwise.


Method vaccinate_schedule()

Schedule an age-group vaccionation Wrapper for C API intervention_vaccinate_age_group.

Usage
Model$vaccinate_schedule(schedule)
Arguments
schedule

An instance of VaccineSchedule.

Returns

The total number of people vaccinated.


Method get_individuals()

Gets information about all individuals. Wrapper for C API get_individuals.

Usage
Model$get_individuals()
Returns

DataFrame of basic individual information.


Method get_transmissions()

Gets information about all transmission events. Wrapper for C API get_transmissions.

Usage
Model$get_transmissions()
Returns

DataFrame of transmission information.


Method delete_network()

Delete a network. Wrapper for C API delete_network.

Usage
Model$delete_network(network)
Arguments
network

The network to delete.

Returns

TRUE on success, FALSE on failure.


Method get_app_users()

Get all app users. Wrapper for C API get_app_users.

Usage
Model$get_app_users()
Returns

All app users.


Method set_app_users()

Sets specific users to have or not have the app. Wrapper for C API set_app_users. Throws error on failure.

Usage
Model$set_app_users(df_app_users)
Arguments
df_app_users

A dataframe which includes the names c("ID", "app_user").


Method one_time_step()

Move the model through one time step. Wrapper for C API one_time_step.

Usage
Model$one_time_step()

Method 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.

Usage
Model$results()
Returns

A dataframe of the time-series results


Method run()

Runs simulation to the end (specified by the parameter end_time)

Usage
Model$run(n_steps = NULL, verbose = TRUE)
Arguments
n_steps

Number 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)

Returns

Null


Method one_time_step_results()

Get the results from one-time step.

Usage
Model$one_time_step_results()
Returns

A vector with names (i.e. dictionary).


Method write_output_files()

Write output files. Wrapper for C API write_output_files.

Usage
Model$write_output_files()

Method write_individual_file()

Write output files Wrapper for C API write_individual_file.

Usage
Model$write_individual_file()

Method write_interactions_file()

Wrapper for C API write_interactions.

Usage
Model$write_interactions_file()

Method write_trace_tokens_timeseries()

Wrapper for C API write_trace_tokens_ts.

Usage
Model$write_trace_tokens_timeseries(init = FALSE)
Arguments
init

If 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.


Method write_trace_tokens()

Wrapper for C API write_trace_tokens.

Usage
Model$write_trace_tokens()

Method write_transmissions()

Wrapper for C API write_transmissions.

Usage
Model$write_transmissions()

Method write_quarantine_reasons()

Wrapper for C API write_quarantine_reasons.

Usage
Model$write_quarantine_reasons()

Method write_occupation_network()

Wrapper for C API write_occupation_network.

Usage
Model$write_occupation_network(idx)
Arguments
idx

Network index.


Method write_household_network()

Wrapper for C API write_household_network.

Usage
Model$write_household_network()

Method write_random_network()

Wrapper for C API write_random_network.

Usage
Model$write_random_network()

Method print_individual()

Wrapper for C API print_individual.

Usage
Model$print_individual(idx)
Arguments
idx

Individual index.

See Also

Parameters

AgeGroupEnum

SAFE_UPDATE_PARAMS

NETWORK_CONSTRUCTIONS the C model R pointer object check the C model still exists

Examples

 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)
}

OpenABMCovid19 documentation built on July 20, 2021, 5:08 p.m.