# Simple model
model_sirconn <- ModelSIRCONN(
name = "COVID-19",
n = 10000,
prevalence = 0.01,
contact_rate = 5,
transmission_rate = 0.4,
recovery_rate = 0.95
)
# Running and printing
run(model_sirconn, ndays = 100, seed = 1912)
plot(model_sirconn)
epitool <- tool(
name = "Vaccine",
prevalence = 0.5,
as_proportion = TRUE,
susceptibility_reduction = .9,
transmission_reduction = .5,
recovery_enhancer = .5,
death_reduction = .9
)
epitool
set_name_tool(epitool, "Pfizer") # Assigning name to the tool
get_name_tool(epitool) # Returning the name of the tool
add_tool(model_sirconn, epitool)
run(model_sirconn, ndays = 100, seed = 1912)
model_sirconn
plot(model_sirconn)
# To declare a certain number of individuals with the tool
rm_tool(model_sirconn, 0) # Removing epitool from the model
# Setting prevalence to 0.1
set_distribution_tool(epitool, distribute_tool_randomly(0.1, TRUE))
add_tool(model_sirconn, epitool)
run(model_sirconn, ndays = 100, seed = 1912)
# Adjusting probabilities due to tool
set_susceptibility_reduction(epitool, 0.1) # Susceptibility reduction
set_transmission_reduction(epitool, 0.2) # Transmission reduction
set_recovery_enhancer(epitool, 0.15) # Probability increase of recovery
set_death_reduction(epitool, 0.05) # Probability reduction of death
rm_tool(model_sirconn, 0)
add_tool(model_sirconn, epitool)
run(model_sirconn, ndays = 100, seed = 1912) # Run model to view changes
# Using the logit function --------------
sir <- ModelSIR(
name = "COVID-19", prevalence = 0.01,
transmission_rate = 0.9, recovery_rate = 0.1
)
# Adding a small world population
agents_smallworld(
sir,
n = 10000,
k = 5,
d = FALSE,
p = .01
)
# Creating a tool
mask_wearing <- tool(
name = "Mask",
prevalence = 0.5,
as_proportion = TRUE,
susceptibility_reduction = 0.0,
transmission_reduction = 0.3, # Only transmission
recovery_enhancer = 0.0,
death_reduction = 0.0
)
add_tool(sir, mask_wearing)
run(sir, ndays = 50, seed = 11)
hist_0 <- get_hist_total(sir)
# And adding features
dat <- cbind(
female = sample.int(2, 10000, replace = TRUE) - 1,
x = rnorm(10000)
)
set_agents_data(sir, dat)
# Creating the logit function
tfun <- tool_fun_logit(
vars = c(0L, 1L),
coefs = c(-1, 1),
model = sir
)
# The infection prob is lower
hist(plogis(dat %*% rbind(.5, 1)))
tfun # printing
set_susceptibility_reduction_fun(
tool = get_tool(sir, 0),
model = sir,
tfun = tfun
)
run(sir, ndays = 50, seed = 11)
hist_1 <- get_hist_total(sir)
op <- par(mfrow = c(1, 2))
plot(hist_0)
abline(v = 30)
plot(hist_1)
abline(v = 30)
par(op)
Run the code above in your browser using DataLab