You are here:
Geoprocessing tool reference > Spatial Statistics toolbox > Analyzing Patterns toolset > Tools

# Average Nearest Neighbor (Spatial Statistics)

Release 9.2

Print all topics in : "Tools"

Calculates a nearest neighbor index based on the average distance from each feature to its nearest neighboring feature.

Illustration

Usage tips

• The nearest neighbor index is expressed as the ratio of the observed distance divided by the expected distance. The expected distance is the average distance between neighbors in a hypothetical random distribution. If the index is less than 1, the pattern exhibits clustering; if the index is greater than 1, the trend is toward dispersion or competition.

• The Z score value is a measure of statistical significance which tells us whether or not to reject the null hypothesis. In this case the null hypothsis states that the points are randomly distributed. In this tool, the Z Score is based on Randomization Null Hypothesis computation. For more information on Z Scores, see What is a Z Score?.

• If an area value is not specified, then the area of the minimum enclosing rectangle around the features is used. The nearest neighbor function is very sensitive to the area value (small changes in the area can result in considerable changes in the results).

• The units of the area parameter are the input feature class' coordinate system's units squared.

• Although this tool will work with polygon or line data, it is really only appropriate for event, incident, or other fixed-point feature data. For line and polygon features, feature centroids are used in the computations.

• When output is shown graphically, a separate graphics dialog box will be displayed. Therefore, the output should not be displayed graphically (set display_output_graphically to FALSE) in batch operations.

• When using the tool in scripting, use "false" for the Display Output Graphically parameter. If you do not select false, the popup graphic will appear and your script will not complete until you click"Close".

• The nearest neighbor index and associated Z score values are written to the command window and passed as derived output.

• Calculations are based on either Euclidean or Manhattan distance and require projected data to accurately measure distances.

• Current map layers may be used to define the input feature class. When using layers, only the currently selected features are used.

• The "Display Output Graphically" parameter will only work on the windows operating system. When set to true it will display the results of the tool graphically.

• The environment settings do not have an effect on this tool.

Command line syntax
An overview of the Command Line window
AverageNearestNeighbor_stats <Input_Feature_Class> <Euclidean Distance | Manhattan Distance> <Display_Output_Graphically> {Area}

 Parameter Explanation Data Type The point feature class for which the average nearest neighbor distance will be calculated. Feature Layer Specifies how distances are calculated in the nearest neighbor calculation. Euclidean (as the crow flies) — The straight-line distance between two points. Manhattan (city block) — The distance between two points measured along axes at right angles. Calculated by summing the (absolute) differences between point coordinates. String Specifies whether the tool will display the nearest neighbor index graphically. True — The output will be displayed graphically. False — The output will not be displayed graphically. Boolean {Area} The area of the nearest neighbor analysis. The default area value is the area of the minimum enclosing rectangle. The units of this parameter are the input feature class' coordinate system's units squared. Double
Data types for geoprocessing tool parameters

### Command line example

workspace e:\tongass\data
AverageNearestNeighbor harvested.shp 'Euclidean Distance' true #

Scripting syntax
About getting started with writing geoprocessing scripts
AverageNearestNeighbor_stats (Input_Feature_Class, Distance_Method, Display_Output_Graphically, Area)

 Parameter Explanation Data Type Input_Feature_Class (Required) The point feature class for which the average nearest neighbor distance will be calculated. Feature Layer Distance_Method (Required) Specifies how distances are calculated in the nearest neighbor calculation. Euclidean (as the crow flies) — The straight-line distance between two points. Manhattan (city block) — The distance between two points measured along axes at right angles. Calculated by summing the (absolute) differences between point coordinates. String Display_Output_Graphically (Required) Specifies whether the tool will display the nearest neighbor index graphically. True — The output will be displayed graphically. False — The output will not be displayed graphically. Boolean Area (Optional) The area of the nearest neighbor analysis. The default area value is the area of the minimum enclosing rectangle. The units of this parameter are the input feature class' coordinate system's units squared. Double

Data types for geoprocessing tool parameters

### Script example

# Analyze crime data to determine if spatial patterns are statistically significant

# Import system modules
import arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Local variables...
workspace = "C:/project93/data"
crime_data = "burglaries.shp"

try:
# Set the current workspace (to avoid having to specify the full path to the feature classes each time)
gp.workspace = workspace

# Obtain Nearest Neighbor Ratio and Z Score
# Process: Average Nearest Neighbor...
nn_output = gp.AverageNearestNeighbor_stats(crime_data, "Euclidean Distance", "false", "#")
nn_values = nn_output.split(";")
print "The nearest neighbor index is: " + nn_values[0]
print "The z score of the nearest neighbor index is: " + nn_values[1]

except:
# If an error occurred when running the tool, print out the error message.
print gp.GetMessages()

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.