For the assignment of calculating various probability distributions with given forecast and observed data, I wrote a script with Matlab to handle the process of making counts from the data and calculating probabilities based on those counts. This initially required the forecast and observed data to be added as arrays in Matlab using the “Import Data” tool. After these data were added, the steps listed below were taken. The blocks of code show examples of how this work could be done with Matlab. These examples assume one set of forecasts and corresponding observations for a dichotomous (yes or no) event. Therefore, a 2x2 contingency table is used to calculate the respective probability distributions. 1. Make a scatter plot of the joint distribution of forecasts and observations
figure scatter(forecasts(:),observations(:),'.'); title('Joint Distribution of Forecasts and Observations') xlabel('Forecasts') ylabel('Observations') 2. Create 2-D array to represent the contingency table (R-forecasts, C-observations)
contingency_table(1:2,1:2) = 0; for k=1:length(forecasts); if forecasts(k) == 1 i = 1; else i = 2; end if observations(k) == 1 j = 1; else j = 2; end contingency_table(i,j) = contingency_table(i,j) + 1; end
joint(1:2,1:2) = 0; joint(:,:) = contingency_table(:,:)/N;
fcount(1:2,1) = 0; xcount(1,1:2) = 0;
for i=1:length(contingency_table) fcount(i,:) = sum(contingency_table(i,:)); xcount(:,i) = sum(contingency_table(:,i)); end
pf(1:2,1) = 0; px(1,1:2) = 0; for i=1:length(pf); pf(i,1) = fcount(i,1)/length(forecasts); px(1,i) = xcount(1,i)/length(observations); end
pfx(1:2,1:2) = 0; pxf(1:2,1:2) = 0;
for i=1:length(pf); for j=1:length(px); if px(j) == 0 pfx(i,j) = NaN; elseif pf(i) == 0 pxf(i,j) = NaN; else pfx(i,j) = joint(i,j)/px(j); pxf(i,j) = joint(i,j)/pf(i); end end end
avg_f = mean(forecasts(:)); avg_o = mean(observations(:)); bias = avg_f - avg_o; |
Purdue High Impact Weather Laboratory > Archive > Forecast Verification - EAS 591 - Fall 2012 > HW #2 >