モラン散布図(大域的自己相関)
各地域をその近隣の平均と比べ、モランの I、並べ替え検定、参照分布を添えます。

大域的な空間自己相関は、地図全体について 1 つの問いを立てます。似た値どうしが、偶然で説明できる以上に隣り合っているか。モラン散布図はこれを視覚的に答えます。各点は地域で、横軸はその地域自身の(標準化した)値、縦軸は近隣の平均、すなわち空間ラグです。行標準化した重みを使うと、当てはめた直線の傾きはちょうどモランの I(Moran, 1950)になります。右上と左下の象限の点は近隣に似た地域、残りの 2 つの象限には空間的な外れ値が入ります。
推測は並べ替えで行います。値を地図上で 999 回無作為に入れ替え、そのたびに I を計算し直します。挿入図は空間的無作為性のもとでの参照分布で、擬似 p 値は観測された I 以上に極端な入れ替えの割合です。
データはシミュレーションで、CIRANO による五大湖–セントローレンス川の貿易・輸送回廊のデジタルツイン GVCdtLab を背景に設定しています。ダルースとシカゴからセントローレンス湾に至る模式的な水路に沿った 276 の六角形ゾーンで、それぞれに、その海運が低水位にどれだけさらされているかを示す 0〜100 の指数を与えています。ゾーンも値もこのラボのデータや結果ではありません。重みはクイーン型隣接、統計量は esda.Moran によります。
コードおよび図中のテキストは英語です。
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
from esda.moran import Moran
from libpysal import weights
from shapely.geometry import MultiLineString, Point, Polygon
# Simulated data, set in the context of the CIRANO GVCdtLab [gvcdtlab]
# Schematic corridor: hexagonal zones within reach of the waterway, Duluth and Chicago to the Gulf
main = [(-92.1, 46.8), (-89.2, 48.4), (-84.4, 46.5), (-82.4, 44.0), (-83.0, 42.3), (-81.2, 42.2),
(-79.0, 42.9), (-79.4, 43.6), (-76.5, 44.2), (-73.6, 45.5), (-71.2, 46.8), (-68.5, 48.5),
(-64.5, 49.2)]
michigan = [(-84.0, 45.6), (-86.6, 45.4), (-87.0, 43.5), (-87.6, 41.9)]
k = np.cos(np.radians(45)) # shrink longitudes so the hexagons are regular
water = MultiLineString([[(x * k, y) for x, y in line] for line in (main, michigan)])
r, hexes = 0.3, []
for col in range(90):
for row in range(36):
cx, cy = -66.5 + 1.5 * r * col, 40.5 + np.sqrt(3) * r * (row + (col % 2) / 2)
if water.distance(Point(cx, cy)) < 0.95:
hexes.append(Polygon([(round(cx + r * np.cos(a), 6), round(cy + r * np.sin(a), 6))
for a in np.radians(range(0, 360, 60))]))
g = gpd.GeoDataFrame(geometry=hexes)
xy = np.column_stack([g.centroid.x / k, g.centroid.y]) # back to longitude, latitude
# Exposure to low water: high at shallow passages (Seaway, connecting channels, upper lakes),
# low in the deep tidal estuary, plus spatially smooth noise and one draft-limited harbour
def bump(lon, lat, s):
return np.exp(-((xy[:, 0] - lon) ** 2 + (xy[:, 1] - lat) ** 2) / (2 * s ** 2))
w = weights.Queen.from_dataframe(g, use_index=False)
w.transform = "r"
rng = np.random.default_rng(12)
noise = rng.normal(0, 1, len(g))
for _ in range(2):
noise = weights.lag_spatial(w, noise) # smooth the noise over neighbours
exposure = (35 + 30 * bump(-74.8, 45.0, 1.6) + 22 * bump(-82.7, 42.7, 1.2) + 20 * bump(-90.3, 47.6, 1.8)
- 25 * bump(-67.0, 48.8, 2.2) + 12 * noise + rng.normal(0, 4, len(g)))
exposure[np.argmin(np.hypot(xy[:, 0] + 66.0, xy[:, 1] - 49.0))] = 75 # outlier harbour
g["exposure"] = exposure.clip(0, 100).round(1)
y = g["exposure"].to_numpy()
# Moran's I with row-standardised queen weights (w above) and 999 permutations
np.random.seed(1) # esda draws its permutations from NumPy's global generator
mi = Moran(y, w, permutations=999)
z = (y - y.mean()) / y.std()
lag = weights.lag_spatial(w, z) # average of the neighbours' z-scores
fig, ax = plt.subplots(figsize=(8, 6.2))
quad = np.select([(z > 0) & (lag > 0), (z < 0) & (lag < 0)], ["#FF3B30", "#007AFF"], "#8E8E93")
ax.scatter(z, lag, s=34, c=quad, alpha=0.75, lw=0)
xs = np.array([z.min(), z.max()])
ax.plot(xs, mi.I * xs, color="#1D1D1F", lw=2, label=f"slope = Moran's I = {mi.I:.2f}")
ax.axhline(0, color="#C7C7CC", lw=1); ax.axvline(0, color="#C7C7CC", lw=1)
for (tx, ty, txt) in [(0.98, 0.97, "high, among high"), (0.02, 0.03, "low, among low"),
(0.02, 0.97, "low, among high"), (0.98, 0.03, "high, among low")]:
ax.text(tx, ty, txt, transform=ax.transAxes, ha="right" if tx > 0.5 else "left",
va="top" if ty > 0.5 else "bottom", fontsize=9, color="#6E6E73")
ax.set_xlabel("Exposure to low water, standardised (z)")
ax.set_ylabel("Neighbours' average exposure (spatial lag of z)")
ax.grid(axis="x")
ax.set_ylim(-2.7, 2.8)
ax.legend(loc="lower right", bbox_to_anchor=(1, 0.08))
# Inset: reference distribution of I under spatial randomness
ins = ax.inset_axes([0.06, 0.58, 0.32, 0.3])
ins.hist(mi.sim, bins=30, color="#C7C7CC", edgecolor="white")
ins.axvline(mi.I, color="#FF3B30", lw=2)
ins.set_title("999 random maps", fontsize=8.5, loc="left", pad=3)
ins.tick_params(labelsize=7.5); ins.set_yticks([]); ins.grid(False)
ax.set_title(f"Exposed zones sit next to exposed zones (Moran's I = {mi.I:.2f})", pad=26)
ax.text(0, 1.02, f"Permutation p = {mi.p_sim:.3f} · E[I] = {mi.EI:.3f} under randomness · "
f"queen weights, row-standardised · n = {w.n} corridor zones (simulated)",
transform=ax.transAxes, fontsize=9.5, color="#6E6E73")
plt.show()
# Moran scatterplot (global autocorrelation): the R equivalent of plot.py
# Simulated data, set in the context of the CIRANO GVCdtLab [gvcdtlab]
# R and NumPy draw different random numbers, so the values differ slightly from the Python figure.
library(sf)
library(spdep)
library(ggplot2)
set.seed(12)
# Schematic corridor: hexagonal zones within reach of the waterway, Duluth and Chicago to the Gulf
main <- rbind(c(-92.1, 46.8), c(-89.2, 48.4), c(-84.4, 46.5), c(-82.4, 44.0), c(-83.0, 42.3),
c(-81.2, 42.2), c(-79.0, 42.9), c(-79.4, 43.6), c(-76.5, 44.2), c(-73.6, 45.5),
c(-71.2, 46.8), c(-68.5, 48.5), c(-64.5, 49.2))
michigan <- rbind(c(-84.0, 45.6), c(-86.6, 45.4), c(-87.0, 43.5), c(-87.6, 41.9))
k <- cos(pi / 4) # shrink longitudes so the hexagons are regular
shrink <- function(m) cbind(m[, 1] * k, m[, 2])
water <- st_sfc(st_multilinestring(list(shrink(main), shrink(michigan))))
r <- 0.3
centres <- expand.grid(row = 0:35, col = 0:89)
centres$cx <- -66.5 + 1.5 * r * centres$col
centres$cy <- 40.5 + sqrt(3) * r * (centres$row + (centres$col %% 2) / 2)
near <- as.numeric(st_distance(st_as_sf(centres, coords = c("cx", "cy")), water)) < 0.95
centres <- centres[near, ]
hexagon <- function(cx, cy) {
a <- seq(0, 360, 60) * pi / 180
st_polygon(list(round(cbind(cx + r * cos(a), cy + r * sin(a)), 6)))
}
g <- st_sf(geometry = st_sfc(Map(hexagon, centres$cx, centres$cy)))
n <- nrow(g)
lon <- centres$cx / k # back to longitude, latitude
lat <- centres$cy
# Queen contiguity, row-standardised: the spatial lag is the average of the neighbours
w <- nb2listw(poly2nb(g, queen = TRUE), style = "W")
# Exposure to low water: high at shallow passages (Seaway, connecting channels, upper lakes),
# low in the deep tidal estuary, plus spatially smooth noise and one draft-limited harbour
bump <- function(lon0, lat0, s) exp(-((lon - lon0)^2 + (lat - lat0)^2) / (2 * s^2))
noise <- rnorm(n)
for (i in 1:2) noise <- lag.listw(w, noise) # smooth the noise over neighbours
exposure <- 35 + 30 * bump(-74.8, 45.0, 1.6) + 22 * bump(-82.7, 42.7, 1.2) +
20 * bump(-90.3, 47.6, 1.8) - 25 * bump(-67.0, 48.8, 2.2) + 12 * noise + rnorm(n, 0, 4)
exposure[which.min(sqrt((lon + 66.0)^2 + (lat - 49.0)^2))] <- 75 # outlier harbour
y <- round(pmin(pmax(exposure, 0), 100), 1)
# Moran's I with 999 permutations
mc <- moran.mc(y, w, nsim = 999)
I <- unname(mc$statistic)
sims <- mc$res[1:999] # I on the 999 shuffled maps
z <- (y - mean(y)) / sqrt(mean((y - mean(y))^2))
d <- data.frame(z = z, lag = lag.listw(w, z)) # lag: average of the neighbours' z-scores
d$quadrant <- ifelse(d$z > 0 & d$lag > 0, "high", ifelse(d$z < 0 & d$lag < 0, "low", "other"))
# Inset: reference distribution of I under spatial randomness
inset <- ggplot(data.frame(I = sims), aes(I)) +
geom_histogram(bins = 30, fill = "#C7C7CC", colour = "white") +
geom_vline(xintercept = I, colour = "#FF3B30", linewidth = 0.9) +
labs(title = "999 random maps", x = NULL, y = NULL) +
theme_minimal(base_size = 8) +
theme(panel.grid = element_blank(), axis.text.y = element_blank(),
plot.title = element_text(size = 8.5),
plot.background = element_rect(fill = "white", colour = NA))
ylim <- c(-2.7, 2.8)
at <- function(lim, share) lim[1] + share * diff(lim) # position as a share of an axis
p <- ggplot(d, aes(z, lag)) +
geom_hline(yintercept = 0, colour = "#C7C7CC") +
geom_vline(xintercept = 0, colour = "#C7C7CC") +
geom_point(aes(colour = quadrant), size = 2.2, alpha = 0.75, show.legend = FALSE) +
scale_colour_manual(values = c(high = "#FF3B30", low = "#007AFF", other = "#8E8E93")) +
geom_abline(intercept = 0, slope = I, colour = "#1D1D1F", linewidth = 0.9) +
annotate("text", x = c(Inf, -Inf, -Inf, Inf), y = c(Inf, -Inf, Inf, -Inf),
label = c("high, among high", "low, among low", "low, among high", "high, among low"),
hjust = c(1.1, -0.1, -0.1, 1.1), vjust = c(1.6, -0.8, 1.6, -0.8),
size = 3.2, colour = "#6E6E73") +
annotate("text", x = Inf, y = at(ylim, 0.22), hjust = 1.05, size = 3.5,
label = sprintf("slope = Moran's I = %.2f", I)) +
annotation_custom(ggplotGrob(inset), xmin = at(range(z), 0.04), xmax = at(range(z), 0.38),
ymin = at(ylim, 0.58), ymax = at(ylim, 0.90)) +
coord_cartesian(ylim = ylim) +
labs(title = sprintf("Exposed zones sit next to exposed zones (Moran's I = %.2f)", I),
subtitle = sprintf(paste("Permutation p = %.3f · E[I] = %.3f under randomness ·",
"queen weights, row-standardised · n = %d corridor zones (simulated)"),
mc$p.value, -1 / (n - 1), n),
x = "Exposure to low water, standardised (z)",
y = "Neighbours' average exposure (spatial lag of z)") +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(face = "bold"),
plot.subtitle = element_text(size = 8.5, colour = "#6E6E73"),
panel.grid.minor = element_blank())
print(p)
図にはオプションの PyStatlas スタイル を使用しています。同じ見た目にするには plt.style.use("pystatlas.mplstyle") を追加してください。
データの出典
- Simulated data. Simulated data with a fixed random seed, created for this example.
No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work. - CIRANO GVCdtLab, digital twin of the Great Lakes–St. Lawrence corridor. CIRANO. GVCdtLab: Digital twin of the Great Lakes–St. Lawrence trade and transport corridor (researcher in charge: T. Warin). Supported by Transport Canada's National Trade Corridors Fund; research on hydrological change, maritime traffic and trade funded by the Fonds de recherche du Québec. https://cirano.qc.ca/en/research/pole/Transport
The examples are set in the context of the lab's work; the hexagonal zones form a schematic map of the corridor and the values are simulated — they are not the lab's data, geography or results.
これらの例は統計手法を説明するためのものです。項目に別の記載がない限り数値はシミュレーションであり、図のタイトルはこのシミュレーションデータで図が示す内容を述べたものです。引用した論文の知見でも、実質的な問いに対する著者の立場でもありません。結果、背景、データについては、ここに挙げた論文を参照してください。
引用方法
PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。
Warin, T. (2026). Moran scatterplot (global autocorrelation). In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/spatial-data/moran-scatterplot/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
version = {1.1.0},
howpublished = {\url{https://warin.ca/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}空間データのその他のグラフ
空間重み付きコロプレス図
1 つの変数の地図に近隣ネットワークを重ねた図。あらゆる空間統計の土台となる構造です。
spdep::poly2nb() + plot(nb, coords)LISA クラスター地図(局所的自己相関)
クラスターと空間的外れ値がどこにあるか。各地域の局所モラン I を、並べ替えによる有意性とともに地図に示します。
spdep::localmoran_perm() / rgeoda::local_moran()空間コレログラム
近隣の次数を広げながらモランの I を求め、並べ替えによる包絡線を添えます。空間的なクラスターがどこまで及ぶかを示します。
spdep::sp.correlogram(method = "I")