Ordinary Least Squares (OLS) (Spatial Statistics)

License Level:BasicStandardAdvanced

Summary

Performs global Ordinary Least Squares (OLS) linear regression to generate predictions or to model a dependent variable in terms of its relationships to a set of explanatory variables.

You can access the results of this tool (including the optional report file) from the Results window. If you disable background processing, results will also be written to the Progress dialog box.

Learn more about how Ordinary Least Squares regression works

Illustration

OLS Regression
Ordinary Least Squares Regression: predicted values in relation to observed values

Usage

Syntax

OrdinaryLeastSquares_stats (Input_Feature_Class, Unique_ID_Field, Output_Feature_Class, Dependent_Variable, Explanatory_Variables, {Coefficient_Output_Table}, {Diagnostic_Output_Table}, {Output_Report_File})
ParameterExplanationData Type
Input_Feature_Class

The feature class containing the dependent and independent variables for analysis.

Feature Layer
Unique_ID_Field

An integer field containing a different value for every feature in the Input Feature Class.

Field
Output_Feature_Class

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

Feature Class
Dependent_Variable

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

Field
Explanatory_Variables
[Explanatory_Variables,...]

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

Field
Coefficient_Output_Table
(Optional)

The full path to an optional table that will receive model coefficients, standardized coefficients, standard errors, and probabilities for each explanatory variable.

Table
Diagnostic_Output_Table
(Optional)

The full path to an optional table that will receive model summary diagnostics.

Table
Output_Report_File
(Optional)

The path to the optional PDF file you want the tool to create. This report file includes model diagnostics, graphs, and notes to help you interpret the OLS results.

File

Code Sample

OrdinaryLeastSquares example 1 (Python window)

The following Python window script demonstrates how to use the OrdinaryLeastSquares tool.

import arcpy
arcpy.env.workspace = r"c:\data"
arcpy.OrdinaryLeastSquares_stats("USCounties.shp", "MYID","olsResults.shp", 
                                 "GROWTH","LOGPCR69;SOUTH;LPCR_SOUTH;PopDen69",
                                 "olsCoefTab.dbf","olsDiagTab.dbf")
OrdinaryLeastSquares example 2 (stand-alone Python script)

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

# Analyze the growth of regional per capita incomes in US
# Counties from 1969 -- 2002 using Ordinary Least Squares Regression

# 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.workspace = workspace

    # Growth as a function of {log of starting income, dummy for South
    # counties, interaction term for South counties, population density}
    # Process: Ordinary Least Squares... 
    ols = arcpy.OrdinaryLeastSquares_stats("USCounties.shp", "MYID", 
                        "olsResults.shp", "GROWTH",
                        "LOGPCR69;SOUTH;LPCR_SOUTH;PopDen69",
                        "olsCoefTab.dbf",
                        "olsDiagTab.dbf")

    # Create Spatial Weights Matrix (Can be based off input or output FC)
    # Process: Generate Spatial Weights Matrix... 
    swm = arcpy.GenerateSpatialWeightsMatrix_stats("USCounties.shp", "MYID",
                        "euclidean6Neighs.swm",
                        "K_NEAREST_NEIGHBORS",
                        "#", "#", "#", 6) 
                        

    # Calculate Moran's Index of Spatial Autocorrelation for 
    # OLS Residuals using a SWM File.  
    # Process: Spatial Autocorrelation (Morans I)...      
    moransI = arcpy.SpatialAutocorrelation_stats("olsResults.shp", "Residual",
                        "NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE", 
                        "EUCLIDEAN_DISTANCE", "NONE", "#", 
                        "euclidean6Neighs.swm")

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

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
4/18/2013