## 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

## Usage

GWR constructs a separate equation for every feature in the dataset incorporating the dependent and explanatory variables of features falling within the bandwidth of each target feature. The shape and extent of the bandwidth is dependent on user input for the Kernel type, Bandwidth method, Distance, and Number of neighbors parameters with one restriction: when the number of neighboring features would exceed 1000, only the closest 1000 are incorporated into each local equation.

GWR should be applied to datasets with several hundred features for best results. It is not an appropriate method for small datasets. The tool does not work with multipoint data.

- The GWR tool also produces an Output feature class and a table with the tool execution summary report diagnostic values. The name of this table is automatically generated using the output feature class name with _supp suffix. The Output feature class is automatically added to the table of contents with a hot/cold rendering scheme applied to model residuals. A full explanation of each output is provided in Interpreting GWR results.
The _supp file is always created in the same location as the Output feature class unless the output feature class is created inside a Feature Dataset. When the output feature class is inside a feature dataset, the _supp table is created in the geodatabase containing the feature dataset.

Using projected data is always recommended; it is especially important whenever distance is a component of the analysis, as it is for GWR when you select Fixed for Kernel type. It is strongly recommended that your data is projected using a Projected Coordinate System (rather than a Geographic Coordinate System).

Some of the computations done by the GWR tool take advantage of multiple CPUs in order to increase performance and will automatically use up to eight threads/CPUs for processing.

You should always begin regression analysis with Ordinary Least Squares (OLS) regression. First find a properly specified OLS model, then use the same explanatory variables to run GWR (excluding any "dummy" explanatory variables representing different spatial regimes).

Dependent and Explanatory variables should be numeric fields containing a variety of values. Linear regression methods, like GWR, are not appropriate for predicting binary outcomes (e.g., all of the values for the dependent variable are either 1 or 0).

In global regression models, such as Ordinary Least Squares Regression (OLS), results are unreliable when two or more variables exhibit multicollinearity (when two or more variables are redundant or together tell the same "story"). GWR builds a local regression equation for each feature in the dataset. When the values for a particular explanatory variable cluster spatially, you will very likely have problems with local multicollinearity. The condition number field (COND) in the output feature class indicates when results are unstable due to local multicollinearity. As a rule of thumb, do not trust results for features with a condition number larger than 30, equal to Null or, for shapefiles, equal to -1.7976931348623158e+308.

Caution should be used when including nominal or categorical data in a GWR model. Where categories cluster spatially, there is strong risk of encountering local multicollinearity issues. The condition number included in the GWR output indicates when local collinearity is a problem (a condition number less than zero, greater than 30, or set to Null). Results in the presence of local multicollinearity are unstable.

Do not use "dummy" explanatory variables to represent different spatial regimes in a GWR model (e.g., census tracts outside the urban core are assigned a value of 1, while all others are assigned a value of 0). Because GWR allows explanatory variable coefficients to vary, these spatial regime explanatory variables are unnecessary, and if included, will create problems with local multicollinearity.

To better understand regional variation among the coefficients of your explanatory variables, examine the optional raster coefficient surfaces created by GWR. These raster surfaces are created in the Coefficient raster workspace, if you specify one. For polygon data, you can use graduated color or cold-to-hot rendering on each coefficient field in the Output feature class to examine changes across your study area.

You may use GWR for prediction by supplying a Predictions locations feature class (often this feature class is the same as the Input feature class), the Prediction explanatory variables, and an Output prediction feature class. There must be a one to one correspondence between the fields used to calibrate the regression model (the values entered for the Explanatory variables field) and the fields used for prediction (the values entered for the Prediction explanatory variables field). The order of these variables must be the same. Suppose, for example, you are modeling traffic accidents as a function of speed limits, road conditions, number of lanes, and number of cars. You can predict the impact that changing speed limits or improving roads might have on traffic accidents by creating a new variables with the amended speed limits and road conditions. The existing variables would be used to calibrate the regression model and would be used for the Explanatory variables parameter. The amended variables would be used for predictions and would be entered as your Prediction explanatory variables.

If a Prediction locations feature class is provided, but no Prediction explanatory variables are specified, the Output prediction feature class is created with computed coefficients for each location only (no predictions).

A regression model is misspecified if it is missing a key explanatory variable. Statistically significant spatial autocorrelation of the regression residuals and/or unexpected spatial variation among the coefficients of one or more explanatory variables suggests that your model is misspecified. You should make every effort (through OLS residual analysis and GWR coefficient variation analysis, for example) to discover what these key missing variables are so they may be included in the model.

Always question whether or not it makes sense for an explanatory variable to be nonstationary. For example, suppose you are modeling the density of a particular plant species as a function of several variables including ASPECT. If you find that the coefficient for the ASPECT variable changes across the study area, you are likely seeing evidence of a key missing explanatory variable (perhaps prevalence of competing vegetation, for example). You should make every effort to include all key explanatory variables in your regression model.

When the result of a computation is infinity or undefined, the result for nonshapefiles will be Null; for shapefiles the result will be -DBL_MAX = -1.7976931348623158e+308.

When you select either AICc (corrected Akaike Information Criterion) or CV (Cross Validation) for the Bandwidth Method parameter, GWR will find the optimal distance (for a fixed kernel) or optimal number of neighbors (for an adaptive kernel). Problems with local multicollinearity, however, will prevent both the AICc and CV bandwidth methods from resolving an optimal distance/number of neighbors. If you get an error indicating

**severe model design**problems, try specifying a particular distance or neighbor count, then examining the condition numbers in the output feature class to see which features are associated with local collinearity problems**Severe model design**errors, or errors indicating local equations do not include enough neighbors, often indicate a problem with global or local multicollinearity. To determine where the problem is, run your model using OLS and examine the VIF value for each explanatory variable. If some of the VIF values are large (above 7.5, for example), global multicollinearity is preventing GWR from solving. More likely, however, local multicollinearity is the problem. Try creating a thematic map for each explanatory variable. If the map reveals spatial clustering of identical values, consider removing those variables from the model or combining those variables with other explanatory variables in order to increase value variation. If, for example, you are modeling home values and have variables for both bedrooms and bathrooms, you may want to combine these to increase value variation, or to represent them as bathroom/bedroom square footage. Avoid using spatial regime dummy variables, spatially clustering categorical/nominal variables, or variables with very few possible values when constructing GWR models.GWR is a linear model subject to the same requirements as OLS. Review the How Regression Models Go Bad section in the Regression Analysis Basics document as a check that your GWR model is properly specified.

## 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 | Data 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. - 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 | Specifies how the extent of the kernel should be determined. When AICc or CV are selected, the tool will find the optimal distance or number of neighbors for you. Typically you will select either AICc or CV when you aren't sure what to use for the Distance or Number of neighbors parameter. Once the tool determines the optimal distance or number of neighbors, however, you would use the BANDWIDTH_PARAMETER option. - AICc —The extent of the kernel is determined using the Akaike Information Criterion (AICc).
- CV —The extent of the kernel is determined using Cross Validation.
- BANDWIDTH_PARAMETER —The extent of the kernel is determined by a fixed distance or a fixed number of neighbors. You must specify a value for either the Distance or Number of Neighbors parameters.
| String |

distance (Optional) | The distance whenever the kernel_type is FIXED and bandwidth_method is BANDWIDTH_PARAMETER. | Double |

number_of_neighbors (Optional) | The exact number of neighbors to include in the local bandwidth of the Gaussian kernel when kernel_type is ADAPTIVE and the bandwidth_method is BANDWIDTH_PARAMETER. | Long |

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 than 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. | Folder |

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 geoprocessing 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 correspondence) 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 property to overwrite existing outputs
arcpy.env.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

## Licensing information

- ArcGIS Desktop Basic: Requires Spatial Analyst or Geostatistical Analyst
- ArcGIS Desktop Standard: Requires Spatial Analyst or Geostatistical Analyst
- ArcGIS Desktop Advanced: Yes