查看原文
其他

Stata:全局VS局部空间自相关命令操作汇总

空间自相关

1、简介

空间自相关统计量是用于度量空间数据(spatial data)的一个基本性质:某位置上的数据与其他位置上的数据间的相互依赖程度。通常把这种依赖叫做空间依赖(spatial dependence)。

空间数据(spatial data)由于受空间相互作用和空间扩散的影响,彼此之间可能不再相互独立,而是相关的。

在统计上,通过相关分析(correlation analysis)可以检测两种现象(统计量)的变化是否存在相关性

如果这个分析统计量是不同观察对象的同一属性变量,就称之为「自相关」(autocorrelation)。因此,所谓的空间自相关(spatial autocorrelation)就是研究「空间中,某空间单元与其周围单元间,就某种特征值,透过统计方法,进行空间自相关性程度的计算,以分析这些空间单元在空间上分布现象的特性」。

一般来说,方法在功用上可大致分为两大类:一为全域型(Global Spatial Autocorrelation),另一则为区域型(Local Spatial Autocorrelation)两种。

全域型的功能在于描述某现象的整体分布状况,判断此现象在空间是否有聚集特性存在,但其并不能确切地指出聚集在哪些地区。且若将全域型不同的空间间隔(spatial lag)的空间自相关统计量依序排列,还可进一步作空间自相关系数图(spatial autocorrelation coefficient correlogram),分析该现象在空间上是否有阶层性分布。

而依据Anselin(1995)提出LISA(Local Indicators of Spatial Association)方法论说法,区域型之所以能够推算出聚集地(spatial hot spot)的范围,主要有两种:一是藉由统计显著性检定的方法,检定聚集空间单元相对於整体研究范围而言,其空间自相关是否够显著,若显著性大,即是该现象空间聚集的地区,如:Getis和Ord(1992)发展的Getis统计方法;另外,则是度量空间单元对整个研究范围空间自相关的影响程度,影响程度大的往往是区域内的「特例」(outliers),也就表示这些「特例」点往往是空间现象的聚集点,例如:Anselin’s Moran Scatterplot。

2、全局空间自相关spatgsa

2.1 语法格式:


spatgsa varlist , weights(matrix) [ moran geary go twotail ]



*-基本含义:
  *Spatgsa计算三个全局空间自相关统计量:对于varlist中的每个统计量和每个变量,
  *spatgsa计算并以表格形式显示统计量本身、
  *在全局空间独立性的零假设下统计量的期望值、
  *统计量的标准差、z值、以及相应的单尾或双尾p值。

2.2 选项含义

 *-语法格式为:
  *weights(matrix)总是必要的选项。
  *它指定用于计算请求的全局空间自相关统计信息的空间权重矩阵的名称。
  *这个矩阵一定是由spatwmat生成的。
  *moran要求计算并显示moran统计量
  *geary要求计算并显示Geary's c统计量。
  *go请求计算并显示Getis and Ord'
s Gt统计量。
  *该选项要求由选项weights(matrix) 指定的空间权重矩阵为非标准化对称二元权矩阵。

  *twotail 表示计算和显示双尾p值,而不是默认的单尾p值。
  *要运行spatgsa,必须至少指定以下选项之一:moran、geary和go。

2.3 案例应用

 spatgsa hoval income crime, weights(W) moran geary go

spatgsa hoval income crime, weights(W) moran geary twotail



结果为:

   spatgsa hoval income crime, weights(w) moran geary go


Measures of global spatial autocorrelation


Weights matrix
--------------------------------------------------------------
Name: w
Type: Imported (binary)
Row-standardized: No
--------------------------------------------------------------

Moran's I
--------------------------------------------------------------
          Variables |    I      E(I)   sd(I)     z    p-value*
--------------------+-----------------------------------------
              hoval |  0.220  -0.021   0.085   2.824   0.002
             income |  0.413  -0.021   0.086   5.067   0.000
              crime |  0.521  -0.021   0.087   6.212   0.000
--------------------------------------------------------------

Geary'
s c
--------------------------------------------------------------
          Variables |    c      E(c)   sd(c)     z    p-value*
--------------------+-----------------------------------------
              hoval |  0.805   1.000   0.138  -1.411   0.079
             income |  0.716   1.000   0.131  -2.165   0.015
              crime |  0.584   1.000   0.109  -3.835   0.000
--------------------------------------------------------------

Getis & Ord's G
--------------------------------------------------------------
          Variables |    G      E(G)   sd(G)     z    p-value*
--------------------+-----------------------------------------
              hoval |  0.098   0.099   0.006  -0.188   0.425
             income |  0.098   0.099   0.005  -0.057   0.477
              crime |  0.126   0.099   0.006   4.714   0.000
--------------------------------------------------------------
*1-tail test



.   spatgsa hoval income crime, weights(w) moran geary twotail


Measures of global spatial autocorrelation


Weights matrix
--------------------------------------------------------------
Name: w
Type: Imported (binary)
Row-standardized: No
--------------------------------------------------------------

Moran'
s I
--------------------------------------------------------------
          Variables |    I      E(I)   sd(I)     z    p-value*
--------------------+-----------------------------------------
              hoval |  0.220  -0.021   0.085   2.824   0.005
             income |  0.413  -0.021   0.086   5.067   0.000
              crime |  0.521  -0.021   0.087   6.212   0.000
--------------------------------------------------------------

Geary's c
--------------------------------------------------------------
          Variables |    c      E(c)   sd(c)     z    p-value*
--------------------+-----------------------------------------
              hoval |  0.805   1.000   0.138  -1.411   0.158
             income |  0.716   1.000   0.131  -2.165   0.030
              crime |  0.584   1.000   0.109  -3.835   0.000
--------------------------------------------------------------
*2-tail test




end of do-file




3、局部空间自相关spatlsa

spatlsa varname , weights(matrix) [ moran geary go1 go2 id(varname) twotail sort graph(moran|go1|go1) symbol(id|n) map(filename) xcoord(varname) ycoord(varname) savegraph(filename [, replace]) ]

weights(matrix)总是需要的。它指定用于计算所请求的局部空间自相关统计信息的空间权重矩阵的名称。这个矩阵一定是由spatwmat生成的。

3.1 选项含义


*moran要求计算并显示moran统计量

*geary要求计算并显示Geary's c统计量。

*go请求计算并显示Getis and Ord'
s Gt统计量。
*该选项要求由选项weights(matrix) 指定的空间权重矩阵为非标准化对称二元权矩阵。

id(varname) 指定包含分析的每个位置对象标识符的变量的名称。

*twotail 表示计算和显示双尾p值,而不是默认的单尾p值。
*要运行spatlsa,必须至少指定以下选项之一:moran、geary和go。

Graph (moran|go1|go1)请求显示结果的图形表示。可以请求四种图形:

symbol(id|n)请求在Moran散点图中,位置由标识符而不是默认图形符号表示。

symbol(id)请求位置由选项id(varname)指定的变量的值来标识。

symbol(n)要求位置由案例编号标识。

Map (filename)指定包含划分分析的地理区域对象的多边形坐标的文件。该选项要求同时指定xcoord(varname)和ycoord(varname)选项。

Xcoord (varname)指定包含分析的每个位置对象的x坐标的变量的名称。

Ycoord (varname)指定了包含分析的每个位置对象的y坐标的变量的名称。

Savegraph (filename [, replace])请求以filename格式保存图形。如果filename存在,除非同时指定replace,否则将出现错误。文件名必须有以下扩展名之一:ps, .eps, .prn, or .wmf.

3.2 案例应用

 . spatlsa crime, weights(W) moran go2

        . spatlsa crime, weights(WS) moran graph(moran) symbol(n)

        . spatlsa crime, w(W) go2 graph(go2) map(ColumbusBoundary.dta) x(x) y(y)




结果为:

. spatlsa crime, weights(w) moran go2



Measures of local spatial autocorrelation


Weights matrix
--------------------------------------------------------------
Name: w
Type: Imported (binary)
Row-standardized: No
--------------------------------------------------------------

Moran's Ii (Residential burglaries & vehicle thefts pe)
--------------------------------------------------------------
           Location |    Ii    E(Ii)  sd(Ii)     z    p-value*
--------------------+-----------------------------------------
                  1 |  1.586  -0.063   1.674   0.985   0.162
                  2 |  0.019  -0.083   1.912   0.054   0.479
                  3 |  0.460  -0.125   2.289   0.255   0.399
                  4 | -7.442  -0.083   1.912  -3.850   0.000
                  5 |  1.474  -0.042   1.381   1.097   0.136
                  6 |  0.375  -0.083   1.912   0.240   0.405
                  7 |  2.429  -0.167   2.581   1.006   0.157
                  8 | -0.363  -0.042   1.381  -0.233   0.408
                  9 |  4.409  -0.125   2.289   1.981   0.024
                 10 |  0.161  -0.083   1.912   0.128   0.449
                 11 | -0.324  -0.063   1.674  -0.156   0.438
                 12 |  2.703  -0.063   1.674   1.652   0.049
                 13 |  4.959  -0.083   1.912   2.638   0.004
                 14 |  2.495  -0.063   1.674   1.528   0.063
                 15 |  0.935  -0.042   1.381   0.707   0.240
                 16 |  4.846  -0.104   2.113   2.342   0.010
                 17 |  3.414  -0.208   2.815   1.287   0.099
                 18 |  0.195  -0.146   2.443   0.140   0.444
                 19 | -0.024  -0.125   2.289   0.044   0.482
                 20 |  1.180  -0.104   2.113   0.607   0.272
                 21 | -0.496  -0.083   1.912  -0.216   0.415
                 22 |  0.214  -0.083   1.912   0.156   0.438
                 23 | -0.210  -0.146   2.443  -0.026   0.490
                 24 |  3.465  -0.125   2.289   1.569   0.058
                 25 | -0.103  -0.104   2.113   0.000   0.500
                 26 |  1.090  -0.063   1.674   0.689   0.246
                 27 |  0.814  -0.083   1.912   0.470   0.319
                 28 |  0.272  -0.083   1.912   0.186   0.426
                 29 |  0.035  -0.125   2.289   0.070   0.472
                 30 |  2.539  -0.125   2.289   1.164   0.122
                 31 |  8.793  -0.188   2.704   3.321   0.000
                 32 | 11.771  -0.146   2.443   4.877   0.000
                 33 | 10.351  -0.125   2.289   4.577   0.000
                 34 |  8.276  -0.104   2.113   3.965   0.000
                 35 |  1.600  -0.146   2.443   0.714   0.238
                 36 |  9.910  -0.167   2.581   3.904   0.000
                 37 |  4.529  -0.146   2.443   1.913   0.028
                 38 |  7.290  -0.104   2.113   3.498   0.000
                 39 |  0.501  -0.083   1.912   0.306   0.380
                 40 |  3.692  -0.125   2.289   1.667   0.048
                 41 |  2.400  -0.063   1.674   1.471   0.071
                 42 |  2.763  -0.104   2.113   1.357   0.087
                 43 |  0.465  -0.063   1.674   0.315   0.376
                 44 |  2.114  -0.083   1.912   1.149   0.125
                 45 |  2.035  -0.042   1.381   1.503   0.066
                 46 |  6.216  -0.104   2.113   2.991   0.001
                 47 |  2.304  -0.042   1.381   1.698   0.045
                 48 |  2.499  -0.042   1.381   1.840   0.033
                 49 |  2.173  -0.042   1.381   1.604   0.054
--------------------------------------------------------------

Getis & Ord'
s G2i (Residential burglaries & vehicle thefts pe)
--------------------------------------------------------------
           Location |    G2i   E(G2i) sd(G2i)    z    p-value*
--------------------+-----------------------------------------
                  1 |  0.057   0.082   0.019  -1.340   0.090
                  2 |  0.099   0.102   0.021  -0.132   0.448
                  3 |  0.167   0.143   0.024   1.013   0.156
                  4 |  0.116   0.102   0.021   0.661   0.254
                  5 |  0.038   0.061   0.016  -1.433   0.076
                  6 |  0.086   0.102   0.021  -0.772   0.220
                  7 |  0.218   0.184   0.026   1.285   0.099
                  8 |  0.062   0.061   0.016   0.069   0.473
                  9 |  0.203   0.143   0.024   2.521   0.006
                 10 |  0.079   0.102   0.021  -1.138   0.128
                 11 |  0.053   0.082   0.019  -1.540   0.062
                 12 |  0.044   0.082   0.019  -2.003   0.023
                 13 |  0.043   0.102   0.021  -2.851   0.002
                 14 |  0.048   0.082   0.019  -1.821   0.034
                 15 |  0.037   0.061   0.016  -1.511   0.065
                 16 |  0.071   0.122   0.022  -2.325   0.010
                 17 |  0.189   0.224   0.028  -1.263   0.103
                 18 |  0.154   0.163   0.025  -0.375   0.354
                 19 |  0.145   0.143   0.024   0.079   0.469
                 20 |  0.158   0.122   0.022   1.595   0.055
                 21 |  0.108   0.102   0.021   0.281   0.389
                 22 |  0.111   0.102   0.021   0.435   0.332
                 23 |  0.157   0.163   0.025  -0.235   0.407
                 24 |  0.183   0.143   0.024   1.701   0.044
                 25 |  0.119   0.122   0.022  -0.158   0.437
                 26 |  0.061   0.082   0.019  -1.133   0.129
                 27 |  0.082   0.102   0.021  -0.982   0.163
                 28 |  0.091   0.102   0.021  -0.517   0.303
                 29 |  0.147   0.143   0.024   0.189   0.425
                 30 |  0.202   0.143   0.024   2.501   0.006
                 31 |  0.281   0.204   0.027   2.806   0.003
                 32 |  0.250   0.163   0.025   3.454   0.000
                 33 |  0.222   0.143   0.024   3.328   0.000
                 34 |  0.181   0.122   0.022   2.630   0.004
                 35 |  0.246   0.163   0.025   3.271   0.001
                 36 |  0.275   0.184   0.026   3.475   0.000
                 37 |  0.209   0.163   0.025   1.828   0.034
                 38 |  0.181   0.122   0.022   2.625   0.004
                 39 |  0.116   0.102   0.021   0.661   0.254
                 40 |  0.182   0.143   0.024   1.661   0.048
                 41 |  0.113   0.082   0.019   1.663   0.048
                 42 |  0.177   0.122   0.022   2.464   0.007
                 43 |  0.099   0.082   0.019   0.958   0.169
                 44 |  0.065   0.102   0.021  -1.780   0.038
                 45 |  0.033   0.061   0.016  -1.760   0.039
                 46 |  0.063   0.122   0.022  -2.675   0.004
                 47 |  0.029   0.061   0.016  -1.975   0.024
                 48 |  0.029   0.061   0.016  -1.975   0.024
                 49 |  0.032   0.061   0.016  -1.803   0.036
--------------------------------------------------------------
*1-tail test



4、空间相关性度量命令estat moran

案例应用为:



copy https://www.stata-press.com/data/r17/homicide1990.dta .
copy https://www.stata-press.com/data/r17/homicide1990_shp.dta .
 use homicide1990
spset

spmatrix create contiguity W

regress hrate
estat moran, errorlag(W)

---------------------------------------------------------------------
spmatrix create idistance M
estat moran, errorlag(W) errorlag(M)


结果为:

  use homicide1990
(S.Messner et al.(2000), U.S southern county homicide rates in 1990)


. spset

      Sp dataset: homicide1990.dta
Linked shapefile: homicide1990_shp.dta
            Data: Cross sectional
 Spatial-unit ID: _ID
     Coordinates: _CX, _CY (planar)




. spmatrix create contiguity W




. regress hrate

      Source |       SS           df       MS      Number of obs   =     1,412
-------------+----------------------------------   F(0, 1411)      =      0.00
       Model |           0         0           .   Prob > F        =         .
    Residual |    69908.59     1,411  49.5454217   R-squared       =    0.0000
-------------+----------------------------------   Adj R-squared   =    0.0000
       Total |    69908.59     1,411  49.5454217   Root MSE        =    7.0389

------------------------------------------------------------------------------
       hrate | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
       _cons |   9.549293   .1873201    50.98   0.000     9.181837    9.916749
------------------------------------------------------------------------------


. estat moran, errorlag(W)

Moran test for spatial dependence
         H0: Error terms are i.i.d.
         Errorlags:  W

         chi2(1)      =   265.84
         Prob > chi2  =   0.0000




 spmatrix create idistance M



. estat moran, errorlag(W) errorlag(M)

Moran test for spatial dependence
         H0: Error terms are i.i.d.
         Errorlags:  W M

         chi2(2)      =   898.62
         Prob > chi2  =   0.0000





您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存