{"word_count": 397, "character_count": 4158}
The most popular model to model epidemics is the so-called SIR model - or Kermack-McKendrick. Consider a population of size [latex]N[/latex], and assume that [latex]S[/latex] is the number of susceptible, [latex]I[/latex] the number of infectious, and [latex]R[/latex] for the number recovered (or immune) individuals, [latex display="true"]\displaystyle {\begin{aligned}&#38;{\frac {dS}{dt}}=-{\frac {\beta IS}{N}},\\[6pt]&#38;{\frac {dI}{dt}}={\frac {\beta IS}{N}}-\gamma I,\\[6pt]&#38;{\frac {dR}{dt}}=\gamma I,\end{aligned}}[/latex]so that [latex display="true"]\displaystyle{{\frac{dS}{dt}}+{\frac {dI}{dt}}+{\frac {dR}{dt}}=0}[/latex]which implies that [latex]S+I+R=N[/latex]. In order to be more realistic, consider some (constant) birth rate [latex]\mu[/latex], so that the model becomes[latex display="true"]\displaystyle {\begin{aligned}&#38;{\frac {dS}{dt}}=\mu(N-S)-{\frac {\beta IS}{N}},\\[6pt]&#38;{\frac {dI}{dt}}={\frac {\beta IS}{N}}-(\gamma+\mu) I,\\[6pt]&#38;{\frac {dR}{dt}}=\gamma I-\mu R,\end{aligned}}[/latex]Note, in this model, that people get sick (infected) but they do not die, they recover. So here, we can model chickenpox, for instance, not SARS.The dynamics of the infectious class depends on the following ratio:[latex display="true"]\displaystyle{R_{0}={\frac {\beta }{\gamma +\mu}}}[/latex] which is the so-called basic reproduction number (or reproductive ratio). The effective reproductive ratio is [latex]R_0S/N[/latex], and the turnover of the epidemic happens exactly when [latex]R_0S/N=1[/latex], or when the fraction of remaining susceptibles is [latex]R_0^{-1}[/latex]. As shown in Directly transmitted infectious diseases:Control by vaccination, if [latex]S/N&#60;R_0^{-1}[/latex] the disease (the number of people infected) will start to decrease.Want to see it  ? Start withmu = 0beta = 2gamma = 1/2for the parameters. Here,  [latex]R_0=4[/latex]. We also need starting valuesepsilon = .001N = 1S = 1-epsilonI = epsilonR = 0Then use the ordinary differential equation solver, in R. The idea is to say that [latex]\boldsymbol{Z}=(S,I,R)[/latex] and we have the gradient [latex display="true"]\frac{\partial \boldsymbol{Z}}{\partial t} = SIR(\boldsymbol{Z})[/latex]where [latex]SIR[/latex] is function of the various parameters. Hence, setp = c(mu = 0, N = 1, beta = 2, gamma = 1/2)start_SIR = c(S = 1-epsilon, I = epsilon, R = 0)The we must define the time, and the function that returns the gradient,times = seq(0, 10, by = .1)SIR = function(t,Z,p){S=Z[1]; I=Z[2]; R=Z[3]; N=S+I+Rmu=p["mu"]; beta=p["beta"]; gamma=p["gamma"]dS=mu*(N-S)-beta*S*I/NdI=beta*S*I/N-(mu+gamma)*IdR=gamma*I-mu*RdZ=c(dS,dI,dR)return(list(dZ))}To solve this problem uselibrary(deSolve)resol = ode(y=start_SIR, times=times, func=SIR, parms=p)We can visualize the dynamics belowpar(mfrow=c(1,2))t=resol[,"time"]plot(t,resol[,"S"],type="l",xlab="time",ylab="")lines(t,resol[,"I"],col="red")lines(t,resol[,"R"],col="blue")plot(t,t*0+1,type="l",xlab="time",ylab="",ylim=0:1)polygon(c(t,rev(t)),c(resol[,"R"],rep(0,nrow(resol))),col="blue")polygon(c(t,rev(t)),c(resol[,"R"]+resol[,"I"],rev(resol[,"R"])),col="red")We can actually also visualize the effective reproductive number is [latex]R_0S/N[/latex], whereR0=p["beta"]/(p["gamma"]+p["mu"])The effective reproductive number is on the left, and as we mentioned above, when we reach 1, we actually reach the maximum of the infected,plot(t,resol[,"S"]*R0,type="l",xlab="time",ylab="")abline(h=1,lty=2,col="red")abline(v=max(t[resol[,"S"]*R0&#62;=1]),col="darkgreen")points(max(t[resol[,"S"]*R0&#62;=1]),1,pch=19)plot(t,resol[,"S"],type="l",xlab="time",ylab="",col="grey")lines(t,resol[,"I"],col="red",lwd=3)lines(t,resol[,"R"],col="light blue")abline(v=max(t[resol[,"S"]*R0&#62;=1]),col="darkgreen")points(max(t[resol[,"S"]*R0&#62;=1]),max(resol[,"I"]),pch=19)And when adding a [latex]\mu[/latex] parameter, we can obtain some interesting dynamics on the number of infected,times = seq(0, 100, by=.1)p = c(mu = 1/100, N = 1, beta = 50, gamma = 10)start_SIR = c(S=0.19, I=0.01, R = 0.8)resol = ode(y=start_SIR, t=times, func=SIR, p=p)plot(resol[,"time"],resol[,"I"],type="l",xlab="time",ylab="")