# Week 11 Hot spot analysis
###### tags: `GlobalAnalysisMethods`
> 熱區分析的空間統計方法
* For polygon data:
1. Local moran's I index
2. Local Gi*
## Local Moran's I


### 顯著性檢定

### LISA
Cluster of similar values:
* HH: 自己跟周圍都很高
* LL: 自己跟周圍都很低
---
Cluster of dissimilar values:
* LH: 自己低但周圍很高
* HL: 自己高但周圍很低
高於平均或低於平均-->區分冷熱區
Moran's I 得到的值是顯示與鄰居的相似程度
## 2. Local G
> Gi* 計算鄰居是包含自己的

### 顯著性檢定

## R-code 實作
* LISA
```r=
# 定義鄰近
tw.nb = poly2nb(TW)
# 建立鄰近表
tw.nb.w = nb2listw(tw.nb, zero.policy = T)
# 區域空間自相關運算
LISA = localmoran(old, tw.nb.w, zero.policy, alternative = "two.sided")
# 區分顏色
diff = old - mean(old) # 看自己和平均比較起來算是H還是L
z = LISA[,4]
quad = c()
quad[diff>0 & z>0] = 1 # HH
quad[diff<0 & z>0] = 2 # LL
quad[diff>0 & z<0] = 3 # HL
quad[diff<0 & z<0] = 4 # LH
quad[LISA[,5]>0.05] = 5 # 不顯著,雙尾用0.05比較
# 繪圖
colors = c("red", "blue", "lightpink", "skyblue2", rgb(.95,.95,.95))
plot(TW, border = "grey", col = colors[quad], main = "LISA Map")
legend("bottomright", legend = c("HH", "LL", "HL", "LH", "NS"), fill = colors, bty = "n", cex = 0.7, y.intersp = 1, x.intersp = 1)
```
* Gi*
```r=
tw.nb = poly2nb(TW)
tw.nb.in = include.self(tw.nb)
tw.nb.w.in = nb2listw(tw.nb.in)
Gi = localG(old, tw.nb.w.in)
LG = as.vector(Gi)
# 區分顏色
quad = c()
quad[LG >= 1.645] = 1 # cluster
quad[LG < 1.645] = 2 # non-cluster
# 繪圖
colors = c("red", "lightgray")
plot(TW, border = "grey", col = colors[quad], main = "Cluster Map")
legend("bottomright", c("Cluster","Non-cluster"), fill = colors, bty = "n", cex = 0.7, y.intersp = 1, x.intersp = 1)
```