Label | Explanation | Data Type |
Input Features
| The input features containing the field that will be spatially filtered. | Feature Layer |
Input Field
| The input field that will be spatially filtered. | Field |
Output Features
| The output features containing a field of the spatially filtered input field and fields of the spatial components used to filter it. | Feature Class |
Append All Fields From Input Features
(Optional) | Specifies whether all fields will be copied from the input features to the output feature class.
| Boolean |
Input Spatial Weights Matrix Files
(Optional) | A list of input SWM files (.swm) that will be used as candidates for the SWM that will be used to filter the spatial autocorrelation from the input field. The SWM that most effectively filters spatial autocorrelation will be used. If no files are provided, the tool will test 28 different neighborhoods. | File |
Output Spatial Weights Matrix File
(Optional) | The output SWM file (.swm) of the neighbors and weights selected by the tool. | File |
Unique ID Field (Optional) | The unique ID field of the output .swm file. The field must be an integer and must have a unique value for each input feature. | Field |
Compare Only Input Spatial Weight Matrices
(Optional) | Specifies whether only the .swm files provided in the Input Spatial Weights Matrix Files parameter will be tested or whether 28 additional neighborhoods will also be tested. The tool will use the SWM that creates spatial components that most accurately predict the values of the input fields. This parameter only applies if at least one input .swm file is provided.
| Boolean |
Summary
Creates a spatially filtered version of an input field. The filtered variable will have no statistically significant spatial clustering but will maintain the core statistical properties of the field. The spatially filtered version of the field can then be used in analytical workflows (such as correlation or regression analysis) that assume the values at each location are spatially independent (not spatially clustered).
The tool filters spatial autocorrelation by splitting the field in a nonspatial component (the filtered field) and a set of spatial components (called Moran eigenvectors). When the input field is a field of residuals or standardized residuals from a prediction or regression model, including the spatial components as explanatory variables in the model (in addition to the original explanatory variables) will reduce or eliminate spatial autocorrelation of the residual term, which is an assumption of various prediction models.
Illustration

Usage
The output feature class will contain a field of the spatially filtered input variable along with fields of the spatial components used to filter it. When run in an active map, the output feature layer will draw based on the spatially filtered input field.
The geoprocessing messages include the following tables that summarize the selection of spatial components used to spatially filter the input field:
- Neighborhood Search History—For each of the spatial weight matrices (SWMs) that were tested, details of the SWM (such as the number of neighbors and weighting scheme), the Moran's I p-value for the original input variable, the Moran's I value and p-value of the spatially filtered input variable, and the number of components that were required to remove the spatial autocorrelation are displayed. The SWM that was selected to filter the input field is indicated by bold text and an asterisk.
- Spatial Component Search History—For the selected SWM, the ID value of each component (for example, ID 4 means that it was the fourth spatial component), the Moran's I value of the component, and the Moran's I value and p-value of the spatially filtered input variable are displayed. The rows are in the order of the selected components, so the p-value will increase at each row until it exceeds 0.05 (not statistically significant).
To select the SWM that will be used to filter the spatial autocorrelation from the input field, the tool generates a list of candidate SWMs and tests which one most effectively removes autocorrelation. If no SWMs are provided in the Input Spatial Weights Matrix Files parameter, 28 SWMs will be created and included in the candidate list (see Understanding Moran eigenvectors for descriptions of each SWM). If any input SWMs are provided, you can use the Compare Only Input Spatial Weight Matrices parameter to specify whether the candidate list only includes the provided SWMs or includes the provided SWMs and the 28 SWMs created by the tool. For example, to use a single specified SWM, provide the SWM in the Input Spatial Weights Matrix Files parameter and leave the Compare Only Input Spatial Weight Matrices parameter checked.
The tool selects among the candidate SWMs using the following procedure:
- For each SWM, the input field is tested for statistically significant spatial autocorrelation using a permutation test of Moran's I. Any SWM that is not statistically significant is removed from the candidate list. If the spatial autocorrelation is not statistically significant (the p-value is greater than 0.05) for all SWMs, the tool will fail and the input field will not be spatially filtered. This indicates that the field is spatially uncorrelated and does not need to be filtered. The p-values of the tests are adjusted using a Šidák correction to account for the number of SWMs tested.
- For each remaining candidate SWM, spatial components are sequentially added and used as explanatory variables to predict the input field. For each new spatial component, the spatial autocorrelation of the residual term is tested for statistical significance, and each SWM stops adding components when the autocorrelation of the residuals are no longer statistically significant (the p-value is greater than 0.05). Each new component is selected based on the largest increase in the p-value of the autocorrelation of the residual term (indicating the lowest spatial autocorrelation).
- The SWM that required the fewest number of components to produce residuals that are not significantly autocorrelated is selected. If there are ties in the fewest number of components, the one with the largest p-value is selected.
- The selected components and residuals are returned as fields of the output feature class. The residuals are the spatially filtered version of the input field.
This procedure is called the MIR (Minimizing autocorrelation In the Residuals) selection method and is fully described in the following reference:
Griffith, Daniel A., and Pedro R. Peres-Neto. 2006. "Spatial modeling in ecology: the flexibility of eigenfunction spatial analyses." Ecology 87, no. 10: 2603-2613. https://doi.org/10.1890/0012-9658(2006)87[2603:SMIETF]2.0.CO;2.
Parameters
arcpy.stats.FilterSpatialAutocorrelationFromField(in_features, input_field, out_features, {append_all_fields}, {in_swm}, {out_swm}, {id_field}, {compare_only_inputs})
Name | Explanation | Data Type |
in_features | The input features containing the field that will be spatially filtered. | Feature Layer |
input_field | The input field that will be spatially filtered. | Field |
out_features | The output features containing a field of the spatially filtered input field and fields of the spatial components used to filter it. | Feature Class |
append_all_fields (Optional) | Specifies whether all fields will be copied from the input features to the output feature class.
| Boolean |
in_swm [in_swm,...] (Optional) | A list of input SWM files (.swm) that will be used as candidates for the SWM that will be used to filter the spatial autocorrelation from the input field. The SWM that most effectively filters spatial autocorrelation will be used. If no files are provided, the tool will test 28 different neighborhoods. | File |
out_swm (Optional) | The output SWM file (.swm) of the neighbors and weights selected by the tool. | File |
id_field (Optional) | The unique ID field of the output .swm file. The field must be an integer and must have a unique value for each input feature. | Field |
compare_only_inputs (Optional) | Specifies whether only the .swm files provided in the in_swm parameter will be tested or whether 28 additional neighborhoods will also be tested. The tool will use the SWM that creates spatial components that most accurately predict the values of the input fields. This parameter only applies if at least one input .swm file is provided.
| Boolean |
Code sample
The following Python window script demonstrates how to use the FilterSpatialAutocorrelationFromField function.
# Filter spatial autocorrelation from a field.
arcpy.env.workspace = r"c:\data\project_data.gdb"
arcpy.stats.FilterSpatialAutocorrelationFromField(
in_features="myFeatureClass",
input_field="myAnalysisField",
out_features=r"myOutputFeatureClass",
append_all_fields="ALL",
in_swm=None,
out_swm=None,
id_field=None
)
The following stand-alone script demonstrates how to use the FilterSpatialAutocorrelationFromField function.
# Run Generalized Linear Regression, then filter spatial autocorrelation from residuals.
import arcpy
# Set the current workspace
arcpy.env.workspace = r"c:\data\project_data.gdb"
# Run the regression tool.
arcpy.stats.GeneralizedLinearRegression(
in_features=r"myFeatureClass",
dependent_variable="myDependentField",
model_type="CONTINUOUS",
output_features=r"myOutputFeatureClass",
explanatory_variables="myExplanatoryField1;myExplanatoryField2",
distance_features=None,
prediction_locations=None,
explanatory_variables_to_match=None,
explanatory_distance_matching=None,
output_predicted_features=None,
output_trained_model=None
)
arcpy.stats.FilterSpatialAutocorrelationFromField(
in_features="myOutputFeatureClass",
input_field="RESIDUAL",
out_features=r"myFilteredOutputFeatureClass",
append_all_fields="ALL",
in_swm=None,
out_swm=None,
id_field=None
)
# Print the messages.
print(arcpy.GetMessages())
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes