Ordinary Least Squares (Spatial Statistics)

Performs global Ordinary Least Squares linear regression to generate predictions or to model a dependent variable in terms of its relationships to a set of explanatory variables. Requires an ArcInfo license or the Spatial Analyst extension.

Learn more about how Ordinary Least Squares regression works


Illustration

OLS Regression

Usage tips

Syntax

OrdinaryLeastSquares_stats (Input_Feature_Class, Unique_ID_Field, Output_Feature_Class, Dependent_Variable, Explanatory_Variables, Coefficient_Output_Table, Diagnostic_Output_Table)
Parameter Explanation Datatype
Input Feature Class (Required)

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

Feature Layer
Unique ID Field (Required)

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

Field
Output Feature Class (Required)

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

Resize the tool progress window during execution for optimal display of OLS results.

Feature Class
Dependent Variable (Required)

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

Field
Explanatory Variables (Required)

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.

Resize the tool progress window during execution for optimal display of OLS results.

Table
Diagnostic Output Table (Optional)

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

Resize the tool progress window during execution for optimal display of OLS results.

Table
Data types for geoprocessing tool parameters

Script Example

# Analyze the growth of regional per capita incomes in US
# Counties from 1969 -- 2002 using Ordinary Least Squares Regression
# Import system modules
import arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.OverwriteOutput = 1
# Local variables...
workspace = "C:\Data\USCounties\US"
try:

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

See Also

  • Regression analysis basics
  • Interpreting OLS results
  • Geographically Weighted Regression (Spatial Statistics)
  • Spatial Autocorrelation (Morans I) (Spatial Statistics)
  • Hot Spot Analysis (Getis-Ord Gi*) (Spatial Statistics)
  • What is a Z Score What is a p-value