Princeton Election Consortium

A first draft of electoral history. Since 2004

MATLAB – shade plot, national polls

first=[17 17 15 18 13 12 14 11 13 12 11 10 12 11 10 7 7 7 5 8 8 7 5 6 5 5 5 4 4 0 4 2 1 -2 -1 2 0 -1 -1 -2 -3 -3 -3 -4 -4 -5 -3 -4 -7 -4];
last=[19 19 19 18 18 18 16 16 15 14 14 14 13 13 13 13 12 11 11 10 10 9 9 8 8 7 7 7 7 6 4 4 4 4 3 2 2 1 1 0 0 0 0 0 0 0 -1 -1 -1 -2];
m=[2 -1 3 -2 2 -6 -1 3 1 -4 -1 1 3 -2 3 -3 0 1 -2 -1 1 -1 0 3 -1 0 0 -4 -2 1 -1 2 1 5 6 4 4 1 5 3 3 0 4 3 7 4 9 2 3 2];

i1=min([first last]);
i2=max([first last]);
n=last-first+1;
for i=1:i2-i1+1
d(i)=i1+i-1;
inds=intersect(find(d(i)>=first),find(d(i)<=last));
inds=intersect(inds,[1:29 31 33:50]);
mavg(i)=sum(m(inds)./n(inds))/sum(1./n(inds));
msem(i)=std(m(inds))./sqrt(length(inds));
end

shadedplot(d,mavg-msem,mavg+msem,’y')
hold on
plot(d,mavg,’-k’)
plot(d,mavg,’.k’)
grid on
plot(d,mavg+msem,’-r’)
plot(d,mavg-msem,’-r’)
axis([-5 20 -3 7])
set(gca,’xtick’,[-7:7:28])
xlabel(‘October 2012′)
ylabel(‘Obama-Romney margin (%)’)

plot(mmd-1,mm,’-b’)
plot(mmd-1,mm,’.b’)