-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfwd_SEIRD_model.m
162 lines (131 loc) · 5.07 KB
/
fwd_SEIRD_model.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
function [y, B, new_infi, expbetai, inf_distrib, Reff] = fwd_SEIRD_model(params,tau_params,tvec, y0, dt, disease)
% This function runs the forward finite difference implementation of the
% SEIRD model, incorporating the time-dependent infectiousness by
% convolving beta(t) with I(t) at each time point...
P = num2cell(params);
Y = num2cell(y0);
[beta0, gamma, alpha, infend, trem]=deal(P{:});
switch disease
case 'COVID'
a= tau_params(1);
b = tau_params(2);
tind = tvec(1):dt:tvec(end);
tind = tind';
w_tau = gampdf(tind, a,b);
case 'SARS'
mu = tau_params(1);
sigma = tau_params(2);
tind = tvec(1):dt:tvec(end);
tind = tind';
w_tau = normpdf(tind, mu, sigma);
case 'flu'
a= tau_params(1);
b = tau_params(2);
tind = tvec(1):dt:tvec(end);
tind = tind';
w_tau = gampdf(tind, a,b);
end
beta_tau = beta0*w_tau;
%
[S0, E0, I0, Isr0, R0]=deal(Y{:});
S(1) = S0;
E(1) = E0;
I(1) = I0;
Isr(1) = Isr0;
R(1) = R0;
N = S0+E0+I0+Isr0+R0;
gamma = gamma; % Rate of going from exposed to infectious
beta0 = beta0; % Rate infected spread to susceptible
delta = 1/(infend-trem); % Rate of recovery from isolated = duration of infection- duration infected not isolated
infend = infend/dt+1; % time to be considered "recovered"
alpha = alpha; % Percent isolated at tremoved
irem = round(trem/dt+1,0);
% B keeps track of the individuals in each stage of infection (density of
B=zeros(length(tind), length(tind)); % start with no one infected
B(1,1) = I0; % first time point have one infected at age 1 of infection
%
for t = 2:length(tind)
% Use previus time step to update each compartment
% those in B matrix after time of being infectious become recovered
recovered = B(t-1, infend);
% alpha % of those after irem get put into isolation
isolated = alpha*(B(t-1,irem));
recoveredisolated = delta*Isr(t-1);
% remove the isolated from B matrix
B(t-1,irem) = B(t-1,irem)-(alpha.*B(t-1,irem));
Isr(t) = Isr(t-1) + dt*(isolated-recoveredisolated);
R(t) = R(t-1) + dt*(recovered + recoveredisolated);
% Take density of infectious infidivuals over infection age and
% multiply by weight of infection age
expbeta = sum(B(t-1,1:end-1)'.*beta_tau(2:end).*dt); % expectation of beta
pdf_inf = B(t-1,1:end-1)./sum(B(t-1,1:end-1));
beta_t = sum(pdf_inf'.*beta_tau(2:end)); % average/expected value of beta
% update S, E, and I accordingly
new_exposures = expbeta*S(t-1)./(N);
%new_exposures = expbeta*S(t-1)./(N-Isr(t-1)); % run if you want to remove isoalted from system
new_inf = gamma*E(t-1);
S(t) = S(t-1) - dt*(new_exposures);
E(t) = E(t-1) + dt*(new_exposures - new_inf);
I(t) = I(t-1) + dt*(new_inf - recovered -isolated);
% update B and count of new infections
B(t,1) = new_inf;
new_infi(t)=new_inf;
new_exp(t) = new_exposures;
expbetai(t) = beta_t;
inf_distrib(:,t) = beta0.*(B(t-1,:).*(w_tau./dt)'); % each column is a distribution of infectionusess
%Re(t) = new_infi(t)/I(t-1);
% update B by moving each infection along one step form previous
% infection
for i = 2:length(tind)
B(t,i) = B(t-1,i-1); % each time step, push infections along
end
end
y = horzcat(S',E',I', Isr', R');
S(1) = S0;
E(1) = E0;
I(1) = I0;
Isr(1) = Isr0;
R(1) = R0;
N = S0+E0+I0+Isr0+R0;
B2=zeros(length(tind), length(tind)); % start with no one infected
B2(1,1) = I0; % first time point have one infected at age 1 of infection
%
% Estimate Reff
sec_inf=0;
new_inf2(1) = 0;
expbetat(1) = 0;
for t = 2:length(tind)
% Use previus time step to update each compartment
% those in B matrix after time of being infectious become recovered
recovered = B2(t-1, infend);
% alpha % of those after irem get put into isolation
isolated = alpha*(B2(t-1,irem));
recoveredisolated = delta*Isr(t-1);
% remove the isolated from B matrix
B2(t-1,irem) = B2(t-1,irem)-(alpha.*B2(t-1,irem));
Isr(t) = Isr(t-1) + dt*(isolated-recoveredisolated);
R(t) = R(t-1) + dt*(recovered + recoveredisolated);
% Take density of infectious infidivuals over infection age and
% multiply by weight of infection age
expbeta = sum(B2(t-1,1:end-1)'.*beta_tau(2:end).*dt); % expectation of beta
% update S, E, and I accordingly
new_exposures = expbeta*S(t-1)./(N);
expbetat(t) = expbeta;
%new_exposures = expbeta*S(t-1)./(N-Isr(t-1)); % run if you want to remove isoalted from system
new_inf = gamma*E(t-1);
S(t) = S(t-1) - dt*(new_exposures);
E(t) = E(t-1) + dt*(new_exposures- new_inf);
I(t) = I(t-1) + dt*(new_inf- recovered - isolated);
% update B and count of new infections
new_inf2(t) = new_inf;
sec_inf = sec_inf + new_inf;
%Re(t) = new_infi(t)/I(t-1);
% update B by moving each infection along one step form previous
% infection
for i = 2:length(tind)
B2(t,i) = B2(t-1,i-1); % each time step, push infections along
end
B2(t,1) = 0;
end
Reff = sec_inf./I0;
end