# Princeton Election Consortium

## National margin prediction – Bayesian combination of national/state

% First, input parameters (passed to it or here, entered manually)
% Where are we today?
MM=2.9; % today’s Meta-Margin
MMdrift=1;

% cover range of +/-5 sigma
Mrange=[MM-5*MMdrift:0.02:MM+5*MMdrift];

% What is near-term drift starting from conditions now?
now=tpdf((Mrange-MM)/MMdrift,3); % long-tailed distribution. you never know.
now=now/sum(now);

% What is the national-poll expectation? (the prior)
M2012=0; M2012SD=1.75; % parameters from national polls
prior=tpdf((Mrange-M2012)/M2012SD,3); % long-tailed, a loose prior
prior=prior/sum(prior);

% Combine to make prediction
pred=now.*prior; % All hail Reverend Bayes
pred=pred/sum(pred);

plot(Mrange,now,’-k’) % drift from today
hold on
plot(Mrange,prior,’-g’) % the prior
plot(Mrange,pred,’-r’) % the prediction
grid on
axis([-2.5 7 0 0.008])
xlabel(‘Obama-Romney margin (%)’)
ylabel(‘Relative probability’)

% Define mean and error bands for prediction
predictmean=sum(pred.*Mrange)/sum(pred)
for i=1:length(Mrange)
cumulpredict(i)=sum(pred(1:i));
end
Msig1lo=Mrange(min(find(cumulpredict>normcdf(-1,0,1))))
Msig1hi=Mrange(min(find(cumulpredict>normcdf(+1,0,1))))
Msig2lo=Mrange(min(find(cumulpredict>normcdf(-2,0,1))))
Msig2hi=Mrange(min(find(cumulpredict>normcdf(+2,0,1))))

popularvote_winprob=sum(pred(find(Mrange>=0)))/sum(pred)