普通最小二乘法 (OLS) (空间统计)

摘要

执行全局“普通最小二乘法 (OLS)”线性回归可生成预测,也可为一个因变量针对它与一组解释变量关系建模。

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.

了解有关“普通最小二乘法”回归工作原理的详细信息

插图

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

用法

语法

OrdinaryLeastSquares_stats (Input_Feature_Class, Unique_ID_Field, Output_Feature_Class, Dependent_Variable, Explanatory_Variables, {Coefficient_Output_Table}, {Diagnostic_Output_Table}, {Output_Report_File})
参数说明数据类型
Input_Feature_Class

包含用于分析的因变量和自变量的要素类。

Feature Layer
Unique_ID_Field

包含输入要素类中每个要素不同值的整型字段。

Field
Output_Feature_Class

接收因变量的估计数和残差的输出要素类。

Feature Class
Dependent_Variable

包含要尝试建模的值的数值字段。

Field
Explanatory_Variables
[Explanatory_Variables,...]

表示回归模型中解释变量的字段列表。

Field
Coefficient_Output_Table
(可选)

将接收各解释变量的模型系数、标准差和概率的可选表的完整路径名。

Table
Diagnostic_Output_Table
(可选)

将接收模型汇总诊断的可选表的完整路径名。

Table
Output_Report_File
(可选)

工具要创建的可选 PDF 文件的路径。此报表文件包括模型诊断、图表以及有助于您解释 OLS 结果的注释。

File

代码示例

OrdinaryLeastSquares 示例(Python 窗口)

以下 Python 窗口脚本演示了如何使用 OrdinaryLeastSquares 工具。

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 示例(独立 Python 脚本)

以下独立 Python 脚本演示了如何使用 OrdinaryLeastSquares 工具。

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

环境

相关主题


7/10/2012