## See vignettes for more detailed work-ups.
##########################################
## See model_parallel()
## for an example to run realizations in parallel
##########################################
# Required for run:
require(lubridate)
## Using supplied example data:
# Read in the example data:
ex_dir <- system.file(
"extdata", "sparsemodr_example.Rdata", package="SPARSEMODr", mustWork=TRUE)
load(ex_dir)
n_pop <- length(dat_list[["pop_N"]])
# Set up realizations:
realz_seeds <- 1:2
n_realz <- length(realz_seeds)
# Set up time windows (see time_windows for other ways to do this)
input_beta <- c( 0.3, 0.3, 0.08, 0.08, 0.15)
input_dist_phi <- c( 200, 200, 20, 150, 150)
input_m <- c( 0.002, 0.002, 0.002, 0.02, 0.02)
input_imm_frac <- c( 0.0, 0.0, 0.0, 0.02, 0.02)
# Window intervals
start_dates = c(mdy("1-1-20"), mdy("2-1-20"), mdy("2-16-20"), mdy("3-11-20"), mdy("3-22-20"))
end_dates = c(mdy("1-31-20"), mdy("2-15-20"), mdy("3-10-20"), mdy("3-21-20"), mdy("5-1-20"))
# User creates the time_windows object here
tw <- time_windows(beta = input_beta,
dist_phi = input_dist_phi,
m = input_m,
imm_frac = input_imm_frac,
start_dates = start_dates,
end_dates = end_dates)
# Randomly generate initial conditions for
# EXPOSED class:
E_pops <- vector("numeric", length = n_pop)
n_initial_E <- 40
# (more exposed in larger populations)
these_E <- sample.int(n_pop,
size = n_initial_E,
replace = TRUE,
prob = dat_list$pop_N)
for(i in 1:n_initial_E){
E_pops[these_E[i]] <- E_pops[these_E[i]] + 1
}
# Inputs for the models
N_pops <- as.integer(dat_list[["pop_N"]])
S_pops <- N_pops - E_pops
# User created control list of parameters
covid19_control <- covid19_control(input_N_pops = N_pops,
input_S_pops = S_pops,
input_E_pops = E_pops)
arg.list <- list(
input_dist_mat = dat_list$dist_vec,
input_census_area = dat_list$census_area,
input_tw = tw,
input_realz_seeds = realz_seeds
)
# Using all default parameter values,
# these are the minimum inputs
covid_model_output <-
model_interface(
control = covid19_control,
arg.list
)
Run the code above in your browser using DataLab