Ordinary Least Squares (OLS) (Spatial Statistics)

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. Results are accessible from the Results window.

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})
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

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

Field
Coefficient_Output_Table
(Optional)

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

Table
Diagnostic_Output_Table
(Optional)

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

Table

Code Sample

OrdinaryLeastSquares Example (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 (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

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

3/7/2012