Average Nearest Neighbor (Spatial Statistics)

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

Learn more about how Average Nearest Neighbor Distance works


Average Nearest Neighbor illustration

Usage tips


AverageNearestNeighbor_stats (Input_Feature_Class, Distance_Method, Display_Output_Graphically, Area)
Parameter Explanation Datatype
Input Feature Class (Required)

The feature class, typically a point feature class, for which the average nearest neighbor distance will be calculated.

Feature Layer
Distance Method (Required)

Specifies how distances are calculated from each feature to its nearest neighboring feature.

  • 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) difference between the X and the Y coordinates.

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.

Area (Optional)

A numeric value representing the study area size. The default value is the area of the minimum enclosing rectangle that would encompass all features (or all selected features). Units should match those for the Output Coordinate System.

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"

    # 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]
    print "The p-value of the nearest neighbor index is: " + nn_values[2]

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

See Also

  • Multi-Distance Spatial Cluster Analysis (Ripley's k-function) (Spatial Statistics)
  • Calculate Areas (Spatial Statistics)
  • Spatial Autocorrelation (Morans I) (Spatial Statistics)
  • Modeling spatial relationships
  • What is a Z score What is a p-value