⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 find_nnd2.m

📁 计量工具箱
💻 M
字号:
% PURPOSE: An example of using find_nn()%          finds an index to the nearest neighbors %          demo for a large data set                   %---------------------------------------------------% USAGE: find_nnd2%---------------------------------------------------clear all;% A data set for 1980 Presidential election results covering 3,107 % US counties. From Pace, R. Kelley and Ronald Barry. 1997. ``Quick% Computation of Spatial Autoregressive Estimators'',% in  Geographical Analysis.% %  Variables are:%  columns 1-4 are census identifiers %  column 5  = lattitude%  column 6  = longitude%  column 7  = population casting votes%  column 8  = population over age 19 eligible to vote%  column 9  = population with college degrees%  column 10 = homeownership%  column 11 = incomeload elect.dat;                    % load data on voteslatt = elect(:,5);long = elect(:,6);y = elect(:,7);    % # of votersy = y./elect(:,8); % percentage of elgible voters votingm = 5;index = find_nn(latt,long,m);% pull out nearest neighbor values from yy1 = y(index(:,1),1); % pulls out nearest neighbor crime rates% plot crime rates in each neighborhood vs that in the nearest neighborplot(y,y1,'.g');xlabel('rate of voter participation');ylabel('nearest neighbor participation rates');fprintf(1,'in pause mode, hit any key to continue \n');pause;y2 = y(index(:,1),1)+y(index(:,2),1); % crime rates in nearest 2 neighborsy2 = y2/2; % an average of these% plot crime rates in each neighborhood vs the average in the nearest 2 neighborsplot(y,y2,'.r');xlabel('voter participation rates');ylabel('average of 2 nearest neighbor participation rates');fprintf(1,'in pause mode, hit any key to continue \n');pause;% crime rates in nearest 5 neighborsy5 = y(index(:,1),1)+y(index(:,2),1)+y(index(:,3),1)+y(index(:,4),1)+y(index(:,5),1);y5 = y5/5; % an average of these% plot crime rates in each neighborhood vs the average in the nearest 2 neighborsplot(y,y5,'.r');xlabel('voter participation rates');ylabel('average of 5 nearest neighbor participation rates');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -