-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdcPandemicSimulationW5subFull.m
346 lines (343 loc) · 10.1 KB
/
cdcPandemicSimulationW5subFull.m
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
function [f,g,z2]=cdcPandemicSimulationW5subFull(params,xdata,plotComp,plotEpis,ydata,tswitch)%(R0,phi1,phi2,tlag,seednum,tswitch,closureFactor,betacModifier)
%V: antiViral treatment
%plotComp: plot comparison (with data)
%plotEpis: plot incidence (non-aggregated)
foi=1;%1 for sum(I_j/N_j), 2 for (sum I_j)/N
ages=5;
if ages==4
%death=[.005,.0072,.04,.079]'/100;
hosp=[.042,.016,.029,.166]';
NNbar=[19169690;62121035;184015269;39570590];
Cc=[27.57920413,8.051767033,4.975736133,0.850626995;
9.165259795,43.43045174,8.195858852,2.158756533;
5.941537452,5.863025518,14.20166331,5.533694466;
0.600583289,0.807369258,1.39444674,7.848296781]';
tdays=30;%Days per month
simCut=3;%Cut this many months from start of year
legString={'0-4','5-19','20-64','65+'};
from57=13/45;
t1=1;%Plot data from month t1
elseif ages==5
NNbar=[1464566;3790730;10236474;3984200;2412129];
hosp=1./[393.0256 999.3054 702.6867 406.0680 177.1958]';
Cc=[1.9200 0.4268 0.4600 0.4434 0.1665;
1.7600 8.7522 2.4600 1.8630 1.2190;
0.4500 0.4911 2.5900 0.8132 0.3412;
4.5200 4.9913 5.6500 6.9995 4.3001;
0.2300 0.2975 0.4300 0.6903 1.8930]';
tdays=7;%Days per week
simCut=16;%Cut this many weeks from start of year
legString={'0-4','5-17','18-24','25-64','65+'};
from57=8/30;
t1=18;%Plot data from week t1
end
%
tswitchAttack=243;%Always calculate attck rate from here
%Changes for closure:
logPlots=0;
byAge=1;%=0 for global incidence plot, =1 to stratify by age - f
ageInc=1;%Total or age-specific incidence out (before aggregated) - g
relInc=0;%Relative incidence - fraction of age group population - both
immuneFactor=0;%In over 52s (born pre-1957) %W5*
%%
%Fixed parameters:
R0=1.6/.775;%1.4065; 1.4082;%
seednum=4;%2.9756;
%tswitch=243;
betacModifier=1;
closureFactor=0.5844;
tshift=-1;
seasonality=1;%On
ftimes=1;
tclose=10^4;
phi1=1;
phi2=0;
tlag=0;%Days
gamma=.38;%.3362;
tau=0;
tv=0;
sub=.99;%Relative size of sub-population
eps=10e-4;%School closure coupling
%%
%Input parameters:
%
seednum=params(1);
closureFactor=params(2);
immuneFactor=params(3);%[4,.42,.2,1.38,.38]
%sub=params(4);
%eps=params(5);
%monthShift=params(3);
%tswitch=params(3);
phi2=params(4);
phi1=1-phi2;
%}
%
%propSymp=params(end-2);
R0=params(end-1);
gamma=params(end);
%}
%phi2=1-phi1;
%%
%gamma=1/TR;
gammabar=1/(1/gamma-1/tau-1);
nbar=length(NNbar);
NN=sum(NNbar);
NNrep=repmat(NN,nbar,1);
%Age mixing:
%USA:
Co=Cc;
%Cc(2:3,2:3)=closureFactor*Co(2:3,2:3);
Cc(2,2)=closureFactor*Co(2,2);
if ages==4
zn=zeros(nbar,1);
y0=[NNbar;zn;zn;zn;zn];
a3out=y0(nbar-1)*immuneFactor*from57;
y0(4)=y0(4)-a3out; y0(end-nbar-1)=a3out;
a4out=y0(nbar)*immuneFactor;
y0(5)=y0(5)-a4out; y0(end-nbar)=a4out;
elseif ages==5
zn=zeros(nbar,1);
y0=[NNbar;zn;zn;zn;zn];
a4out=y0(nbar-1)*immuneFactor*from57;
y0(4)=y0(4)-a4out; y0(end-nbar-1)=a4out;
a5out=y0(nbar)*immuneFactor;
y0(5)=y0(5)-a5out; y0(end-nbar)=a5out;
end
y0=[sub*y0;(1-sub)*y0];
%Calculate betas:
%
NNbar=[sub*NNbar;(1-sub)*NNbar];
NNrep=[sub*NNrep;(1-sub)*NNrep];
Sstart=repmat(NNbar,1,2*nbar);%Ni
Mj=NNbar'; Mj(Mj==0)=1; Mjover=1./Mj;
Mjover=repmat(Mjover,2*nbar,1);%1/Nj
if foi==1
Dc=(Sstart.*Mjover).*repmat(Cc,2,2);
Dc=Dc.*kron([1,eps;eps,1],ones(nbar));
Gc=1/gamma*Dc;
d=eigs(Gc,1); R0c=max(d); betac=R0/R0c*betacModifier;
Do=(Sstart.*Mjover).*repmat(Co,2,2);
%Do=kron(ones(2),Do);
Go=1/gamma*Do;
d=eigs(Go,1); R0o=max(d); betao=R0/R0o;
%}
elseif foi==2
Dc=Sstart.*repmat(Cc,2,2)/NN;
Dc=Dc.*kron([1,eps;eps,1],ones(nbar));
Gc=1/gamma*Dc;
d=eigs(Gc,1); R0c=max(d); betac=R0/R0c*betacModifier;
Do=(Sstart.*Mjover).*repmat(Co,2,2);
%Do=kron(ones(2),Do);
Go=1/gamma*Do;
d=eigs(Go,1); R0o=max(d); betao=R0/R0o;
end
betac=betao*betacModifier;%Assume R0 fitted to Oct wave
%betao=betac;
%}
%%
%For simulation:
t0=0; tend=450;
%Ni=repmat(NN0,1,nbar); Nj=Ni';
%
if foi==1
Dc=kron([1,eps;eps,1],Cc);
Do=repmat(Co,2,2);
NN0=NNbar;
NN0(NN0==1)=1;
elseif foi==2
Dc=kron([1,eps;eps,1],Cc).*Mjover*NN;
Do=repmat(Co,2,2).*Mjover*NN;
NN0=NNrep;
NN0(NNrep==0)=1;
end
%}
seed=10^(-seednum);
%%
%Do=kron(ones(2),Do);
%Dc=kron([1,eps;eps,1],Dc);
%NNbar=[sub*NNbar;(1-sub)*NNbar];
%NN0=[sub*NN0;(1-sub)*NN0];
%y0=[sub*y0;(1-sub)*y0];
%%
%Simulate:
%ODE solver:
%if solvetype==2
[tout,yout]=ode45(@(t,y)integr8all(t,y,betac,betao,gamma,tau,gammabar,nbar,NN0,Dc,Do,seasonality,phi1,phi2,seed,hosp,tlag,tswitch,tclose,tv),[t0,tend],y0);
%Incidence curve in here:
Y=yout(:,1:nbar);
Y=-diff(Y,1,1);
tdiff=diff(tout);
Y=Y./repmat(tdiff,1,nbar);
tout=tout(2:end);
if ageInc==1
g=[tout,Y];
else
g=[tout,sum(Y,2)];
end
z2=sum(Y(tout>tswitchAttack,:),1);
if relInc==1
if byAge==1
NNdiv=repmat(NNbar',size(Y,1),1);
Y=Y./NNdiv;
else
Y=sum(Y,2)/NN;
end
elseif byAge==0
Y=sum(Y,2);
end
%
if plotEpis==1
figure
fs=12; lw=2;
colormap lines
if logPlots==0
plot(tout,Y,'linewidth',lw);
elseif logPlots==1
semilogy(tout,Y,'linewidth',lw);
end
xlabel('Time (days)','FontSize',fs);
ylabel('Incidence','FontSize',fs);
set(gca,'FontSize',fs);
maxY=max(max(Y));
axis([0,tend,0,maxY]);
if byAge==1
legend(legString,'location','NW')
end
grid on
grid minor
box on
hold off
end
tmonth=ceil(tout/tdays);%+tshift);
tmonth(tmonth==0)=1;
if byAge==1
f1=accumarray(tmonth,Y(:,1));
f2=accumarray(tmonth,Y(:,2));
f3=accumarray(tmonth,Y(:,3));
f4=accumarray(tmonth,Y(:,4));
if ages==4
fall=ftimes*[f1,f2,f3,f4];
else
f5=accumarray(tmonth,Y(:,5));
fall=ftimes*[f1,f2,f3,f4,f5];
end
fall(1:simCut,:)=[];
if plotComp==1
figure
fs=12; lw=2;
maxf=max(max([fall;ydata]));
cmap=lines(nbar);
hold on
simVec=simCut+1:simCut+size(fall,1);
h1=plot(simVec,ftimes*fall(:,1),'linewidth',lw,'color',cmap(1,:));
h2=plot(simVec,ftimes*fall(:,2),'linewidth',lw,'color',cmap(2,:));
h3=plot(simVec,ftimes*fall(:,3),'linewidth',lw,'color',cmap(3,:));
h4=plot(simVec,ftimes*fall(:,4),'linewidth',lw,'color',cmap(4,:));
if ages==5
h5=plot(simVec,ftimes*fall(:,5),'linewidth',lw,'color',cmap(5,:));
end
plotVec=t1:t1+size(ydata,1)-1;
plot(plotVec,ydata(:,1),'--','linewidth',lw,'color',cmap(1,:))
plot(plotVec,ydata(:,2),'--','linewidth',lw,'color',cmap(2,:))
plot(plotVec,ydata(:,3),'--','linewidth',lw,'color',cmap(3,:))
plot(plotVec,ydata(:,4),'--','linewidth',lw,'color',cmap(4,:))
if ages==5
plot(plotVec,ydata(:,5),'--','linewidth',lw,'color',cmap(5,:))
end
xlabel('Time (weeks)','FontSize',fs);
ylabel('Incidence','FontSize',fs);
set(gca,'FontSize',fs);
axis([simCut+1,size(fall,1),0,maxf]);%tend
if ages==4
legend([h1,h2,h3,h4],legString,'location','NW')
else
legend([h1,h2,h3,h4,h5],legString,'location','NW')
end
%legend([h1,h2,h3,h4,h5],legString,'location','NW')
grid on
grid minor
box on
hold off
end
else
fall=ftimes*accumarray(tmonth,Y);
if relInc==1
ydata=sum(ydata,2)/NN;
else
ydata=sum(ydata,2);
end
if plotComp==1 %&&
figure
fs=12; lw=2;
fall=accumarray(tmonth,Y);
fall(1:simCut)=[];
maxf=max([fall;ydata]);
hold on
%plot([1,1],[0,maxf],'k--','linewidth',lw)
%plot([12,12],[0,maxf],'k--','linewidth',lw)
h1=plot(1:length(fall),ftimes*fall,'linewidth',lw);
h2=plot(t1:size(ydata,1),ydata(t1:end,1),'--','linewidth',lw);
xlabel('Time (months)','FontSize',fs);
ylabel('Incidence','FontSize',fs);
set(gca,'FontSize',fs);
axis([0,size(ydata,1),0,maxf]);%tend
legend([h1,h2],'Sim','Data','location','NW')
grid on
grid minor
box on
hold off
end
end
f=fall(xdata,:);
end
%%
function f=integr8all(t,y,betac,betao,gamma,tau,gammabar,nbar,NNin,Dc,Do,seasonality,phi1,phi2,seed,hosp,tlag,tswitch,tclose,tv)
propSym=.55;%Data
relInf=.5;%Data
mu=[.005,.0072,.04,.079,1.57]'/100;%Data
mu=repmat(mu,2,1);
if seasonality==1
phi=phi1-phi2*cos(pi*(t-tlag)/180);
else
phi=1;
end
if t<tswitch || t>tclose
XX=Dc;
beta=betac;
else
XX=Do;
beta=betao;
end
S=[y(1:nbar);y(5*nbar+1:6*nbar)];
%I=y(nbar+1:2*nbar);
%IV=y(2*nbar+1:3*nbar);
IS=[y(nbar+1:2*nbar);y(6*nbar+1:7*nbar)];
IA=[y(2*nbar+1:3*nbar);y(7*nbar+1:8*nbar)];
if t<30
seed1=seed.*S./NNin;
seed1(5*nbar+1:end)=0;%Seed onbly sub population
else
seed1=0;
end
if t<tv
taux=0;
else
taux=tau;
end
Sfoi=phi*(beta*S.*(XX*((IS+relInf*IA)./NNin)+seed1));
%{
Sdot=-Sfoi;
Idot=Sfoi-gamma*I-.55*taux*I.*hosp;
IVdot=.55*taux*I.*hosp-gammabar*IV;
Rdot=gamma*I+gammabar*IV;
f=[Sdot;Idot;IVdot;Rdot];
%}
Sdot=-Sfoi;
ISdot=propSym*Sfoi-gamma*IS-mu.*IS;%-.55*taux*I.*hosp;
IAdot=(1-propSym)*Sfoi-gamma*IA;
%IVdot=.55*taux*I.*hosp-gammabar*IV;
Rdot=gamma*(IS+IA);%+gammabar*IV;
Ddot=mu.*IS;
f=[Sdot(1:nbar);ISdot(1:nbar);IAdot(1:nbar);Rdot(1:nbar);Ddot(1:nbar);
Sdot(nbar+1:end);ISdot(nbar+1:end);IAdot(nbar+1:end);Rdot(nbar+1:end);Ddot(nbar+1:end)];
end