-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMake_Growth_Rate_Table.m
72 lines (65 loc) · 1.9 KB
/
Make_Growth_Rate_Table.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
function [gr_rate,kept_states] = Make_Growth_Rate_Table(app,nf,DATA)
% Make_Growth_Rate_Table(app)
% This function calculates and makes a table for the growth rates of the
% pandemic in each individual country or state. Uses the JHU COVID-19 data
% as requested in the COVID19_Matlab_App GUI (app).
% Create lists of all (B) and selected (A) countries/states.
if app.CountryButton.Value
ListA = app.countries.Items;
ListB = app.Countries;
elseif app.RegionButton.Value
ListB = app.States;
ListA = app.States;
ListA=ListA(~strcmp(ListA,''));
end
if nargin<2
nf = app.days_for_trend.Value;
DATA = app.DATA;
elseif nargout>=1
clear ListA ListB
for i = 1:size(DATA,1)
ListA(i) = {num2str(i)};
ListB(i) = {num2str(i)};
end
end
kept_states = zeros(size(DATA,1),1,'logical');
NC = length(ListA);
N = size(DATA,2);
xf = [0:nf]';
j = 0;
if app.abs_2.Value
cut_off_for_trend = 10;
else
cut_off_for_trend = 0.01;
end
% Iterate through all selected states/countries and collect the
% corresponding data.
Data = {};
for i=1:NC
I = ismember(ListB,ListA{i});
inf_vs_t = sum(DATA(I,:),1);
if inf_vs_t(end)>cut_off_for_trend % Ignore regions with too few infections.
j=j+1;
% Perform regression to find log-slope.
Y = log(inf_vs_t(N-nf:N))';
x = xf(isfinite(Y));
Y = Y(isfinite(Y));
Q=[]; Q(:,1) = x'; Q(:,2)=1; M = Q\Y;
M(1) = max(M(1),0);
Data(i,1:2) = {ListA{i},log(2)./M(1)};
kept_states(i) = 1;
else
kept_states(i) = 0;
Data(i,1:2) = {ListA{i},inf};
end
end
Data = Data(kept_states,:);
if nargout>=1
gr_rate = [Data{:,2}]';
return
end
% Sort growth rates fastest to slowest.
[~,I] = sort([Data{:,2}],'ascend');
app.gr_table.Data = Data(I,:);
% Make Histogram of growth rates.
histogram(app.gr_hist,[app.gr_table.Data{:,2}],[0:2:30],'Normalization','probability');