Exercise 7 Spatial Statistics GISC 6382 Briggs UTD 4/17/07 Doing Spatial Statistics Spatial statistics are not available in one standardized package. You have to make use of a combination of resources which might include: Using the Spatial Statistics toolset in ArcGIS 9 These have been developed using ArcScripts or Modelbuilder Adding ArcScripts and other custom programmed modules developed by others to ArcGIS (this was all that was available prior to ArcGIS 9) Writing additional spatial statistics capabilities using the greatly enhanced scripting and modeling capabilities of ArcGIS 9 Using the CrimeStat package for point pattern analysis (free) http://www.icpsr.umich.edu/NACJD/crimestat.html Using the Geoda (Geographic data analysis) package developed by Luc Anselin at the Center for Spatially Integrated Social Science for polygon and point data (free) http://www.csiss.org/ Using the Spatial Statistics module in the statistical package S-Plus (expensive) Using the package R, an open source version of S-Plus (free but more difficult to use) Using other statistical packages such as SAS, STATA and SPSS (expensive and lack good support for spatial statistics) Using Spatial Statistics (and other) tools in ArcGIS 9 1. If not already done, copy the folder P:\data\p6382\exercisedata\spatstat to c:\usr\ini 2. Open a new map document and add the Columbus.shp, COL_pnt.shp, and COL.bnd files. (Columbus, Ohio census tracts, centroids of tracts, and outer boundary) 3. To Obtain Centroids for Polygons Go to ArcToolbox/Data Management/Features/Feature to Point Input Features: Columbus.shp Output Feature Class: col_pnt2 Result should be identical to col_pnt 4. To Obtain the Mean Center for a set of points (which can be polygon centroids) Go to ArcToolbox/Spatial Statistics/Measuring Geographic Distributions/Mean Center Input Features: col_pnt2 Output Feature Class: col_MC Note the warning about lat/long! Many of the Spatial Statistics tools measure Euclidean distance and assume that data is in an appropriate projection for this! To Obtain the Mean Center for a set of points in State Plane Open a second, ArcMap and add the file geocode_tel_soft_State_plane.shp (high tech firms in DFW—in state plane coordinate system) (if desired, also add dalarearoad from P:\...coverages for orientation) Go to ArcToolbox/Spatial Statistics/Measuring Geographic Distributions/Mean Center Input Features: geocode_tel_soft_State_plane.shp Output Feature Class: tel_centroid 5. To Obtain the Standard Deviation Ellipse for a set of points Go to ArcToolbox/Spatial Statistics/Measuring Geographic Distributions/Directional Distribution Input Features: geocode_tel_soft_State_plane.shp Output Feature Class: tel_sde 1 Circle Size: 2 Standard Deviations Case Field: Industry Note: If a case field is specified, separate standard distances are calculated for each group of observations with the same value on the case field To see results, make polygon shading hollow. 6. To Calculate Moran’s I Return to the Columbus data Go to ArcToolbox/Spatial Statistics/Analyzing Patterns/Spatial Autocorrelation Input Features: Columbus.shp Input Field: Crime Output Feature Class: Col_I_crime Check Display Output Graphically Conceptualization of Spatial Relationships: Inverse distance Distance method: Euclidean Click OK. Results are displayed in graphics box. Moran’s I = 0.17 (which seems low) but is statistically significant—pattern is clustered since index is above 0. Click Close on the graphic box and the tool dialog will finish. Using CrimeStat package (note: this is just one example. CrimeStat does far more.) 7. CrimeStat was specifically designed for analysis of crime data, but it can be used for any point data. It will only analyze point data.Go to Start/Programs/CrimeStat to open software Note: this is a standalone package, not part of ArcGIS (It’s in the ArcGIS start folder for convenience only) 8. Add data: click the DataSetUp tab. Click Select Files button, specify Type as .shp and load geocode_tel_soft_State_plane.shp (Note: can only load point files. If you have a polygon file, obtain centroids using ArcToolbox/Data Management/Features/Feature to Point) 9. “Describe” data: In the Column column, specify For X: specify X For Y: specify Y (be careful here. CrimeStat extracts X and Y coordinates from the shape file. If your attributes table also contains X/Y variables, you will find X and Y listed twice. The first ones are from the shape file. You normally want these.) For Intensity: if doing Spatial Autocorrelation, must specify variable here otherwise leave blank ( Leave blank in this case.) For Weights: for analyses other than spatial autocorrletion, specify a weight variable here, but only if you want to do a weighted analysis ( Leave blank in this case.) (normally, do not specify both a weights variable and an intensity variable) Type of Coordinate System: Projected Data units: feet 10. Obtain Desired Statistic: Click Spatial Description tab Place check in box(s) for desired stats--Standard Deviation Ellipse Click Save Results to button and specify shapefile called DFWfirms Click Compute button: results are displayed on screen Click Print button if you want to print them (DON’T) 11. Display and compare results in ArcMap Open the map document saved in #5 above (spatstat.mxd) Add the DFWfirms shape file: elipse displays 2 Add the geocode_tel_soft_State_plane.shp Use Standard Deviation Ellipse tool to calculate standard deviation elipse Be sure to specify 2 standard deviations Results should be the same as with CrimeStat Using GeoDA 12. GeoDA is a package for exploratory analysis of geographic data. It replaces two earlier products: SpaceStat and DynaESDA It is designed primarily to analyze polygon data. In particular, it calculates and maps Local Indices of Spatial Association (LISA— specifically local Moran’s I). Again its standalone and free. Consequently, you don’t need ArcGIS to use it. If you don’t have ArcGIS but want to do some basic data analysis, its very useful. Think of it as a free, mini-version of ArcGIS. 13. For copies of the software, documentation and sample data sets go to: P:\Arcscripts\geoda Geoda_quickstart is a 25 page quick start guide to using geoda (read this first) Geoda_spauto a quick guide to spatial autocorreletion measures (read next) Geoda93_manual is a 125 page manual which fully documents the software Geoda 95i_updates is a 64 page manual which covers bug fixes and enhancements in the latest release 14. Starting GeoDa --Start GeoDa: Start/Programs/GeoDA --Go to File/Open Project to input a file (e.g. Columbus.shp) (Note: when specifying a file name, always use browse button—don’t type name.) Specify key field which identifies polygons—must be integer (e.g. POLYID) (Don’t confuse this with the variable being analyzed e.g. crime) --Go to Edit/Select variable (optional) In left box, select the variable to analyze (e.g CRIME) Place check in the box “Set the variables as default” (Note: This selects a variable as the default for analysis. It is optional since you can usually select the variable of interest later, when you choose a particular type of analysis, but it’s convenient not to have to keep selecting the variable. Come back here if you want to change the default.) 15. GeoDa Interface There are six separate menus with icons (v.0.95i). Above they are shown “undocked”, but the drop down menus on the Main toolbar are easier to understand and use. The most important Main menus items are: Edit—allows you to make copies of maps to compare with later analyses Tools—this has a powerful capability for creating weights matrices Space—this has the options for calculating various spatial statistics Maps—useful for creating standard and special types of choropleth maps 3 --especially box and percentile maps which highlight the extreme values Explore—creates various non-spatial graphs of data Regress—simple regression Options—allows options to be changed for the currently active window. Also go here to test statistical significance via simulation A major strength of GeoDA is its ability to link and brush data in all open widows. You can click, drag a box (then hold CTRL), draw a circle, etc around observations in one plot (e.g. a scatter diagram) and those same observations are highlighted in other window (e.g. choropleth map). 16. GeoDA Example: Box and Percentage Maps—looking at pattern of crime In spatial analysis, we are often interested in the “outliers” e.g. where there is a lot of crime, or where there is very little crime. Go to Maps, and create each of the following: Map/Quantiles with 4 categories: Places data into four categories, each with 25% of the observations—a quartile map OK, but not especially illuminating Use Edit/Duplicate Map to create new map, and retain a copy of this map. Map/Box with “hinge” = 1.5: Similar to quartile map, but adds “extreme” categories for data with values which are 1.5 (or 3) times the interquartile range (difference between 25% and 75% percentiles) Extremes here are based on the data value itself. Appears much better--highlights the clustering of the high and low values. However, it’s the different coloring that helps here for this particular data --in this case, no observations have these extreme values! --note the frequency counts in the legend to confirm this Use Edit/ Duplicate Map to create new map, and retain a copy of this map. Map/Percentile Uses percentiles in tails of distribution to highlight extremes: top & bottom 1% & 10%. Extremes here are merely the tails of the distribution. Observations will always be present in these categories but they are not necessarily “extreme” values, as in the case of the Box map. 17. geoDA Example: Linking and Brushing Best for comparing two variables, although what follows can be done with just one. Close all from # 20 windows except Box map for crime Create Box Plot for home values (which we will compare with crime) Go to Edit/Select variable and select variable HOVAL Go to Explore and select Box plot --go to Options and select Hinge 1.5 Select Window/Tile vertical The Box plot is interpreted as follows: --all observations are positioned based on their value on HOVAL --the colored center section shows the 25-75% percentile --the red line is the median --the T line in the upper part shows the location of upper “hinge” (value which is 1.5 times the interquartile range) --the lower is at the bottom of the box in this case 4 --sometimes both Ts are at the top & bottom of box (as in crime data), so no observations are beyond the hinge --sometimes no Ts show at all—if they are within the interquartile range Linking: click an observation (or drag a box) in one window it’s highlighted in other Brushing: hold CTRL and drag a small box in the map; it flashes, then drag it over the map and corresponding observations in the Box Plot are highlighted. --you can also do the reverse (create box in Box Plot, and observe map) --note how high home values always have low crime but middle values are mixed, some with low crime others with high crime --you can do the same with a Scatter Diagram --if you set Options/Exclude Selected, the regression line is recalculated to exclude the selected observations in the box. 18. GeoDA Example: Calculating Moran’s I and Anselin’s LISA (Local Moran’s I) Create Weights Matrix: Go to Tools>weights>create Input file: Columbus Output weights file: colpolywt ID Variable for weights file: PolyID Use Rook Contiguity with Contiguity order of 1 (Note: you can also create Distance-based weights-- very powerful routine.) Check Weights Matrix: Go to Tools>Weights>Properties Make sure there are no polygons with zero neighbors (legend key is on left side) Click on bar in histogram—observations in map will be highlighted Calculate Moran: Go to Space>Univariate Moran Variable: Crime (for file Columbus.shp) Click OK (If a default variable to analyze has already have been set, this option will not show. See above. Use Edit/Select Variable to change this.) Weights: colpolwt Click OK A scatterplot opens with W_Crime on vertical (Y) axis and Crime on X axis This shows correlation between crime and lagged crime (W_crime) W_crime is, in essence, the average of crimes for all neighbors. The slope of this line equals Moran’s I Check Statistical Significance via Simulation: Go to Options>Randomization Select 499 permutations Moran’s I of .5237 has less than .002 probability of occurring by chance Highly statistically significant Calculate LISA: Go to Space>Univariate LISA Variable: Crime (for file Columbus.shp) Click OK (If a default variable to analyze has already have been set, this option will not show. See above. Use Edit/Select Variable to change this.) Weights: colpolwt Click OK Place check in top three boxes (we already have Moran plot), and click OK Four windows are now open Examining results Close original Columbus window Go to Window>Tile Vertical Drag left side of map windows to display legends One map shows type of Spatial Autocorrelation (High/High etc) Other shows significance levels 5 Dynamic linking is in effect: click on an observation (or drag a box) in one window and same observations are highlighted in others. Using ArcScript Tools in ArcGIS 8 to do Spatial Statistics 19. ArcGIS 8 does not have tools for doing Spatial Statitics. In Exercise 6 Customization, especially #11-14 on Adding Toolbars and Scripts, we added tools to ArcGIS for doing spatial statistics. The spatstat.mxd map document you created should contain these tools. The file sstools.mxd in the spatstat folder contains these same tools, plus some others, although all may not work! 20. Copy the folder P:\data\p6382\exercisedata\spatstat to c:\usr\ini, 21. Open your map document spatstat.mxd or sstools.mxd in the spatstat folder 22. Add the Columbus.shp, COL_pnt.shp, and COL.bnd files. (Columbus, Ohio census tracts, centroids of tracts, and outer boundary) 23. Test the Polygon to Centroid tool on COLUMBUS.shp file (polygons) --should reproduce COL_pnt.shp file 24. Test the Standard Distance tool on COL_pnt.shp (points) (or use the centroids you created) Calculate Mean Center or Standard Deviation ellipse 25. Test the Rookcase Tool (calculates Moran’s I, Geary’s C, etc) 26. Use COLUMBUS.shp file (polygon) CRIME variable Lag distance of 1 27. Click Compute button Obtaining Consistent Results The same statistic can be calculated by several of these different pieces of software. However, you may not always get the same results! Differences result from: --using polygons or their centroids --different formulations for weights matrix (read documentation) --different ways of measuring distance (especially if data is lat/long—try to use State Plane) --parameters/options selected (e.g. is standard ellipse based on 1 or 2 standard deviations) Adding These Tools to Computers Off-campus All of the scripts used here (plus others), along with GeoDA and CrimeStat are on P:\Arcscripts. You can copy this folder and load onto any computer off-campus. You may need Power User or administrator privileges. Documentation in this folder together with custom.doc explains how. Lab/Exercise (1) The file geocode_tel_soft.shp contains point data on telecomm and software companies in the D/FW area for the period 1985 to 2002. The variable Enter gives the year the company started (or 1985 if the company was in existence at the start of the study) and Exit gives the year the company closed (or 2002 if still existed at study end). Use Centrographic Statistics tools (mean center and standard deviation ellipse) and nearest neighbor to explore spatial patterns and differences (if any) in these data e.g. Telecom versus software Companies in existence in 1985 versus those in existence in 2002 6