summedhist=zeros(2400,1);
SD_remaining_states=12/sqrt(19)*sqrt(2); % sqrt(2) to combine SD of Trump and whoever is at #2
for ibias=-40:1:50
    close
    biaspct=ibias/5*SD_remaining_states; % sweep through. any constant term is Cruz bonus
    GOP_delegate_estimator_20april2016
    summedhist(fixeddels+(1:length(histogram)))=summedhist(fixeddels+(1:length(histogram)))+histogram' * tpdf(ibias/5,3);
end
histogram=summedhist/sum(summedhist);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Plot the histogram %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close
%figure('Color', 'w')
phandle=plot([1237 1237],[0 max(histogram)*110],'-r','LineWidth',1.5);
leftrange=0;
EVticks=920:50:1500;
grid on
hold on
bar(histogram*100)
axis([min(EVticks) max(EVticks) 0 max(histogram)*110])
xlabel('Total delegates for Trump','FontSize',14);
ylabel('Probability of exact # (%)','FontSize',14)
set(gcf, 'InvertHardCopy', 'off');
% title('Distribution of possible delegates 3/15 to last primary','FontSize',14)
text(min(EVticks)+3,max(histogram)*104,'Under 1237','FontSize',14)
text(max(EVticks)-140,max(histogram)*104,'Over 1237','FontSize',14)
if analysisdate==0
    datelabel=datestr(now);
else
    datelabel=datestr(analysisdate);
end
text(min(EVticks)+3,max(histogram)*17,datelabel(1:6),'FontSize',12)
text(min(EVticks)+3,max(histogram)*11,'election.princeton.edu','FontSize',12)

cumul=cumsum(histogram);
median_delegates=min(find(cumul>0.5))
IQR_delegates=[min(find(cumul>0.25)) min(find(cumul>0.75))]
prob_Trump_gt_1237=1-cumul(1236)