Simulate SIR data according to a chain Binomial

simulate_SIR_agents(n_sims, n_time_steps, beta, gamma, init_SIR)

Arguments

n_sims

number of times to run simulation

n_time_steps

number of total time steps (will use 0 to n_time_steps -1 inclusive)

beta

infection parameter for SIR chain Binomial. See details

gamma

recovery paraemter for SIR chain Binomial. See details

init_SIR

vector of (S0, I0, R0) the number of agents initially in the Susceptible, Infected, and Recovered state, respectively. The sum of this will be used as the number of agents

Value

The the output is a data.frame with columns agent_id, init_state, sim_num, tI, tR. The size is (n_agents x n_sims) x 4.

Details

For each simulation \(i\), agent \(A_{t,k}\) (the kth agent at time t) will update according to the following where the states are denoted \(S=0,I=1,R=2\). The update follows a Bernoulli draw based on the agent's current state. Specifically, $$A_{t,k}| S_{t-1}, I_{t-1} \sim \left \{\begin{array}{ll} \textnormal{Bernoulli} \left ( p_{t-1}\right ) & \textnormal{ if } A_{t-1,k} = 0 \\ 1 + Bernoulli(\gamma) & \textnormal{ if } A_{t-1,k} = 1 \\2 & \textnormal{ otherwise} \end{array} \right . $$ If the agent was infectious at time \(t=0\) then \(tI <= 0 \). If the agent never becomes infectious then \(tI = NA\). If the agent never recovers or is recovered from time 0 on then \(tR = NA\). Otherwise we assume the agent is susceptible.

Examples

sims_data <- simulate_SIR_agents(n_sims = 2, n_time_steps = 5, beta = .5, gamma = .1, init_SIR = c(9,1,0)) dim(sims_data)
#> [1] 20 4