普通最小二乘法 (OLS) (Spatial Statistics)

许可等级:BasicStandardAdvanced

摘要

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

可从结果 窗口获取此工具的结果(包括可选报表文件)。如果禁用了后台处理,结果也将被写入进度 对话框。

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

插图

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 示例 1(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")
OrdinaryLeastSquare 示例 2(独立 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()

环境

相关主题

许可信息

ArcGIS for Desktop Basic:是
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013