Geographically Weighted Regression (GWR) (Spatial Statistics)

Summary

Performs Geographically Weighted Regression (GWR), a local form of linear regression used to model spatially varying relationships.

Learn more about how Geographically Weighted Regression works

Illustration

Geographically Weighted Regression
GWR is a local regression model. Coefficients are allowed to vary.

Usage

Syntax

GeographicallyWeightedRegression_stats (in_features, dependent_field, explanatory_field, out_featureclass, kernel_type, Bandwidth_method, {Distance}, {number_of_neighbors}, {weight_field}, {Coefficient_raster_workspace}, {cell_size}, {in_prediction_locations}, {prediction_explanatory_field}, {Out_prediction_featureclass})
ParameterExplanationData Type
in_features

The feature class containing the dependent and independent variables.

Feature Layer
dependent_field

The numeric field containing values for what you are trying to model.

Field
explanatory_field
[explanatory_field,...]

A list of fields representing independent explanatory variables in your regression model.

Field
out_featureclass

The output feature class to receive dependent variable estimates and residuals.

Feature Class
kernel_type

Specifies if the kernel is constructed as a fixed distance, or if it is allowed to vary in extent as a function of feature density.

  • FIXEDThe spatial context (the Gaussian kernel) used to solve each local regression analysis is a fixed distance.
  • ADAPTIVEThe spatial context (the Gaussian kernel) is a function of a specified number of neighbors. Where feature distribution is dense, the spatial context is smaller; where feature distribution is sparse, the spatial context is larger.
String
Bandwidth_method

Specifies how the extent of the kernel should be determined. When AICc or CV are selected, the tool will find the optimal distance/neighbor parameter for you.

  • AICcThe extent of the kernel is determined using the Akaike Information Criterion (AICc).
  • CVThe extent of the kernel is determined using Cross Validation.
  • BANDWIDTH PARAMETERThe extent of the kernel is determined by a fixed distance or a fixed number of neighbors.
String
Distance
(Optional)

Specifies a fixed bandwidth extent or distance whenever the kernel type is FIXED and the bandwidth method is BANDWIDTH PARAMETER.

Double
number_of_neighbors
(Optional)

An integer reflecting the exact number of neighbors to include in the local bandwidth of the Gaussian kernel whenever the kernel type is ADAPTIVE and the bandwidth method is BANDWIDTH PARAMETER.

Integer
weight_field
(Optional)

The numeric field containing a spatial weighting for individual features. This weight field allows some features to be more important in the model calibration process than others. Primarily useful when the number of samples taken at different locations varies, values for the dependent and independent variables are averaged, and places with more samples are more reliable (should be weighted higher). If you have an average of 25 different samples for one location, but an average of only 2 samples for another location, you can use the number of samples as your weight field so that locations with more samples have a larger influence on model calibration that locations with few samples.

Field
Coefficient_raster_workspace
(Optional)

A full pathname to the workspace where all of the coefficient rasters will be created. When this workspace is provided, rasters are created for the intercept and every explanatory variable.

Workspace
cell_size
(Optional)

The cell size (a number) or reference to the cell size (a pathname to a raster dataset) to use when creating the coefficient rasters.

The default cell size is the shortest of the width or height of the extent specified in the Environment output coordinate system, divided by 250.

Analysis Cell Size
in_prediction_locations
(Optional)

A feature class containing features representing locations where estimates should be computed. Each feature in this dataset should contain values for all of the explanatory variables specified; the dependent variable for these features will be estimated using the model calibrated for the input feature class data.

Feature Layer
prediction_explanatory_field
[prediction_explanatory_field,...]
(Optional)

A list of fields representing explanatory variables in the Prediction Locations feature class. These field names should be provided in the same order (a one-to-one correspondance) as those listed for the input feature class Explanatory variables parameter. If no prediction explanatory variables are given, the output prediction feature class will only contain computed coefficient values for each prediction location.

Field
Out_prediction_featureclass
(Optional)

The output feature class to receive dependent variable estimates for each feature in the Prediction locations feature class.

Feature Class

Code Sample

GeographicallyWeightedRegression Example (Python Window)

The following Python Window script demonstrates how to use the GeographicallyWeightedRegression tool.

import arcpy
arcpy.env.workspace = "c:/data"
arcpy.GeographicallyWeightedRegression_stats("CallData.shp", "Calls","BUS_COUNT;RENTROCC00;NoHSDip","CallsGWR.shp", "ADAPTIVE", "BANDWIDTH PARAMETER","#", "25", "#","CoefRasters", "135", "PredictionPoints", "#", "GWRCallPredictions.shp")
GeographicallyWeightedRegression Example (stand-alone Python script)

The following stand-alone Python script demonstrates how to use the GeographicallyWeightedRegression tool.

# Model 911 emergency calls using GWR

# Import system modules
import arcpy

# Set the geoprocessor object property to overwrite existing outputs
arcpy.gp.overwriteOutput = True

# Local variables...
workspace = r"C:\Data"

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

    # 911 Calls as a function of {number of businesses, number of rental units,
    # number of adults who didn't finish high school}
    # Process: Geographically Weighted Regression... 
    gwr = arcpy.GeographicallyWeightedRegression_stats("CallData.shp", "Calls", 
                        "BUS_COUNT;RENTROCC00;NoHSDip",
                        "CallsGWR.shp", "ADAPTIVE", "BANDWIDTH PARAMETER","#", "25", "#",
                        "CoefRasters", "135", "PredictionPoints", "#", "GWRCallPredictions.shp")

    # Create Spatial Weights Matrix to use with Global Moran's I tool
    # Process: Generate Spatial Weights Matrix... 
    swm = arcpy.GenerateSpatialWeightsMatrix_stats("CallsGWR.shp", "UniqID",
                        "CallData25Neighs.swm",
                        "K_NEAREST_NEIGHBORS",
                        "#", "#", "#", 25) 
                        
    # Calculate Moran's Index of Spatial Autocorrelation for 
    # OLS Residuals using a SWM File.  
    # Process: Spatial Autocorrelation (Morans I)...      
    moransI = arcpy.SpatialAutocorrelation_stats("CallsGWR.shp", "StdResid",
                        "NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE", 
                        "EUCLIDEAN_DISTANCE", "NONE", "#", 
                        "CallData25Neighs.swm")

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

Environments

Output Coordinate System

Feature geometry is projected to the Output Coordinate System after analysis is complete. Consequently, the value entered for the Distance parameter should be specified in the same units as the Input feature class. Values entered for the Output cell size should be specified in the same units as the Output Coordinate System.

Related Topics

Licensing Information

ArcView: Requires Spatial Analyst or Geostatistical Analyst
ArcEditor: Requires Spatial Analyst or Geostatistical Analyst
ArcInfo: Yes

3/7/2012