#' sim_SI_unif
#'
#' sim_SI_unif simulates the spread of an infectious disease on a social network
#' using the Susceptible-Infected compartmental model with one uniform interaction
#' per dyad per day
#'
#' @param network_el an edgelist file generated by igraph
#' @param beta a value from 0 to 1 indicating per contract probability of
#' pathogen transmission
#' @param days the maximum number of days for which your simulation will run
#'
#' @return vector with 3 elements, 1: number of days simulation went for, 2:
#' final number of susceptible individuals, 3: final numbre of infected
#' individuals
#' @export
#'
#' @examples
sim_SI_unif <- function(network_el, beta, days) {
n = network_el[1,4]
e = network_el[1,5]
cdata <- network_el[,1:2]
infection_status <- c(rep(1,n))
index_infected <- sample(1:n, 1)
infection_status[index_infected] = 2
day_counter <- 0
while(day_counter <= days) {
# this is here instead of int counter for unif
tmp_infection_status <- infection_status
for(selected_edge in 1:e) {
if (sum(infection_status[cdata[selected_edge,1:2]]) == 3) {
if (beta >= runif(1,0,1)) {
tmp_infection_status[cdata[selected_edge,1:2]] = 2 # tmp infection status instead of normal for unif
}
}
}
# this is here instead of int adder in regular
infection_status <- tmp_infection_status
day_counter = day_counter+1
if (sum(infection_status%%2) == 0) break
}
return(c(day_counter-1,sum(infection_status == 1),sum(infection_status == 2)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.