-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimul_SIR.R
148 lines (107 loc) · 4.03 KB
/
simul_SIR.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
library(EpiModel)
library(tidyverse)
##########################################################################-
# Parámetros
# Lambda - tiempo de infección
l = 1/7
# R0
R = 2.56
# Fuerza de infección
lambda <- l*R
# Tasa de contacto por persona
c = 10
# Probabilidad de infección
beta <- lambda/c
# Tasa de natalidad
a = 16.3/(1000*365)
# Tasa de mortalidad
m = 5.50/(1000*365)
# Tasa de mortalidad
m_c = 3/100
##########################################################################-
# Población Colombiana
P = 49070000
PE = P * 0.55 * 0.7979706
init <- init.dcm(s.num = PE, i.num = 58, r.num = 1)
control <- control.dcm(type = "SIR", nsteps = 500, dt = 0.5)
param <- param.dcm(inf.prob = beta, act.rate = c, rec.rate = l,
a.rate = a, ds.rate = m, di.rate = m_c, dr.rate = m)
mod0 <- dcm(param, init, control)
param1 <- param.dcm(inf.prob = beta, act.rate = c, rec.rate = l,
a.rate = a, ds.rate = m, di.rate = m_c, dr.rate = m,
inter.start = 15, inter.eff = 1 - 0.8)
mod1 <- dcm(param1, init, control)
param2 <- param.dcm(inf.prob = beta, act.rate = c, rec.rate = l,
a.rate = a, ds.rate = m, di.rate = m_c, dr.rate = m,
inter.start = 15, inter.eff = 1 - 0.6)
mod2 <- dcm(param2, init, control)
##########################################################################-
# Rearreglo de tabla
data_EPI <- function(m) {
Svec = m$epi$s.num
Ivec = m$epi$i.num$run1
Rvec = m$epi$r.num$run1
data_table <- Svec %>%
rownames_to_column(var = 'Tiempo') %>%
rename(S = run1) %>%
as_tibble(.) %>%
add_column(I = Ivec) %>%
add_column(R = Rvec) %>%
gather(S, I, R, key = 'Tipo', value = 'No') %>%
mutate(Tiempo = as.double(Tiempo))
return(data_table)
}
dataCol <- data1 %>%
filter(location == 'Colombia')
finit <- as.Date("2020/03/06", "%Y/%m/%d")
df1 <- data_EPI(mod0) %>%
mutate(Fecha = Tiempo + finit - 15) %>%
filter(Tipo == 'I')
df2 <- data_EPI(mod1) %>%
mutate(Fecha = Tiempo + finit - 15) %>%
filter(Tipo == 'I')
df3 <- data_EPI(mod2) %>%
mutate(Fecha = Tiempo + finit - 15) %>%
filter(Tipo == 'I')
GEPI1 <- ggplot(df1, aes(x = Tiempo, y = No,
group = Tipo, colour = Tipo)) +
geom_line(col = 'red') +
geom_line(data = df2, col = 'blue3') +
geom_line(data = df3, col = 'green3') +
geom_point(data = dataCol,
aes(x = dd + 15, y = total_cases),
inherit.aes = FALSE) +
ylab('No. de infectados') +
labs(caption = 'Creado DSPG')
GEPI2 <- GEPI1 + coord_cartesian(xlim = c(0, 100),
ylim = c(0, 2.50E+4))+
theme(legend.position="none", axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),axis.title.y=element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_rect(color="red1", fill="white"),
plot.margin = unit(c(0,0,-6,-6),"mm"), plot.caption = element_blank())
t <- ggplotGrob(GEPI2)
GEPI1 +
annotation_custom(grob = t,
xmin = 500, xmax = 1000,
ymin = 2.2E6, ymax = 4E6)
ggplot(df1, aes(x = Fecha, y = No,
group = Tipo, colour = Tipo)) +
geom_line(col = 'red') +
geom_line(data = df2, col = 'blue3') +
geom_line(data = df3, col = 'green3') +
scale_color_discrete() +
ylab('No. de infectados') +
labs(caption = 'Creado DSPG')
##########################################################################-
# Simulación estocástica --------------------------------------------------
##########################################################################-
# initS <- init.icm(s.num = PE, i.num = 58, r.num = 1)
# controlS <- control.icm(type = "SIR", nsteps = 500, nsims = 1)
# paramS <- param.icm(inf.prob = beta, act.rate = c, rec.rate = l,
# a.rate = a, ds.rate = m, di.rate = m_c, dr.rate = m)
#
# modS <- icm(paramS, initS, controlS)
#
#