Geographically Weighted Regression (Spatial Statistics)

Performs GWR, a local form of linear regression used to model spatially varying relationships. Requires an ArcInfo, Spatial Analyst, or Geostatistical Analyst License.

Learn more about how Geographically Weighted regression works


Illustration

Geographically Weighted Regression

Usage tips

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)
Parameter Explanation Datatype
Input feature class (Required)

The feature class containing the dependent and independent variables.

Feature Layer
Dependent variable (Required)

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

Field
Explanatory variable(s) (Required)

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

Field
Output feature class (Required)

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

Feature Class
Kernal type (Optional)

Specifies if the kernal is always fixed or if it is allowed to vary in extent as a function of feature density.

  • FIXED: the spatial context (the Gaussian kernel) used to solve each local regression analysis is a fixed distance
  • ADAPTIVE: the 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 (Optional)

Specifies how the extent of the kernel should be determined: using the Akaike Information Criterion (AICc), using Cross Validation (CV) or allowing the user to specify either a fixed distance or fixed number of neighbors as a bandwidth parameter.

String
Distance (Optional)

Specifies a fixed bandwidth extent whenever the user selects FIXED for kernel type and BANDWIDTH PARAMETER for the Bandwidth method. Enter this value using the units specified by the Environment output coordinate system.

Double
Number of neighbors (Optional)

An integer reflecting the exact number of neighbors to include in the local bandwidth of the Gaussian kernel in cases where the user selects ADAPTIVE for kernel type and BANDWIDTH PARAMETER for Bandwidth method.

Integer
Weights (Required)

The numeric field containing a spatial weighting for individual features. 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).

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
Output 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
Prediction locations (Required)

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 variable(s) (Required)

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
Output prediction feature class (Required)

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

Feature Class
Data types for geoprocessing tool parameters

Script Example

# Model 911 emergency calls using GWR
# Import system modules
import arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.OverwriteOutput = 1
# Local variables...
workspace = "C:\Data\CallAnalysis"
try:

# Set the current workspace (to avoid having to specify the full path to the feature classes each time)
    gp.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 = gp.GeographicallyWeightedRegression("CallData", "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 = gp.GenerateSpatialWeightsMatrix("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 = gp.SpatialAutocorrelation("CallsGWR.shp", "StdResid",
                        "false", "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 gp.GetMessages()

See Also

  • Ordinary Least Squares (Spatial Statistics)
  • Regression analysis basics
  • Interpreting GWR results