-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdcPlotsAge.m
159 lines (145 loc) · 4.28 KB
/
cdcPlotsAge.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
function f=cdcPlotsAge(x)
%x=sortrows(x,[2,3]);
byAge=0;
inds09=find(x(:,2)==2009);
inds10=find(x(:,2)==2010);
inds11=find(x(:,2)==2011);
x=x([inds09;inds10;inds11],:);
years=x(1,2):x(end,2);
%numyears=length(years);
twelve=kron((1:12)',ones(4,1));%No 5th weeks in data
four=1:4;
numyears=length(years);
y=[kron(years',ones(48,1)),repmat(twelve,numyears,1),repmat(four',12*numyears,1)];
y(:,4:18)=nan;
%y(:,3:17)=nan;
%Clunky way:
for i=1:numyears
xi=x(x(:,2)==years(i),:);
for j=1:12
month=find(xi(:,3)==j);
if isempty(month)==0%Assumes all for age groups present for each data point
xij=xi(month,:);
yind=(i-1)*48+(j-1)*4;
for k=1:4
age=xij(xij(:,4)==k,:);
age=nanmean(age,1);
y(yind+k,4:end)=age(5:end);
end
end
end
end
if byAge==1
incScaled=y(:,7).*y(:,17);%./y(:,8).*y(:,17);%.*y(:,15);%.*y(:,6);%.*y(:,end-1);
tvec1=y(1:4:end,1); tvec2=y(1:4:end,2);
tvec=1:size(incScaled,1)/4;
%tvec(isnan(incScaled))=[];
%tvec1(isnan(incScaled))=[];
%tvec2(isnan(incScaled))=[];
%incScaled(isnan(incScaled))=[];
inc1=incScaled(1:4:end);
inc2=incScaled(2:4:end);
inc3=incScaled(3:4:end);
inc4=incScaled(4:4:end);
f=[inc1,inc2,inc3,inc4];
jans=tvec(tvec2==1);%-.5;
ljans=length(jans);
fs=12; lw=2;
ticks=[1,13,25];
labs={'01/09','01/10','01/11'};
cmap=lines(4);
%
figure
hold on
mx=max(incScaled);
for j=1:ljans
plot([jans(j),jans(j)],[0,mx],'k--','linewidth',lw)
end
h1=plot(tvec,inc1,'-','linewidth',lw,'color',cmap(1,:));
h2=plot(tvec,inc2,'-','linewidth',lw,'color',cmap(2,:));
h3=plot(tvec,inc3,'-','linewidth',lw,'color',cmap(3,:));
h4=plot(tvec,inc4,'-','linewidth',lw,'color',cmap(4,:));
%Manual (for plotting):
%plot(tvec(5:12),incScaled(5:12),'-','linewidth',lw+1)
hold off
xlabel('Time (months)')
ylabel('Incidence (relative)')
%ylabel('Incidence (absolute)')
xvec=1:6:tvec(end);
set(gca,'xtick',ticks,'xticklabel',labs)
set(gca,'fontsize',fs)
ax=gca;
ax.XAxis.MinorTickValues=tvec;
axis([0,28,0,mx])%tvec(end)
legend([h1,h2,h3,h4],'0-4','5-19','20-64','65+')
grid on
grid minor
box on
else
incScaled=y(:,7).*y(:,17);%.*y(:,15);%.*y(:,6);%.*y(:,end-1);
pop=y(:,8);
pop1=pop(1:4:end);
pop2=pop(2:4:end);
pop3=pop(3:4:end);
pop4=pop(4:4:end);
pop=pop1+pop2+pop3+pop4;
tvec1=y(1:4:end,1); tvec2=y(1:4:end,2);
tvec=1:size(incScaled,1)/4;
%tvec(isnan(incScaled))=[];
%tvec1(isnan(incScaled))=[];
%tvec2(isnan(incScaled))=[];
%incScaled(isnan(incScaled))=[];
inc1=incScaled(1:4:end);
inc2=incScaled(2:4:end);
inc3=incScaled(3:4:end);
inc4=incScaled(4:4:end);
inc=(inc1+inc2+inc3+inc4);%./pop;
f=inc;
jans=tvec(tvec2==1);%-.5;
ljans=length(jans);
fs=12; lw=2;
ticks=[];%[1,13,25];
labs={'01/09','01/10','01/11'};
%
figure
hold on
mx=max(inc);
for j=1:ljans
plot([jans(j),jans(j)],[0,mx],'k--','linewidth',lw)
end
plot(tvec(4:12),inc(4:12),'k-','linewidth',lw);
%Manual (for plotting):
%plot(tvec(5:12),incScaled(5:12),'-','linewidth',lw+1)
hold off
xlabel('Time (months)')
ylabel('Incidence (relative)')
%ylabel('Incidence (absolute)')
set(gca,'xtick',ticks,'xticklabel',labs)
set(gca,'fontsize',fs)
ax=gca;
ax.XAxis.MinorTickValues=tvec;
axis([0,14,0,mx])%tvec(end)
grid on
grid minor
box on
end
%{
twelve=1:12;
years=x(1,2):x(end,2);
numyears=length(years);
months=[kron(years',ones(12,1)),repmat(twelve',numyears,1)];
weeks=[kron(months,ones(4,1)),repmat((1:4)',length(months),1)];
dummy=100*weeks(:,1)+weeks(:,2)+weeks(:,3)/4-.25;
y=weeks; y(:,4:size(x,2)-1)=nan;
%Clunky:
xyear=x(:,2); xmonth=x(:,3); xweek=x(:,4);
xdummy=100*xyear+xmonth+xweek/4-.25;
for i=1:length(xdummy)
%ind=find(dummy==xdummy(i));
y(dummy==xdummy(i),4:end)=x(i,5:end);
end
tvec2=num2str(tvec2); tvec2(isspace(tvec2))='0';
tlabs=strcat(num2str(tvec1),'/',tvec2);
tlabs=tlabs(:,3:end);
%tlabs=tlabs(find(~isspace(tlabs)));
%}