function analyse (wfb) [numcountries numdimns] = size (wfb); dimension_labels = strvcat('total area', 'land area', 'total borders', 'arable land', 'population', 'population growth rate', 'birth rate', 'death rate', 'net migration rate', 'infant mortality rate', 'life expectancy at birth total', 'literacy total population', 'total fertility rate', 'total labor force', 'national product', 'national product real growth rate', 'national product per capita', 'unemployment rate', 'budget expenditures', 'exports total', 'imports total', 'external debt', 'electricity capacity', 'electricity production', 'electricity consumption per capita', 'highways total', 'airports total', 'television broadcast stations', 'defense expenditures number'); negzeros = zeros (numdimns); % number of zeros and negatives that were thrown out for i=1:numdimns %For each dimension, plot two histograms -- one regular, and other log %We have 29 dimensions, remove NaNs for plotting wfbi = wfb(:,i); wfbi(isnan(wfbi)) = []; subplot (3,2,1); hist(wfbi, 20); title (dimension_labels(i,:)); label = sprintf('%d samples', length(wfbi)); xlabel(label); %Log of non-zero or negative samples not possible, filter them out wfbi_nz = filterzeroneg(wfbi); subplot (3,2,2); hist (log(wfbi_nz),20); title (dimension_labels(i,:)); label = sprintf('%d samples, Log-scale', length(wfbi_nz)); xlabel (label); % sort the data in descending order and plot wfbi_sorted = sort (wfbi* -1) * -1; wfbi_log_sorted = sort (log (wfbi_nz) * -1) * -1; % do kmeans clustering [cluster_ids, centroids, sumdistances] = kmeans (wfbi_sorted,3); % do the same on log of the data [log_cluster_ids, log_centroids, log_sumdistances] = kmeans (wfbi_log_sorted,3); % We need to find the edges of these clusters that kmeans found for % us, so we can partition the space. edges = find_edges (cluster_ids); log_edges = find_edges (log_cluster_ids); subplot (3,2,3); plot (wfbi_sorted); hold on; plot (edges(1), 0, '*'); plot (edges(2), 0, '*'); hold off; %label = sprintf('%d samples, sorted', length(wfbi)); %title (label); % on a log scale subplot (3,2,4); plot (wfbi_log_sorted); hold on; plot (log_edges(1), '*'); plot (log_edges(2), '*'); hold off; %label = sprintf('%d samples, sorted, log-scale', length(wfbi_nz)); %title (label); % normplot subplot (3,2,5); normplot (wfbi); %cdfplot subplot (3,2,6); cdfplot (wfbi); pause; %filename = sprintf('%d.eps', i); %print ('-f1', '-deps', filename); end function x_nz = filterzeroneg(x) nz_array_index = 1; x_nz = []; for j =1:length(x) if sign (x(j)) > 0 % since the array is shrinking the old dimensions might become % invalid, so declare a new array, and increment its index % separately. x_nz(nz_array_index) = x(j); nz_array_index= nz_array_index+1; end end function edges = find_edges (x) j = 1; for i = 1:(length (x) - 1) if x(i) ~= x(i+1) edges (j) = i; j = j+1; end end