


PURPOSE: calculate local Moran's I for a local grid using a weight matrix.
-------------------------------------------------------------------
USAGE: m = localmoran_orig(raster, W, s);
where: [raster] is the grid to analyse
[W] is the normalized weight matrix of same size as [raster]
[s] is an optional flag to use zscores of input values for
calculation. Set to 'true' if zscores of local grid should be
calculated. Leave blank if not desired or input values are already
standardized.
-------------------------------------------------------------------------
OUTPUTS:
[m] local Moran's I
-------------------------------------------------------------------
Version: Original version true to Jo Woods code for edge effects, see
code line 63.
Based on code from Jo Woods dissertation
http://www.soi.city.ac.uk/~jwo/phd/04param.php
NOTES: Weight matrix needs to be 'moving window' style, not contiguity
matrix: Moran's I is calculated and weighted for neighbours to center cell.
Matrix needs to be normalized (weights sum to 1) and center cell weight
will be set to 0 if not already.
Use euklid_W() or euklid_invW() to construct weight matrices with
euklidean distances.
See Anselin (1995, 'LISA.', Geogr. Analysis 27(2),p.93f) for details on standardized variables in
calculation of local Moran's I.
Felix Hebeler, Geography Dept., University Zurich, March 2006.

0001 function m = localmoran_orig(raster, W); 0002 0003 % PURPOSE: calculate local Moran's I for a local grid using a weight matrix. 0004 % ------------------------------------------------------------------- 0005 % USAGE: m = localmoran_orig(raster, W, s); 0006 % where: [raster] is the grid to analyse 0007 % [W] is the normalized weight matrix of same size as [raster] 0008 % [s] is an optional flag to use zscores of input values for 0009 % calculation. Set to 'true' if zscores of local grid should be 0010 % calculated. Leave blank if not desired or input values are already 0011 % standardized. 0012 % ------------------------------------------------------------------------- 0013 % OUTPUTS: 0014 % [m] local Moran's I 0015 % ------------------------------------------------------------------- 0016 % Version: Original version true to Jo Woods code for edge effects, see 0017 % code line 63. 0018 % Based on code from Jo Woods dissertation 0019 % http://www.soi.city.ac.uk/~jwo/phd/04param.php 0020 % 0021 % NOTES: Weight matrix needs to be 'moving window' style, not contiguity 0022 % matrix: Moran's I is calculated and weighted for neighbours to center cell. 0023 % Matrix needs to be normalized (weights sum to 1) and center cell weight 0024 % will be set to 0 if not already. 0025 % Use euklid_W() or euklid_invW() to construct weight matrices with 0026 % euklidean distances. 0027 % 0028 % See Anselin (1995, 'LISA.', Geogr. Analysis 27(2),p.93f) for details on standardized variables in 0029 % calculation of local Moran's I. 0030 % 0031 % Felix Hebeler, Geography Dept., University Zurich, March 2006. 0032 0033 0034 %initialise variables 0035 covar=0; 0036 0037 %if exist('W') 0038 %if (W==1) W=ones(size(raster,1),size(raster,2)); end 0039 %else W=ones(size(raster,1),size(raster,2));end 0040 0041 ncols= size(raster,2); 0042 nrows= size(raster,1); 0043 %n= ncols*nrows-1; %number of neighbours for center cell 0044 w=0; %-W(ceil(nrows/2),ceil(ncols/2)); % set counter to ignore center weight 0045 0046 % calculate mean for raster 0047 zbar = mean(nanmean(raster(:))); 0048 0049 zi = raster(ceil(nrows/2),ceil(ncols/2))*W(ceil(nrows/2),ceil(ncols/2)); % value at center of raster 0050 if (isnan(zi)) m=NaN; return; end; 0051 0052 vari = (zi - zbar) * (zi - zbar); %variance of center cell i 0053 var = mean(nanmean((raster-zbar)*(raster-zbar))); % mean variance over window 0054 0055 for row=1:1:nrows; 0056 for col=1:1:ncols; 0057 zj = raster(row,col); 0058 if (isnan(zj)) break; end; %don't include NaNs 0059 covar = covar + (W(row,col)*((zi - zbar) * (zj - zbar))); 0060 w = w+ W(row,col); 0061 end 0062 end 0063 covar = covar - (W(ceil(nrows/2),ceil(ncols/2))*vari); % subtract 'covar'=vari of center cell with itself from sum of covariances 0064 if (vari~=0.0) 0065 m = covar/(vari*w); 0066 else 0067 m = 1.0; 0068 end