1

PySAL (HH/HL/LH/LL 象限を持つもの) を使用してモランの散布図を作成しようとしていますが、そこに到達したと思いますが、理解/解釈/コードを確認したいと思います。以下のコードは、組み込みのノースカロライナ SIDS データ セットと行の標準化を使用しています。

import numpy as np
import pysal as ps
import matplotlib.pyplot as plt
import matplotlib.cm as cos

# shpdir is wherever the PySAL example data are installed
col = 'SIDR74' 
w = ps.open(os.path.join(shpdir,"sids2.gal")).read()
f = ps.open(os.path.join(shpdir,"sids2.dbf"))
y = np.array(f.by_col(col))

w.transform = 'r'

### Are these next three steps right? ###

# Calculate the spatial lag
yl  = ps.lag_spatial(w, y)

# Z-Score standardisation
yt   = (y - y.mean())/y.std()
ylt  = (yl - yl.mean())/yl.std()

# Elements of a Moran's I Scatterplot
# X-axis = z-standardised attribute values
# Y-axis = z-standardised lagged attribute values
# Quadrants = HH=1, LH=2, LL=3, HL=4
#
# So from that it follows that:
# HH == ylt > 0 and yt > 0 = 1
# LH == ylt > 0 and yt < 0 = 2
# LL == ylt < 0 and yt < 0 = 3
# HL == ylt < 0 and yt > 0 = 4

# Initialise an array with a default
# value to hold the quadrant information
quad = np.zeros(yt.shape)
quad[np.bitwise_and(ylt > 0, yt > 0)]=1 # HH
quad[np.bitwise_and(ylt > 0, yt < 0)]=2 # LH
quad[np.bitwise_and(ylt < 0, yt < 0)]=3 # LL
quad[np.bitwise_and(ylt < 0, yt > 0)]=4 # HL

plt.scatter(yt, ylt, c=quad, cmap=cms.summer)
plt.suptitle("Moran Scatterplot?")
plt.show()

それは合理的に見えるものを生成しますが、モランの I をまだ実際に計算していないことに基づいて、自分自身を結び目に考えたと思います( 経由ps.Moran_Local(...))。これはモラン散布図​​と呼ばれます...

4

0 に答える 0