Hands-on Exercise 5a: Global Measures of Spatial Autocorrelation

Published

August 15, 2024

Modified

August 16, 2024

1 Overview

Learning how to compute Global Measure of Spatial Autocorrelation (GLSA) by using spdep package, including:

  • import geospatial data using appropriate function(s) of sf package
  • import csv file using appropriate function of readr package
  • perform relational join using appropriate join function of dplyr package
  • compute Global Spatial Autocorrelation (GSA) statistics by using appropriate functions of spdep package
    • plot Moran scatterplot
    • compute and plot spatial correlogram using appropriate function of spdep package
  • compute Local Indicator of Spatial Association (LISA) statistics for detecting clusters and outliers by using appropriate functions spdep package
  • compute Getis-Ord’s Gi-statistics for detecting hot spot or/and cold spot area by using appropriate functions of spdep package
  • visualise the analysis output by using tmap package.

The Analytical Question

In spatial policy, one of the main development objective of the local government and planners is to ensure equal distribution of development in the province. Our task in this study, hence, is to apply appropriate spatial statistical methods to discover if development are even distributed geographically. If the answer is No, then, our next question will be “is there sign of spatial clustering?” And, if the answer for this question is Yes, then our next question will be “where are these clusters?”

In this case study, we are interested to examine the spatial pattern of a selected development indicator (i.e. GDP per capita) of Hunan Provice, People Republic of China.

2 The Packages

Package Description
spdep To compute spatial weights, Global and Local Spatial Autocorrelation statistics (eg plot Moran scatterplot, compute and plot correlogram)
sf For importing, managing, and processing geospatial data
tidyverse A collection of functions for performing data science task such as importing, tidying, wrangling data and visualising data.
tmap To prepare cartographic quality choropleth map
DTknitr and kableExtra For building tables
pacman::p_load(sf, spdep, 
               tmap, 
               tidyverse, 
               DT, knitr, kableExtra)

# -   Creates a package list containing the necessary R packages
# -   Checks if the R packages in the package list have been installed
# -   If not installed, will installed the missing packages & launch into R environment.

3 The Data

Two data sets will be used in this hands-on exercise, they are:

Type Name Details
Geospatial Hunan
  • County boundary layer

  • Format: SHP (ESRI Shapefile)

Aspatial Hunan_2012
  • Contains selected Hunan’s local development indicators in 2012

  • Format: CSV

3.1 Loading the Data

In this section, you will learn how to bring a geospatial data and its associated attribute table into R environment. The geospatial data is in ESRI shapefile format and the attribute table is in csv fomat.

The code chunk below uses st_read() of sf package to import Hunan shapefile into R.

#output: simple features object

hunan <- st_read(dsn = "data/geospatial", 
                 layer = "Hunan")
Reading layer `Hunan' from data source 
  `C:\kytjy\ISSS626-GAA\Hands-on_Ex\Hands-on_Ex05\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 88 features and 7 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 108.7831 ymin: 24.6342 xmax: 114.2544 ymax: 30.12812
Geodetic CRS:  WGS 84
NAME_2 ID_3 NAME_3 ENGTYPE_3 Shape_Leng Shape_Area County geometry
Changde 21098 Anxiang County 1.8690742 0.1005619 Anxiang POLYGON ((112.0625 29.75523...
Changde 21100 Hanshou County 2.3606914 0.1997875 Hanshou POLYGON ((112.2288 29.11684...
Changde 21101 Jinshi County City 1.4256199 0.0530241 Jinshi POLYGON ((111.8927 29.6013,...
Changde 21102 Li County 3.4743245 0.1890812 Li POLYGON ((111.3731 29.94649...
Changde 21103 Linli County 2.2895061 0.1145036 Linli POLYGON ((111.6324 29.76288...
Changde 21104 Shimen County 4.1719181 0.3719471 Shimen POLYGON ((110.8825 30.11675...
Changsha 21109 Liuyang County City 4.0605788 0.4601679 Liuyang POLYGON ((113.9905 28.5682,...
Changsha 21110 Ningxiang County 3.3237542 0.2661420 Ningxiang POLYGON ((112.7181 28.38299...
Changsha 21111 Wangcheng County 2.2920930 0.1304916 Wangcheng POLYGON ((112.7914 28.52688...
Chenzhou 21112 Anren County 2.2407387 0.1334394 Anren POLYGON ((113.1757 26.82734...
Chenzhou 21115 Guidong County 2.0467289 0.1285299 Guidong POLYGON ((114.1799 26.20117...
Chenzhou 21117 Jiahe County 1.5038242 0.0631237 Jiahe POLYGON ((112.4425 25.74358...
Chenzhou 21118 Linwu County 2.0512481 0.1244964 Linwu POLYGON ((112.5914 25.55143...
Chenzhou 21119 Rucheng County 2.7155640 0.2176296 Rucheng POLYGON ((113.6759 25.87578...
Chenzhou 21120 Yizhang County 3.2765386 0.1935418 Yizhang POLYGON ((113.2621 25.68394...
Chenzhou 21121 Yongxing County 2.9211528 0.1767181 Yongxing POLYGON ((113.3169 26.41843...
Chenzhou 21122 Zixing County City 2.6995368 0.2476280 Zixing POLYGON ((113.7311 26.16259...
Hengyang 21123 Changning County City 2.4013569 0.1863642 Changning POLYGON ((112.6144 26.60198...
Hengyang 21124 Hengdong County 2.7098301 0.1756985 Hengdong POLYGON ((113.1056 27.21007...
Hengyang 21125 Hengnan County 3.7804926 0.2408050 Hengnan POLYGON ((112.7599 26.98149...
Hengyang 21126 Hengshan County 2.3513543 0.0899128 Hengshan POLYGON ((112.607 27.4689, ...
Hengyang 21129 Leiyang County 2.7427498 0.2426073 Leiyang POLYGON ((112.9996 26.69276...
Hengyang 21130 Qidong County 3.0714217 0.1733332 Qidong POLYGON ((111.7818 27.0383,...
Huaihua 21131 Chenxi County 3.0228314 0.1821929 Chenxi POLYGON ((110.2624 28.21778...
Huaihua 21134 Zhongfang County 2.9023763 0.1994978 Zhongfang POLYGON ((109.9431 27.72858...
Huaihua 21135 Huitong County 3.1096821 0.2053454 Huitong POLYGON ((109.9419 27.10512...
Huaihua 21136 Jingzhou County 2.8584583 0.1988991 Jingzhou POLYGON ((109.8186 26.75842...
Huaihua 21137 Mayang Autonomous County 2.3274351 0.1462606 Mayang POLYGON ((109.795 27.98008,...
Huaihua 21138 Tongdao Autonomous County 2.5711292 0.2021613 Tongdao POLYGON ((109.9294 26.46561...
Huaihua 21139 Xinhuang Autonomous County 2.1443973 0.1377764 Xinhuang POLYGON ((109.227 27.43733,...
Huaihua 21140 Xupu County 4.0350213 0.3136471 Xupu POLYGON ((110.7189 28.30485...
Huaihua 21141 Yuanling County 4.1642914 0.5345233 Yuanling POLYGON ((110.9652 28.99895...
Huaihua 21142 Zhijiang Autonomous County 2.4452310 0.1906027 Zhijiang POLYGON ((109.8818 27.60661...
Loudi 21143 Lengshuijiang County City 0.9753557 0.0372343 Lengshuijiang POLYGON ((111.5307 27.81472...
Loudi 21146 Shuangfeng County 2.4012680 0.1565776 Shuangfeng POLYGON ((112.263 27.70421,...
Loudi 21147 Xinhua County 3.3284533 0.3361624 Xinhua POLYGON ((111.3345 28.19642...
Shaoyang 21148 Chengbu Autonomous County 2.9374722 0.2362023 Chengbu POLYGON ((110.4455 26.69317...
Yongzhou 21149 Dongan District 3.2132100 0.1983914 Dongan POLYGON ((111.4531 26.86812...
Shaoyang 21150 Dongkou County 2.9425568 0.1971258 Dongkou POLYGON ((110.6622 27.37305...
Shaoyang 21151 Longhui County 2.7208650 0.2578820 Longhui POLYGON ((110.985 27.65983,...
Shaoyang 21152 Shaodong County 2.3029031 0.1701016 Shaodong POLYGON ((111.9054 27.40254...
Shaoyang 21155 Suining County 3.3043615 0.2659378 Suining POLYGON ((110.389 27.10006,...
Shaoyang 21156 Wugang County City 2.2565865 0.1400498 Wugang POLYGON ((110.9878 27.03345...
Shaoyang 21157 Xinning County 3.3414094 0.2487593 Xinning POLYGON ((111.0736 26.84627...
Shaoyang 21158 Xinshao County 2.2955891 0.1658312 Xinshao POLYGON ((111.6013 27.58275...
Xiangtan 21159 Shaoshan County City 0.7722034 0.0212792 Shaoshan POLYGON ((112.5391 27.97742...
Xiangtan 21162 Xiangxiang County City 3.0755761 0.1840808 Xiangxiang POLYGON ((112.4549 28.05783...
Xiangxi Tujia and Miao 21163 Baojing County 2.5569785 0.1606901 Baojing POLYGON ((109.7015 28.82844...
Xiangxi Tujia and Miao 21164 Fenghuang County 2.2928893 0.1596618 Fenghuang POLYGON ((109.5239 28.19206...
Xiangxi Tujia and Miao 21165 Guzhang County 1.7973808 0.1202073 Guzhang POLYGON ((109.8968 28.74034...
Xiangxi Tujia and Miao 21166 Huayuan County 1.7921938 0.1025162 Huayuan POLYGON ((109.5647 28.61712...
Xiangxi Tujia and Miao 21167 Jishou County City 1.8826069 0.0973363 Jishou POLYGON ((109.8375 28.4696,...
Xiangxi Tujia and Miao 21168 Longshan County 2.9782522 0.2919091 Longshan POLYGON ((109.6337 29.62521...
Xiangxi Tujia and Miao 21169 Luxi County 2.2051733 0.1434018 Luxi POLYGON ((110.1067 28.41835...
Xiangxi Tujia and Miao 21170 Yongshun County 3.0959707 0.3551324 Yongshun POLYGON ((110.0003 29.29499...
Yiyang 21171 Anhua County 4.5835050 0.4510648 Anhua POLYGON ((111.6034 28.63716...
Yiyang 21172 Nan County 2.3011103 0.1247939 Nan POLYGON ((112.3232 29.46074...
Yiyang 21176 Yuanjiang County City 2.3268236 0.1886048 Yuanjiang POLYGON ((112.4391 29.1791,...
Yongzhou 21178 Jianghua Autonomous County 3.3360379 0.2927690 Jianghua POLYGON ((111.6461 25.29661...
Yongzhou 21180 Lanshan County 2.3556792 0.1603531 Lanshan POLYGON ((112.2286 25.61123...
Yongzhou 21183 Ningyuan County 3.3322291 0.2266737 Ningyuan POLYGON ((112.0715 26.09892...
Yongzhou 21185 Shuangpai County 2.3877440 0.1540255 Shuangpai POLYGON ((111.8864 26.11957...
Yongzhou 21186 Xintian County 1.7274574 0.0894019 Xintian POLYGON ((112.2578 26.0796,...
Yueyang 21187 Huarong County 2.8178435 0.1678359 Huarong POLYGON ((112.9242 29.69134...
Yueyang 21188 Linxiang County City 2.5975997 0.1568525 Linxiang POLYGON ((113.5502 29.67418...
Yueyang 21189 Miluo County City 2.4474057 0.1497881 Miluo POLYGON ((112.9902 29.02139...
Yueyang 21190 Pingjiang County 3.2177944 0.3786800 Pingjiang POLYGON ((113.8436 29.06152...
Yueyang 21191 Xiangyin County 2.3515063 0.1491429 Xiangyin POLYGON ((112.9173 28.98264...
Zhangjiajie 21194 Cili County 2.8940385 0.3232206 Cili POLYGON ((110.8822 29.69017...
Zhuzhou 21197 Chaling County 2.2375615 0.2278921 Chaling POLYGON ((113.7666 27.10573...
Zhuzhou 21198 Liling County City 2.2435440 0.1960655 Liling POLYGON ((113.5673 27.94346...
Zhuzhou 21199 Yanling County 2.1078954 0.1849090 Yanling POLYGON ((113.9292 26.6154,...
Zhuzhou 21200 You County 2.8904505 0.2436366 You POLYGON ((113.5879 27.41324...
Zhuzhou 21201 Zhuzhou District 0.9331877 0.0373488 Zhuzhou POLYGON ((113.2493 28.02411...
Zhangjiajie 21196 Sangzhi County 3.3475449 0.3216362 Sangzhi POLYGON ((110.556 29.40543,...
Yueyang 21192 Yueyang District 2.5710437 0.1047594 Yueyang POLYGON ((113.343 29.61064,...
Yongzhou 21184 Qiyang County 3.1835301 0.2275458 Qiyang POLYGON ((111.5563 26.81318...
Yiyang 21173 Taojiang County 2.6080229 0.1905982 Taojiang POLYGON ((112.0508 28.67265...
Shaoyang 21153 Shaoyang County City 0.9765399 0.0316779 Shaoyang POLYGON ((111.5013 27.30207...
Loudi 21144 Lianyuan County City 2.8007253 0.2057341 Lianyuan POLYGON ((111.6789 28.02946...
Huaihua 21132 Hongjiang District 3.3031522 0.1994795 Hongjiang POLYGON ((110.1441 27.47513...
Hengyang 21127 Hengyang County City 0.9035944 0.0349171 Hengyang POLYGON ((112.7144 26.98613...
Chenzhou 21116 Guiyang County 3.6939698 0.2668106 Guiyang POLYGON ((113.0811 26.04963...
Changsha 21107 Changsha District 0.9536480 0.0320942 Changsha POLYGON ((112.9421 28.03722...
Changde 21105 Taoyuan County 4.1225866 0.4126555 Taoyuan POLYGON ((112.0612 29.32855...
Xiangtan 21160 Xiangtan County City 0.8480602 0.0253653 Xiangtan POLYGON ((113.0426 27.8942,...
Yongzhou 21177 Dao County 2.7674949 0.2206642 Dao POLYGON ((111.498 25.81679,...
Yongzhou 21179 Jiangyong County 2.2995970 0.1473782 Jiangyong POLYGON ((111.3659 25.39472...

Next, we will import Hunan_2012.csv into R by using read_csv() of readr package.

#output: R dataframe class

hunan2012 <- read_csv("data/aspatial/Hunan_2012.csv")
County City avg_wage deposite FAI Gov_Rev Gov_Exp GDP GDPPC GIO Loan NIPCR Bed Emp EmpR EmpRT Pri_Stu Sec_Stu Household Household_R NOIP Pop_R RSCG Pop_T Agri Service Disp_Inc RORP ROREmp
Anhua Yiyang 30544 10967.0 6831.7 456.72 2703.00 13225.0 14567 9276.90 3954.90 3528.3 2718 494.310 441.4 338.0 54.175 32.830 290.400 234.5 101 670.3 5760.60 910.8 4942.253 5414.5 12373 0.7359464 0.8929619
Anren Chenzhou 28058 4598.9 6386.1 220.57 1454.70 4941.2 12761 4189.20 2555.30 3271.8 970 290.820 255.4 99.4 33.171 17.505 104.600 121.9 34 243.2 2386.40 388.7 2357.764 3814.1 16072 0.6256753 0.8782065
Anxiang Changde 31935 5517.2 3541.0 243.64 1779.50 12482.0 23667 5108.90 2806.90 7693.7 1931 336.390 270.5 205.9 19.584 17.819 148.100 135.4 53 346.0 3957.90 528.3 4524.410 14100.0 16610 0.6549309 0.8041262
Baojing Hunan West 30843 2250.0 1005.4 192.59 1379.10 4087.9 14563 3623.50 1253.70 4191.3 927 195.170 145.6 116.4 19.249 11.831 73.200 69.9 18 184.1 768.04 281.3 1118.561 541.8 13455 0.6544614 0.7460163
Chaling Zhuzhou 31251 8241.4 6508.4 620.19 1947.00 11585.0 20078 9157.70 4287.40 3887.7 1449 330.290 299.0 154.0 33.906 20.548 148.700 139.4 106 301.6 4009.50 578.4 3793.550 5444.0 20461 0.5214385 0.9052651
Changning Hengyang 28518 10860.0 7920.0 769.86 2631.60 19886.0 24418 37392.00 4242.80 9528.0 3605 548.610 415.1 273.7 81.831 44.485 211.200 211.7 115 448.2 5220.40 816.3 6430.782 13074.6 20868 0.5490628 0.7566395
Changsha Changsha 54540 24332.0 33624.0 5350.00 7885.50 88009.0 88656 51361.00 40534.00 17070.0 3310 670.820 452.0 219.4 59.151 39.685 300.300 248.4 214 475.1 22604.00 998.6 13107.148 17726.6 183252 0.4757661 0.6738022
Chengbu Shaoyang 28597 2580.6 1922.3 160.73 1191.60 2569.5 10132 1681.40 1232.00 3271.8 582 162.480 127.6 94.4 18.751 7.869 76.100 59.6 17 189.6 1173.80 256.7 1356.950 1215.1 12379 0.7386054 0.7853274
Chenxi Huaihua 33580 4990.0 5818.4 460.49 1724.20 7755.2 17026 6644.50 3220.00 4777.0 2170 308.430 214.4 174.8 26.706 14.591 139.500 110.5 55 311.7 2570.60 456.7 2257.520 1306.3 14595 0.6825049 0.6951334
Cili Zhangjiajie 33099 8116.9 4498.1 499.77 2306.20 11378.0 18714 5843.30 5503.40 5031.8 2179 381.200 334.8 264.3 34.918 27.020 211.400 174.5 70 379.4 3116.90 610.4 3112.731 5005.6 15603 0.6215596 0.8782791
Dao Yongzhou 32541 7245.0 7922.0 461.66 2013.50 11034.0 18059 2393.80 2873.50 9000.0 1588 381.530 344.3 178.3 65.790 31.430 158.700 157.9 44 388.2 2898.80 613.6 5602.035 8411.1 16305 0.6326597 0.9024192
Dongan Yongzhou 36713 6549.3 9158.0 434.07 1720.60 11495.0 20901 11597.00 3320.60 9116.7 1305 322.250 278.1 163.6 39.419 20.661 166.500 163.0 84 366.0 3106.30 551.2 4866.481 6784.4 20265 0.6640058 0.8629946
Dongkou Shaoyang 31483 9489.6 8703.2 374.96 2209.50 10286.0 13240 10568.00 4120.30 3792.5 1620 583.560 499.2 263.2 69.845 43.194 262.400 220.4 74 523.1 3229.10 780.9 6025.184 9116.8 15375 0.6698681 0.8554390
Fenghuang Hunan West 31608 4008.7 2550.0 406.51 1763.60 4681.2 13382 848.99 2863.00 4681.2 1212 250.730 195.4 151.8 33.379 17.690 90.100 80.5 17 255.5 2605.40 351.3 1206.261 651.1 14281 0.7272986 0.7793244
Guidong Chenzhou 30149 2200.1 2512.9 111.19 880.00 1955.9 8497 1202.60 1437.20 3130.4 567 138.530 115.2 56.9 13.437 7.091 64.800 65.4 14 150.1 486.10 231.8 630.016 911.1 12290 0.6475410 0.8315888
Guiyang Chenzhou 41394 9664.8 15712.0 1309.20 2727.50 23023.0 32853 36820.00 4860.10 10271.0 2237 517.180 430.9 242.0 69.344 33.568 231.800 217.5 127 420.4 6281.80 704.1 8804.639 14791.5 64517 0.5970743 0.8331722
Guzhang Hunan West 28610 1563.8 1021.7 108.40 959.60 1490.4 11580 513.95 849.56 3595.9 392 98.421 74.6 56.7 8.718 6.288 35.200 31.4 10 85.2 354.48 129.0 527.230 504.0 11954 0.6604651 0.7579683
Hanshou Changde 32265 7979.0 8665.0 386.13 2062.40 15788.0 20981 13491.00 4550.00 8269.9 2560 456.780 388.8 246.7 42.097 33.029 240.200 208.7 95 553.2 4460.50 804.6 6545.350 17727.0 18925 0.6875466 0.8511756
Hengdong Hengyang 30992 8661.0 6665.0 542.25 1937.40 17409.0 27485 17305.00 4118.00 10829.0 1859 388.340 284.5 201.0 48.983 36.120 164.400 167.4 96 426.4 5127.00 634.9 5972.961 11278.5 19800 0.6716018 0.7326054
Hengnan Hengyang 28031 3288.9 9531.4 804.91 2894.40 21019.0 21911 20953.00 4013.00 9872.9 2173 601.570 503.6 354.0 76.933 57.519 256.000 274.3 118 629.1 5752.60 961.4 8624.680 15914.0 18683 0.6543582 0.8371428
Hengshan Hengyang 28688 5944.6 4871.1 451.46 1393.70 9718.9 25172 8571.50 2221.50 10619.0 966 291.120 261.9 158.8 28.997 20.909 103.700 101.0 89 256.4 1713.70 387.0 3505.269 6233.5 17732 0.6625323 0.8996290
Hengyang Hengyang 27760 14680.0 11145.0 597.66 2778.80 21495.0 19382 18288.00 5549.60 10313.0 2632 686.520 500.2 313.6 88.917 64.674 299.200 247.7 120 733.4 5386.30 1111.6 12451.938 23139.2 124392 0.6597697 0.7286022
Hongjiang Huaihua 37686 5966.0 6515.5 623.95 2067.80 7355.5 17733 13750.00 3272.20 6553.5 1161 229.400 199.9 132.0 23.614 18.837 136.100 124.7 76 260.9 1744.20 415.8 2588.250 202.8 27334 0.6274651 0.8714037
Huarong Yueyang 26832 8116.4 14292.0 365.84 1933.90 21654.0 30413 40193.00 4564.80 10367.0 1500 442.970 359.2 252.9 31.601 26.933 202.300 170.2 151 430.3 6348.90 714.1 7690.520 10050.6 21501 0.6025767 0.8108901
Huayuan Hunan West 31708 3669.8 2200.0 331.78 1503.70 5905.9 20337 9257.60 2463.60 4353.8 1240 214.790 149.8 94.9 23.831 14.031 76.900 59.9 74 188.1 1024.70 291.1 883.722 533.2 15467 0.6461697 0.6974254
Huitong Huaihua 33693 4615.0 2617.4 295.00 1306.70 4588.3 14334 2095.60 1369.30 4631.9 1194 246.150 193.5 143.7 20.603 13.337 96.700 114.4 25 234.5 1061.70 320.9 1580.090 5.2 13989 0.7307572 0.7861060
Jiahe Chenzhou 36023 5493.1 4864.3 453.68 1331.50 9608.2 32091 14882.00 1906.50 7903.3 719 242.800 198.9 83.0 36.054 19.497 99.000 108.5 100 179.6 1365.90 301.3 2276.272 3230.2 17744 0.5960836 0.8191928
Jianghua Yongzhou 34378 4586.4 4631.5 309.70 1651.40 6555.9 15801 3357.10 2976.00 3225.3 1663 306.310 272.7 188.9 37.494 20.644 109.900 116.1 33 285.1 2384.80 416.7 3272.511 10533.8 16274 0.6841853 0.8902746
Jiangyong Yongzhou 30250 3198.2 3942.5 187.23 1009.10 4012.2 17168 2022.70 1201.20 3253.9 720 153.580 132.8 94.3 21.936 11.093 68.300 61.2 25 163.5 1238.20 234.3 2862.901 9773.3 16634 0.6978233 0.8646959
Jingzhou Huaihua 33870 3592.8 2031.4 237.51 1129.00 5007.7 20348 4534.10 1566.50 5397.3 1054 163.910 112.6 85.8 16.978 11.446 69.100 56.1 32 140.6 1611.50 246.7 1769.328 337.5 12859 0.5699230 0.6869624
Jinshi Changde 28692 4581.7 4777.0 373.31 1148.40 8706.9 34592 10935.00 2242.00 8169.9 848 122.780 82.1 61.7 8.723 7.592 81.900 43.7 77 92.4 3683.00 251.8 2562.460 7525.0 19498 0.3669579 0.6686757
Jishou Hunan West 39816 9586.2 5235.0 470.22 1738.20 9631.5 31537 6345.70 8282.90 4823.0 3790 213.420 97.0 62.4 25.454 21.941 99.200 46.5 49 85.2 5651.00 306.6 849.010 611.6 17980 0.2778865 0.4545029
Lanshan Yongzhou 33756 4236.0 3986.7 296.68 1194.60 6627.2 20088 5392.10 1599.40 8672.1 1144 233.390 201.5 131.6 32.448 16.299 83.300 90.7 52 198.2 2234.20 330.9 2262.021 10341.9 19161 0.5989725 0.8633618
Leiyang Hengyang 32814 15393.0 18687.0 1535.20 3819.00 30213.0 26105 42707.00 7409.20 10611.0 2531 750.120 553.7 405.8 112.200 56.350 338.100 281.2 155 629.3 7268.10 1160.2 8349.199 19981.6 19634 0.5424065 0.7381486
Lengshuijiang Loudi 35647 6805.3 9746.8 1054.20 2105.30 21243.0 64257 36926.00 8936.60 10441.0 1413 191.320 101.8 61.8 29.639 20.113 112.400 56.9 118 78.4 5750.60 332.6 1277.869 991.8 23120 0.2357186 0.5320928
Li Changde 32541 13487.0 16066.0 709.61 2459.50 20322.0 24473 18402.00 6748.00 8377.0 2038 513.440 426.8 227.1 38.975 33.938 268.500 256.0 96 539.7 7110.20 832.5 7562.340 53160.0 18985 0.6482883 0.8312558
Lianyuan Loudi 30320 8059.7 9255.3 707.45 3298.60 18340.0 18346 20515.00 7243.20 4307.7 2260 706.840 612.9 344.1 71.232 53.597 316.200 298.7 154 712.6 6889.00 1001.5 7642.158 5965.4 38131 0.7115327 0.8670986
Liling Zhuzhou 42896 12865.0 19125.0 2602.60 4221.40 39553.0 41491 57146.00 9398.10 13347.0 2797 639.830 513.1 212.1 53.992 33.705 248.400 229.7 482 473.2 11213.00 958.0 5373.990 17378.0 24185 0.4939457 0.8019318
Linli Changde 32667 564.1 7781.2 336.86 1538.70 10355.0 25554 8214.00 358.00 8143.1 1440 307.360 272.2 100.8 23.286 18.943 129.100 157.2 99 246.6 3604.90 409.3 3583.910 7031.0 18604 0.6024921 0.8856065
Linwu Chenzhou 32031 5984.0 5734.3 478.92 1435.20 8191.1 23986 6250.70 2152.70 7102.2 959 215.300 184.1 90.2 41.913 13.238 101.500 88.0 67 227.5 2023.30 342.8 1606.947 2632.2 17966 0.6636523 0.8550859
Linxiang Yueyang 31669 5850.5 10852.0 319.20 1609.00 15968.0 31897 29988.00 3788.20 9739.0 1289 293.500 212.5 98.8 36.202 23.831 138.600 136.7 123 286.1 4598.80 502.3 3357.477 2994.6 20628 0.5695799 0.7240204
Liuyang Changsha 40446 21415.0 43599.0 2473.10 4605.50 81113.0 63118 99254.00 23408.00 15719.0 6225 919.620 721.4 300.1 90.978 58.819 374.800 369.8 733 642.7 16233.00 1285.5 10844.470 26617.8 27345 0.4999611 0.7844544
Longhui Shaoyang 33615 11925.0 8723.9 425.06 2741.60 10511.0 9572 9317.90 3985.50 3177.6 2726 709.990 604.4 436.7 95.163 54.211 344.600 298.8 85 834.1 2819.60 1098.2 4320.396 3264.6 12049 0.7595156 0.8512796
Longshan Hunan West 34203 5557.0 2810.0 218.53 2052.40 4933.6 9754 893.45 2128.20 4164.0 1505 334.420 266.7 167.5 42.189 30.946 148.200 126.1 18 345.8 2293.90 508.3 2248.709 921.5 13138 0.6803069 0.7975001
Luxi Hunan West 32680 2946.8 1772.0 184.25 1337.60 4878.3 17472 7085.60 1626.60 4089.1 664 197.490 149.7 80.9 21.683 17.160 82.400 71.1 42 174.3 917.41 280.3 1036.088 540.8 13247 0.6218337 0.7580131
Mayang Huaihua 32772 3456.0 2703.1 215.86 1461.00 4738.8 13744 3876.90 2242.00 4299.8 975 216.850 160.0 148.1 24.173 15.207 90.300 87.8 33 245.0 1581.70 345.6 1865.938 5.2 14487 0.7089120 0.7378372
Miluo Yueyang 36113 4749.3 15828.0 1068.60 2446.50 29548.0 42497 66342.00 3330.60 9421.3 965 451.270 303.3 162.8 40.221 30.662 204.900 193.6 269 351.4 5817.70 697.0 5688.717 8978.5 23379 0.5041607 0.6721032
Nan Yiyang 35272 8921.7 3367.5 300.00 1987.10 15568.0 21311 11804.00 4928.10 8369.8 1877 366.100 325.6 226.1 35.487 29.444 259.200 201.3 91 455.9 5266.20 732.8 7783.359 6781.7 17691 0.6221343 0.8893745
Ningxiang Changsha 40744 18662.0 49234.0 2448.90 4812.20 73250.0 62202 114145.00 18435.00 13763.0 4351 852.960 757.6 318.3 80.715 68.853 391.700 369.6 552 655.5 15623.00 1186.5 12804.480 18447.7 24020 0.5524652 0.8882011
Ningyuan Yongzhou 34190 7351.4 7716.5 514.24 2234.40 8984.3 12697 5627.80 4249.40 4151.5 1753 444.920 401.3 157.8 68.336 32.471 185.500 157.8 64 460.9 3097.50 710.2 4283.431 9958.4 19742 0.6489721 0.9019599
Pingjiang Yueyang 30017 8718.4 10627.0 461.62 2827.00 16444.0 17252 25647.00 5201.20 3780.8 2205 601.380 512.8 278.3 73.943 43.548 260.900 269.9 136 612.5 3448.30 957.5 5060.948 8789.3 14883 0.6396867 0.8527054
Qidong Hengyang 30990 13633.0 6875.7 463.91 2413.20 17718.0 18001 26260.00 4246.10 9020.6 2055 607.640 529.2 311.0 80.694 51.474 289.200 287.3 115 627.8 6076.00 986.4 7380.180 15451.7 18256 0.6364558 0.8709104
Qiyang Yongzhou 32059 14432.0 14439.0 499.51 2710.50 17705.0 20638 11567.00 6388.30 8816.0 2799 594.100 495.2 257.9 75.936 45.318 241.900 255.1 107 519.9 3832.70 860.7 6273.597 13568.8 19776 0.6040432 0.8335297
Rucheng Chenzhou 35575 4777.6 3816.6 343.00 1492.70 3756.0 11286 4492.20 2426.20 2993.7 1130 232.280 197.3 127.8 33.101 14.478 111.300 101.6 43 235.7 751.80 333.2 2079.963 1744.7 13755 0.7073830 0.8494059
Sangzhi Zhangjiajie 33916 3920.0 3081.3 248.06 1856.10 5615.4 14624 1694.80 2981.20 3405.9 1999 267.150 234.5 139.8 31.278 18.993 127.900 122.8 28 256.9 1803.30 385.5 3607.897 17585.8 45167 0.6664073 0.8777840
Shaodong Shaoyang 31507 16184.0 12214.0 771.60 2757.00 22898.0 25246 29175.00 7855.30 10089.0 3080 724.310 547.7 310.0 99.082 59.009 363.200 297.8 148 524.9 8576.30 912.1 5704.602 4679.3 18296 0.5754851 0.7561679
Shaoshan Xiangtan 33314 2626.4 4500.0 258.64 683.65 4956.8 55570 9717.60 1649.00 14916.0 488 73.652 62.0 33.6 5.910 3.201 27.147 30.4 48 57.7 1200.80 92.3 807.714 1630.3 24991 0.6251354 0.8417966
Shaoyang Shaoyang 31783 8345.7 7237.3 376.42 2780.80 9031.2 9653 7887.80 2425.30 3499.3 2294 655.130 569.2 385.0 71.417 43.525 265.400 247.9 65 657.6 3406.30 942.3 5518.299 21656.5 65431 0.6978669 0.8688352
Shimen Changde 33261 8334.4 10531.0 548.33 2178.80 16293.0 27137 17795.00 6026.50 6156.0 2502 392.050 329.6 193.8 29.245 26.104 190.600 184.7 122 399.2 6490.70 600.5 5266.510 6981.0 19275 0.6647794 0.8407091
Shuangfeng Loudi 33684 11455.0 7904.9 470.59 2657.50 15225.0 17755 16665.00 3914.00 5470.3 1862 559.470 488.5 309.6 57.966 41.575 244.300 245.6 129 644.6 4596.00 859.4 7943.893 2613.1 14994 0.7500582 0.8731478
Shuangpai Yongzhou 33302 1918.0 3572.0 226.37 881.96 3728.0 21942 2646.30 2056.40 4568.1 408 86.264 68.0 46.2 11.339 6.890 57.600 39.5 34 111.6 567.21 174.1 1866.171 9092.1 18479 0.6410109 0.7882778
Suining Shaoyang 31750 4307.1 3605.6 222.40 1442.50 5658.1 16069 11150.00 1566.40 4990.4 802 264.080 208.9 145.2 26.200 14.261 108.800 86.3 54 268.4 1761.50 352.9 2064.499 1413.5 15004 0.7605554 0.7910482
Taojiang Yiyang 35184 8657.4 8743.0 417.37 2276.80 15162.0 19509 18691.00 4656.80 8687.9 2504 472.800 411.4 194.0 48.047 33.234 260.900 208.8 153 504.5 5355.90 779.7 13878.842 13439.3 79214 0.6470437 0.8701354
Taoyuan Changde 31877 11948.0 8656.0 710.08 2625.10 19603.0 22879 16529.00 4735.00 7682.6 2070 558.770 479.9 300.5 44.429 36.630 274.500 272.0 60 607.4 8926.00 857.1 18328.460 50619.0 60461 0.7086688 0.8588507
Tongdao Huaihua 35400 2578.0 1525.4 165.59 1046.50 2653.2 12781 2514.50 1021.00 3696.4 882 144.490 105.5 82.2 15.913 7.776 57.900 49.7 27 154.2 749.14 208.1 981.418 644.2 12424 0.7409899 0.7301543
Wangcheng Changsha 45171 12122.0 48829.0 2285.50 3802.30 37488.0 70666 148976.00 10330.00 16495.0 1678 361.480 268.6 131.2 28.838 24.815 161.300 154.8 314 266.6 5623.30 533.4 5222.356 6648.6 27690 0.4998125 0.7430563
Wugang Shaoyang 30573 8618.0 7373.3 486.85 2346.00 9046.7 12112 5346.00 3852.00 4864.4 2250 483.620 402.5 271.4 70.758 43.683 243.900 194.0 52 502.9 3476.00 752.3 4613.704 1734.7 15126 0.6684833 0.8322650
Xiangtan Xiangtan 35274 15516.0 10121.0 1236.60 3050.10 22728.0 27060 30730.00 12217.00 10135.0 2022 610.490 551.9 347.1 46.556 54.439 248.590 239.1 187 574.0 4889.10 845.2 10688.618 40758.0 69261 0.6791292 0.9040279
Xiangxiang Xiangtan 33040 13298.0 9819.0 975.59 2942.80 23175.0 29361 39630.00 7900.30 9264.3 2451 586.400 492.0 324.5 47.743 39.612 231.710 242.0 189 535.7 5891.80 787.8 6852.943 17531.9 22297 0.6799949 0.8390177
Xiangyin Yueyang 33169 5466.1 14714.0 520.53 2318.80 23265.0 33983 49507.00 5222.90 8824.5 1550 466.110 357.4 169.4 44.878 30.752 193.800 190.1 152 408.4 4273.20 686.9 6000.857 8175.0 19945 0.5945552 0.7667718
Xinhua Loudi 32496 11075.0 6725.3 576.47 3599.50 14940.0 13398 12152.00 6121.20 3342.4 1542 755.140 677.9 451.6 96.224 57.670 316.600 313.8 112 817.4 5743.50 1116.7 6919.849 3145.3 13834 0.7319782 0.8977143
Xinhuang Huaihua 31891 2373.1 2075.8 170.11 1069.30 3782.1 15412 3405.70 1265.20 3935.6 1350 149.710 105.6 104.0 15.938 8.781 72.000 72.5 36 178.6 873.45 246.0 1130.322 785.8 12732 0.7260163 0.7053637
Xinning Shaoyang 32067 6126.3 5978.8 390.67 1830.60 6064.6 10732 3857.70 2899.90 3287.7 1565 429.840 347.8 227.4 41.633 22.005 171.400 146.5 38 383.6 1445.90 566.7 2415.712 2364.9 13031 0.6769014 0.8091383
Xinshao Shaoyang 34199 7344.2 8313.8 384.19 2229.20 8590.9 11514 10829.00 5042.50 3986.4 2319 577.690 477.4 265.8 68.131 39.034 234.100 213.0 79 533.6 2941.60 749.0 3003.553 5679.2 13778 0.7124166 0.8263948
Xintian Yongzhou 33609 3851.6 3401.9 250.31 1280.20 4776.4 14426 3357.40 1334.90 2894.9 1264 236.520 217.1 116.9 32.138 15.970 93.800 107.1 42 226.6 1329.80 332.1 2530.482 3134.3 16925 0.6823246 0.9178928
Xupu Huaihua 29873 8675.5 6112.2 457.86 2452.00 10314.0 13863 6720.40 4588.00 5453.1 2106 512.610 400.9 292.3 53.793 29.166 226.100 211.2 71 516.0 3427.30 745.9 4308.431 242.6 16558 0.6917817 0.7820760
Yanling Zhuzhou 34156 3274.4 5835.0 402.90 1038.20 4250.5 21021 5855.80 2379.60 3608.4 545 116.180 99.0 54.0 10.838 6.682 52.200 46.0 75 112.2 1241.20 202.2 971.500 6851.0 18652 0.5548961 0.8521260
Yizhang Chenzhou 33508 7938.8 9992.5 750.40 2142.60 10455.0 17814 19120.00 3697.00 3788.6 2280 348.830 279.9 128.8 63.564 25.843 161.300 142.5 169 363.4 5037.50 588.9 2521.831 3584.6 19318 0.6170827 0.8023966
Yongshun Hunan West 31234 4516.9 2464.1 220.66 2021.70 4142.1 9590 1061.00 2839.90 3963.1 1801 312.990 259.4 195.7 38.686 24.854 115.700 113.9 23 292.5 2247.30 433.3 2018.756 845.8 12650 0.6750519 0.8287805
Yongxing Chenzhou 33278 7097.6 13456.0 1294.50 2476.00 21382.0 37651 43700.00 3053.70 9856.1 1969 375.500 304.9 133.5 52.440 19.765 172.500 145.7 175 333.5 4807.10 562.6 3174.984 4540.5 19960 0.5927835 0.8119840
You Zhuzhou 36791 9541.6 15611.0 1533.30 2803.00 25153.0 36264 32738.00 6316.20 13021.0 1992 472.320 418.0 254.3 42.124 31.908 186.400 196.9 248 344.4 7654.80 693.7 6071.620 27443.0 22732 0.4964682 0.8849932
Yuanjiang Yiyang 33302 7763.4 10486.0 509.45 2381.20 17603.0 26258 21082.00 6464.20 10060.0 1856 401.220 335.2 203.3 34.220 27.932 260.300 161.0 105 366.7 5125.10 672.5 6644.520 5899.6 20552 0.5452788 0.8354519
Yuanling Huaihua 37762 5627.0 5466.8 677.40 2202.60 14156.0 24194 14835.00 2485.30 4265.4 2501 382.530 283.9 210.2 33.935 21.278 166.500 155.9 56 397.0 3092.50 586.5 2508.387 637.8 15165 0.6768968 0.7421640
Yueyang Yueyang 31470 4946.6 15084.0 330.43 1971.60 18974.0 26360 36800.00 3668.70 10377.0 1616 411.260 293.3 173.0 40.218 30.051 201.500 150.9 158 435.3 5836.60 721.7 11279.478 15381.2 88494 0.6031592 0.7131741
Zhijiang Huaihua 33582 4306.1 2802.2 356.96 1470.00 6992.5 20518 4491.80 2477.30 4535.1 935 223.750 175.5 116.1 23.693 14.726 101.800 94.3 56 247.6 2133.30 341.6 2576.470 90.8 13589 0.7248244 0.7843575
Zhongfang Huaihua 34941 1296.3 7594.6 348.83 1048.00 7332.1 30846 8608.50 968.44 6082.5 662 170.250 103.1 89.3 12.709 8.563 71.100 70.9 56 173.8 1064.90 238.3 2917.158 1938.6 37231 0.7293328 0.6055800
Zhuzhou Zhuzhou 37191 5395.6 4777.7 507.04 1408.80 7962.1 27589 6768.90 2970.20 11407.0 1032 210.380 177.0 106.0 12.436 11.824 92.200 85.2 82 210.6 2538.40 289.6 4236.370 10883.0 103228 0.7272099 0.8413347
Zixing Chenzhou 34163 7873.2 14891.0 1556.00 2679.00 22261.0 65706 51921.00 5014.70 10838.0 1159 261.980 177.9 76.0 22.316 14.760 114.000 86.3 155 140.2 4835.80 340.2 2761.164 3636.3 21600 0.4121105 0.6790595

The code chunk below will be used to update the attribute table of hunan’s SpatialPolygonsDataFrame with the attribute fields of hunan2012 dataframe. This is performed by using left_join() of dplyr package.

colnames(hunan)
[1] "NAME_2"     "ID_3"       "NAME_3"     "ENGTYPE_3"  "Shape_Leng"
[6] "Shape_Area" "County"     "geometry"  
colnames(hunan2012)
 [1] "County"      "City"        "avg_wage"    "deposite"    "FAI"        
 [6] "Gov_Rev"     "Gov_Exp"     "GDP"         "GDPPC"       "GIO"        
[11] "Loan"        "NIPCR"       "Bed"         "Emp"         "EmpR"       
[16] "EmpRT"       "Pri_Stu"     "Sec_Stu"     "Household"   "Household_R"
[21] "NOIP"        "Pop_R"       "RSCG"        "Pop_T"       "Agri"       
[26] "Service"     "Disp_Inc"    "RORP"        "ROREmp"     
hunan <- left_join(hunan,hunan2012) %>%
  select(1:4, 7, 15)

3.2 Visualising Regional Development Indicator

Now, we are going to prepare a basemap and a choropleth map showing the distribution of GDPPC 2012 by using qtm() of tmap package.

Show the code
basemap <- tm_shape(hunan) +
  tm_polygons() +
  tm_text("NAME_3", 
          size=0.3) +
  tm_layout(bg.color = "#E4D5C9",
            frame = F)

gdppc <- qtm(hunan, "GDPPC") +
  tm_layout(bg.color = "#E4D5C9",
            frame = F,
            legend.title.size = 0.9,
            legend.text.size = 0.5)

tmap_arrange(basemap, gdppc, asp=1, ncol=2)

4 Global Spatial Autocorrelation

This section is where we will compute global spatial autocorrelation statistics and perform spatial complete randomness test for global spatial autocorrelation.

4.1 Computing Contiguity Spatial Weights

Before we can compute the global spatial autocorrelation statistics, we need to construct a spatial weights of the study area. The spatial weights is used to define the neighbourhood relationships between the geographical units (i.e. county) in the study area.

  • poly2nb() of spdep package to compute contiguity weight matrices for the study area.
  • This function builds a neighbours list based on regions with contiguous boundaries. If you look at the documentation you will see that you can pass a “queen” argument that takes TRUE or FALSE as options.
  • Default: Queen = TRUE, but if you change it to FALSE, you are using ROOK method.
  • The output that you will get is a list.

The code chunk below will be used to compute Queen contiguity weight matrix:

wm_q <- poly2nb(hunan, 
                queen=TRUE)
summary(wm_q)
Neighbour list object:
Number of regions: 88 
Number of nonzero links: 448 
Percentage nonzero weights: 5.785124 
Average number of links: 5.090909 
Link number distribution:

 1  2  3  4  5  6  7  8  9 11 
 2  2 12 16 24 14 11  4  2  1 
2 least connected regions:
30 65 with 1 link
1 most connected region:
85 with 11 links

4.2 Row-standardised weights matrix

  • Assign weights to each neighboring polygon. In our case, each neighboring polygon will be assigned equal weight (style=“W”).

  • This is accomplished by assigning the fraction 1/(# of neighbors) to each neighboring county then summing the weighted income values.

  • While this is the most intuitive way to summaries the neighbors’ values it has one drawback in that polygons along the edges of the study area will base their lagged values on fewer polygons thus potentially over- or under-estimating the true nature of the spatial autocorrelation in the data.

  • Style=“W” option used for this example for simplicity’s sake but more robust options are available, notably style=“B”.

    • Styles:
      • W: row standardised (sums over all links to n)
      • B: basic binary coding
      • C: globally standardised (sums over all links to n)
      • U: equal to C divided by the number of neighbours (sums over all links to unity)
      • S: variance-stabilizing coding scheme (sums over all links to n)
      • minmax: divides the weights by min of the max row sums and max column sums of the input weights; similar to C/U
  • The input of *nb2listw() must be an object of class nb. The syntax of the function has two major arguments, namely style and zero.poly.

rswm_q <- nb2listw(wm_q,
                   style="W",
                   zero.policy = TRUE) 
rswm_q
Characteristics of weights list object:
Neighbour list object:
Number of regions: 88 
Number of nonzero links: 448 
Percentage nonzero weights: 5.785124 
Average number of links: 5.090909 

Weights style: W 
Weights constants summary:
   n   nn S0       S1       S2
W 88 7744 88 37.86334 365.9147

zero.policy = TRUE allows for lists of non-neighbors. This should be used with caution since the user may not be aware of missing neighbors in their dataset however, a zero.policy = FALSE would return an error.

If zero policy = TRUE, weights vectors of zero length are inserted for regions without neighbour in the neighbours list. These will in turn generate lag values of zero, equivalent to the sum of products of the zero row t(rep(0, length = length(neighbours))) %*% x, for arbitrary numerical vector x of length length(neighbours). The spatially lagged value of x for the zero-neighbour region will then be zero, which may (or may not) be a sensible choice.

4.3 Global Spatial Autocorrelation: Moran’s I

  • Describe how features differ from the values in the study area as a whole

  • Hypothesis:

\(H_0\): Observed spatial patterns of values is equally likely as any other spatial pattern i.e. data is randomly disbursed, no spatial pattern

\(H_1\): Data is more spatially clustered than expected by chance alone.

Moran I (\(Z\) value) is:

  • positive (I>0): Clustered, observations tend to be similar;
  • negative(I<0): Dispersed, observations tend to be dissimilar;
  • approximately zero: observations are arranged randomly over space.

Moran’s I statistical testing using moran.test() of spdep.

moran.test(hunan$GDPPC, 
           listw=rswm_q, 
           zero.policy = TRUE, 
           na.action=na.omit)

    Moran I test under randomisation

data:  hunan$GDPPC  
weights: rswm_q    

Moran I statistic standard deviate = 4.7351, p-value = 1.095e-06
alternative hypothesis: greater
sample estimates:
Moran I statistic       Expectation          Variance 
      0.300749970      -0.011494253       0.004348351 

Permutation test for Moran’s I statistic by using moran.mc() of spdep. A total of 1000 simulation will be performed.

set.seed(1234)

bperm= moran.mc(hunan$GDPPC, 
                listw=rswm_q, 
                nsim=999, 
                zero.policy = TRUE, 
                na.action=na.omit)
bperm

    Monte-Carlo simulation of Moran I

data:  hunan$GDPPC 
weights: rswm_q  
number of simulations + 1: 1000 

statistic = 0.30075, observed rank = 1000, p-value = 0.001
alternative hypothesis: greater

Using hist()

Plot the distribution of the statistical values as histogram to examine the simulated Moran’s I test statistics in greater detail: hist() and abline() of R Graphics are used.

Show the code
par(bg = '#E4D5C9')


mean(bperm$res[1:999])
[1] -0.01504572
Show the code
var(bperm$res[1:999])
[1] 0.004371574
Show the code
summary(bperm$res[1:999])
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-0.18339 -0.06168 -0.02125 -0.01505  0.02611  0.27593 
Show the code
hist(bperm$res, 
     freq=TRUE, 
     breaks=20, 
     col = "#efe7df",
     xlab="Simulated Moran's I")

abline(v=0, 
       col="#800200",
       lwd = 3,
       lty = 2) 

Using ggplot

plot2 <- bperm$res
mu <- mean(plot2)

ggplot(data=data.frame(plot2),
       aes(x=plot2)
  ) +
  geom_histogram(
    bins=30,
    fill="#efe7df",
    color="black",
    size=0.2
  ) +
  geom_vline(
    xintercept = mu,
    color="#800200",
    linetype = "longdash",
    size = 1
  ) +
  labs(title ="Histogram of Monte Carlo Moran's Is",
    x = "Simulated Moran's I",
    y = "Frequency"
  ) +
  theme(
    plot.title = element_text(face = "bold", size = 10, hjust = 0.5),
    axis.title.x = element_text(size = 8),
    axis.title.y = element_text(hjust=1, angle=0, size = 8),
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    plot.background = element_rect(fill = "#E4D5C9", color = "#E4D5C9"),
    panel.background = element_rect(fill = "#E4D5C9", color = "#E4D5C9")
  )

4.5 Global Spatial Autocorrelation: Geary’s

In this section, you will learn how to perform Geary’s c statistics testing by using appropriate functions of spdep package.

Describes how features differ from their immediate neighbours.

Geary c (\(Z\) value) is:

  • Large c value (>1) : Dispersed, observations tend to be dissimilar;
  • Small c value (<1) : Clustered, observations tend to be similar;
  • c = 1: observations are arranged randomly over space.

The code chunk below performs Geary’s C test for spatial autocorrelation by using geary.test() of spdep.

geary.test(hunan$GDPPC, 
           listw = rswm_q)

    Geary C test under randomisation

data:  hunan$GDPPC 
weights: rswm_q 

Geary C statistic standard deviate = 3.6108, p-value = 0.0001526
alternative hypothesis: Expectation greater than statistic
sample estimates:
Geary C statistic       Expectation          Variance 
        0.6907223         1.0000000         0.0073364 

Question: What statistical conclusion can you draw from the output above?

  • Here, the p-value is 0.0001526.
  • We will reject the null hypothesis at 99.9% as the p-value is smaller than our alpha value, 0.001.
  • The Geary C statistic is 0.6907223 which is < 1, hence the spatial pattern is “clustered”.

Performs permutation test for Geary’s C statistic by using geary.mc() of spdep.

set.seed(1234)
bperm=geary.mc(hunan$GDPPC, 
               listw=rswm_q, 
               nsim=999)
bperm

    Monte-Carlo simulation of Geary C

data:  hunan$GDPPC 
weights: rswm_q 
number of simulations + 1: 1000 

statistic = 0.69072, observed rank = 1, p-value = 0.001
alternative hypothesis: greater

Question: What statistical conclusion can you draw from the output above?

  • After running 1000 simulations, the p-value is now = 0.001.
  • Hence, we will accept / cannot reject the null hypothesis at 99.9% as the p-value is equal to our alpha value, 0.001.
  • The Geary C statistic is now, 0.69072, which is still < 1, hence the spatial pattern is “clustered”.

Plot a histogram to reveal the distribution of the simulated values by using the code chunk below.

Show the code
par(bg = '#E4D5C9')

mean(bperm$res[1:999])
[1] 1.004402
Show the code
var(bperm$res[1:999])
[1] 0.007436493
Show the code
summary(bperm$res[1:999])
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.7142  0.9502  1.0052  1.0044  1.0595  1.2722 
Show the code
hist(bperm$res, 
     freq=TRUE, 
     breaks=20, 
     col = "#efe7df",
     xlab="Simulated Geary c")

abline(v=1, 
       col="#800200",
       lwd = 3,
       lty = 2) 

plot2 <- bperm$res
mu <- mean(plot2)

ggplot(data=data.frame(plot2),
       aes(x=plot2)
  ) +
  geom_histogram(
    bins=30,
    fill="#efe7df",
    color="black",
    size=0.2
  ) +
  geom_vline(
    xintercept = mu,
    color="#800200",
    linetype = "longdash",
    size = 1
  ) +
  labs(title ="Histogram of Monte Carlo Geary's Cs",
    x = "Simulated Geary's C",
    y = "Frequency"
  ) +
  theme(
    plot.title = element_text(face = "bold", size = 10, hjust = 0.5),
    axis.title.x = element_text(size = 8),
    axis.title.y = element_text(hjust=1, angle=0, size = 8),
    axis.ticks = element_blank(),
    axis.text = element_text(size = 6),
    plot.background = element_rect(fill = "#E4D5C9", color = "#E4D5C9"),
    panel.background = element_rect(fill = "#E4D5C9", color = "#E4D5C9")
  )

Question: What statistical observation can you draw from the output?

The distribution is close to a normal distribution, with more values in the center of the histogram.

5 Spatial Correlogram

  • Spatial correlograms are for examining patterns of spatial autocorrelation in the data or model residuals.
  • They show how correlated are pairs of spatial observations when you increase the distance (lag) between them
    • they are plots of some index of autocorrelation (Moran’s I or Geary’s c) against distance.
  • Although correlograms are not as fundamental as variograms (a keystone concept of geostatistics), they are very useful as an exploratory and descriptive tool.
  • For this purpose they actually provide richer information than variograms.
  • sp.correlogram() of spdep package: computes a 6-lag spatial correlogram of GDPPC.
  • The global spatial autocorrelation used in Moran’s I.
  • The plot() of base Graph is then used to plot the output.
MI_corr <- sp.correlogram(wm_q, 
                          hunan$GDPPC, 
                          order=6, 
                          method="I", 
                          style="W")

print(MI_corr)
Spatial correlogram for hunan$GDPPC 
method: Moran's I
         estimate expectation   variance standard deviate Pr(I) two sided    
1 (88)  0.3007500  -0.0114943  0.0043484           4.7351       2.189e-06 ***
2 (88)  0.2060084  -0.0114943  0.0020962           4.7505       2.029e-06 ***
3 (88)  0.0668273  -0.0114943  0.0014602           2.0496        0.040400 *  
4 (88)  0.0299470  -0.0114943  0.0011717           1.2107        0.226015    
5 (88) -0.1530471  -0.0114943  0.0012440          -4.0134       5.984e-05 ***
6 (88) -0.1187070  -0.0114943  0.0016791          -2.6164        0.008886 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
par(bg = '#E4D5C9')
plot(MI_corr)

  • sp.correlogram() of spdep package: used to compute a 6-lag spatial correlogram of GDPPC.
  • The global spatial autocorrelation used in Geary’s C.
  • The plot() of base Graph is then used to plot the output.
GC_corr <- sp.correlogram(wm_q, 
                          hunan$GDPPC, 
                          order=6, 
                          method="C", 
                          style="W")
print(GC_corr)
Spatial correlogram for hunan$GDPPC 
method: Geary's C
        estimate expectation  variance standard deviate Pr(I) two sided    
1 (88) 0.6907223   1.0000000 0.0073364          -3.6108       0.0003052 ***
2 (88) 0.7630197   1.0000000 0.0049126          -3.3811       0.0007220 ***
3 (88) 0.9397299   1.0000000 0.0049005          -0.8610       0.3892612    
4 (88) 1.0098462   1.0000000 0.0039631           0.1564       0.8757128    
5 (88) 1.2008204   1.0000000 0.0035568           3.3673       0.0007592 ***
6 (88) 1.0773386   1.0000000 0.0058042           1.0151       0.3100407    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
par(bg = '#E4D5C9')
plot(GC_corr)

6 Reference

Kam, T. S. Global Measures of Spatial Autocorrelation. R for Geospatial Data Science and Analytics. https://r4gdsa.netlify.app/chap09.html