#In this work we study the SIR models, in which, to model the progress of an infectious disease in a certain population. To run the models we will rely on the R and R Studio programming software. The work has profound implications for future work on epidemiological models and their efficient implementation as surveillance observatories that they can support in anticipation of events.
#install.packages(deSolve)
library(deSolve)
#tamaño poblacional
N = 12700
#Estado inicial de los compartimentos
init <- c(S = 1-1e-6, #Susceptible
I = 1e-6, #Infected
R = 0) #Recovered #R0= Basic reproduction rate
#parámetros del modelo (coeficientes de las variables)
param <- c(beta = 0.3526, #Transmission rate
gamma = 0.1652) #Recovery rate
#Con estos datos de beta y gamma obtenemos un parámetro importante que se llama R0 (R.Cero) (0.3526/0.1652)= , que se denomina tasa básica de reproducción, y que representa el número de nuevos infectados producidos por un sólo infectado, si toda la población es susceptible, para el caso de México estamos considerando como una problación susceptible de: 12.7 Millones de personas .
#crear la función con las ODE
sir <- function(times, init, param) {
with(as.list(c(init, param)), {
#ecuaciones diferenciales
dS <- -beta * S * I
dI <- beta * S * I - gamma * I
dR <- gamma * I
#resultados de las tasas de cambio
return(list(c(dS, dI, dR)))
})
}
#intervalo de tiempo y resolución
times <- seq(1, 140
, by = 1)
#resolver el sistema de ecuaciones diferenciales con función 'ODE´s' (Ordinary Difference Equation)
out <- ode(y = init, times = times, func = sir, parms = param)
#cambiar out a un data.frame
out <- as.data.frame(out*N) #aquí puede multiplicar 'out' por N
#eliminar la variable 'time' en out
out$time <- NULL
#mostrar 10 primeros datos
head(out,50)
## S I R
## 1 12699.99 0.01270000 0.000000e+00
## 2 12699.98 0.01532583 2.314775e-03
## 3 12699.98 0.01849417 5.107787e-03
## 4 12699.97 0.02231729 8.478019e-03
## 5 12699.96 0.02693071 1.254494e-02
## 6 12699.95 0.03249781 1.745258e-02
## 7 12699.94 0.03921573 2.337473e-02
## 8 12699.92 0.04732236 3.052109e-02
## 9 12699.90 0.05710475 3.914474e-02
## 10 12699.88 0.06890929 4.955105e-02
## 11 12699.85 0.08315399 6.210852e-02
## 12 12699.82 0.10034321 7.726182e-02
## 13 12699.78 0.12108559 9.554753e-02
## 14 12699.74 0.14611554 1.176131e-01
## 15 12699.68 0.17631925 1.442400e-01
## 16 12699.61 0.21276603 1.763709e-01
## 17 12699.53 0.25674613 2.151434e-01
## 18 12699.43 0.30981640 2.619305e-01
## 19 12699.31 0.37385532 3.183885e-01
## 20 12699.16 0.45112936 3.865162e-01
## 21 12698.99 0.54437310 4.687253e-01
## 22 12698.78 0.65688576 5.679260e-01
## 23 12698.52 0.79210058 6.871467e-01
## 24 12698.21 0.95535466 8.310960e-01
## 25 12697.84 1.15225664 1.004723e+00
## 26 12697.40 1.38971476 1.214125e+00
## 27 12696.86 1.67608609 1.466680e+00
## 28 12696.21 2.02143536 1.771275e+00
## 29 12695.42 2.43789355 2.138626e+00
## 30 12694.48 2.94008030 2.581654e+00
## 31 12693.34 3.54561089 3.115935e+00
## 32 12691.96 4.27570557 3.760242e+00
## 33 12690.31 5.15592071 4.537207e+00
## 34 12688.31 6.21702519 5.474096e+00
## 35 12685.90 7.49561961 6.603381e+00
## 36 12683.00 9.03663138 7.964977e+00
## 37 12679.50 10.89357707 9.606505e+00
## 38 12675.28 13.13068232 1.158523e+01
## 39 12670.20 15.82516052 1.397014e+01
## 40 12664.09 19.06960206 1.684423e+01
## 41 12656.72 22.97491938 2.030723e+01
## 42 12647.85 27.67379226 2.447897e+01
## 43 12637.17 33.32466397 2.950323e+01
## 44 12624.33 40.11635054 3.555243e+01
## 45 12608.89 48.27329467 4.283305e+01
## 46 12590.35 58.06146868 5.159200e+01
## 47 12568.08 69.79488033 6.212396e+01
## 48 12541.38 83.84255647 7.477999e+01
## 49 12509.39 100.63576092 8.997710e+01
## 50 12471.12 120.67479709 1.082088e+02
#Plot
matplot(x = times, y = out, type = "l",
xlab = "Days since first infected", ylab = "Infected, Susceptible, Recovery", main = "",
lwd = 1, lty = 1, bty = "l", col = 4:00)
#añadir leyenda de líneas
legend(90, 7500, c("Recovery R(t)", "Infected I(t)", "Susceptible S(t)"),
pch = 1, col = 2:4, bty = "n", cex = 1)

#REFERENCES
#Ávila Ayala, Rocio Maribel (2016). Inferencia de modelos epidemiológicos compartimentales en redes sociales. Centro de Investigación en Matemáticas, A.C.
#Bailey, Norman T. J. (1975). The mathematical theory of infectious diseases and its applications (2nd ed.). London: Griffin.
#Guang W. et al. (2019) Clinical Characteristics of Coronavirus Disease 2019 in China The New England journal of medicine.