Senate_history=load('Senate_estimate_history.csv'); d=Senate_history(:,1); mm=Senate_history(:,12); systematic=3; % Guess at systematic error this year blackswanfactor=3; % a 7% probability of >2 sigma event; allows for outlier events, similar to EV %%%%% Calculate November prediction based on Meta-Margin history [C,IA,IC] = unique(d,'stable'); % Find unique entries in the history mean_mm=mean(mm(IA(find(d(IA)>=153)))); % This is the long-term prediction... sd_mm=std(mm(IA(find(d(IA)>=153)))); % ...based on data after June 1 (Julian 153) h=datenum('08-Nov-2016')-today; % days until election (note: November 8, Julian 314) if and(h<=35,h>=0) % election is soon, so combine current and long-term blackswanfactor=3; current_mm=mm(max(find(d==max(d)))); % Find the most recent Meta-Margin predicted_mm=mean_mm*(1-sqrt(1-h/35))+current_mm*sqrt(1-h/35); %random walk-like predicted_sd=sqrt((sd_mm*h/35)^2+systematic^2); D_November_control_probability = 100*tcdf(predicted_mm/predicted_sd,blackswanfactor) else % election is far off, so use the long-term prediction predicted_mm=mean_mm; predicted_sd=sqrt(sd_mm^2+systematic^2); D_November_control_probability = 100*tcdf((mean_mm)/predicted_sd,blackswanfactor) end dlmwrite('Senate_D_November_control_probability.csv',[today-datenum('31-Dec-2015') D_November_control_probability predicted_mm]) %%%%% end November prediction calculation