% PURPOSE: An example of using arc_moranplot() 
%          with an ArcView shape file containing 
%          3,111 polygons for US counties
%---------------------------------------------------
% USAGE: arc_moranplotd2
%---------------------------------------------------

clear all;

filename = '..\shape_files\us_counties';

results = shape_read(filename);

% data information is:
% col 1 AREANAME  
% col 2 AREAKEY   
% col 3 LATITUDE  
% col 4 LONGITUDE 
% col 5 POP1990   
% col 6 S_SAMHSE  
% col 7 POP65PLUS 
% col 8 EMPLOYMENT
% col 9 HOUSEHLDS 
% col 10 MEDINCOME 
% col 11 PCINCOME  
% col 12 POVERTY   
% col 13 NOHOUSES  
% col 14 MEDRENT   
% col 15 WHITEPOP  
% col 16 BLACKPOP  
% col 17 NATIVPOP  

% convert to per capita variables
variable = matdiv(results.data(:,6:end),results.data(:,5)); 

        
vnames = strvcat('same house','pop65+','employment','households','medincome','pcincome', ...
'poverty','#houses','median rent','white pop','black pop','native pop');

latt = results.xc;
long = results.yc;

% make_nnw is a function from the econometric toolbox
% that constructs a spatial weight matrix based on the
% 5 nearest neighbors
W = make_nnw(latt,long,5); 

% clever way to produce a state index
fips = results.data(:,2);
states = round(fips/1000);

% we add the state index 
% and pass everything along to the mapping function
data = [states results.data];
% don't forget to modify the vnames to include our state variable
options.vnames = strvcat('states',vnames);


options.vnames = vnames;


arc_moranplot(variable,W,results,options);

