Skip to content

Statistical Analysis ​

This section covers statistical functions for analyzing spatial patterns and distributions in geographic datasets. These functions help determine point clustering, calculate representative centers, and visualize distribution characteristics.

For geometric operations like buffers and intersections, see Geometric Operations. For clustering algorithms, see Clustering.

Overview ​

Turf.js provides several statistical analysis functions that examine the spatial characteristics of point datasets:

SVG
100%

Statistical Analysis Module Architecture

Center Calculations ​

The centerMedian() function calculates the geometric median - the point that minimizes the sum of distances to all other points in the dataset.

FunctionInputOutputPurpose
centerMedianFeatureCollection<any>Feature<Point>Finds point requiring least total travel

Center Median Implementation ​

SVG
100%

Center Median Algorithm Flow

The function uses the Weiszfeld algorithm to iteratively find the spatial median:

  • Extracts centroids from input features using @turf/centroid
  • Calculates distances using @turf/distance
  • Supports weighted calculations via feature properties
  • Iterates until tolerance threshold is met (default: 0.001)

Spatial Distribution Analysis ​

The nearestNeighborAnalysis() function determines whether points are clustered, dispersed, or randomly distributed by analyzing distances between nearest neighbors.

Function Interface ​

nearestNeighborAnalysis(
  dataset: FeatureCollection<any>,
  options?: {
    studyArea?: Feature<Polygon>;
    units?: Units & AreaUnits;
    properties?: GeoJsonProperties;
  }
): NearestNeighborStudyArea

Analysis Process ​

SVG
100%

Nearest Neighbor Analysis Process

The analysis follows these steps:

  1. Uses @turf/centroid to extract centroids from input features
  2. Finds nearest neighbors using @turf/nearest-point
  3. Calculates observed mean distance using @turf/distance
  4. Determines population density from study area using @turf/area
  5. Computes expected distance and z-score for statistical inference

Directional Distribution Analysis ​

The standardDeviationalEllipse() function creates an elliptical polygon showing the directional distribution of points, containing approximately one standard deviation (70%) of the dataset.

Function Signature and Dependencies ​

SVG
100%

Standard Deviational Ellipse Dependencies

Ellipse Properties ​

The returned ellipse contains statistical metadata in its properties:

  • meanCenterCoordinates: Centroid of the distribution
  • semiMajorAxis: Length of major axis (standard deviation)
  • semiMinorAxis: Length of minor axis (standard deviation)
  • angle: Rotation angle in degrees
  • numberOfFeatures: Count of input points
  • percentageWithinEllipse: Actual percentage contained

Implementation Flow ​

SVG
100%

Standard Deviational Ellipse Algorithm

Statistical Analysis Data Flow ​

The statistical analysis modules integrate with core Turf.js infrastructure and share common dependency patterns:

SVG
100%

Statistical Analysis Module Dependencies

All statistical analysis functions follow consistent patterns:

  • Accept FeatureCollection inputs via standardized interfaces
  • Use @turf/helpers for GeoJSON creation and unit conversions
  • Leverage @turf/meta for coordinate iteration and traversal
  • Return standardized GeoJSON outputs with statistical metadata
  • Support optional weighting via feature properties