LoginSignup
1
0

More than 5 years have passed since last update.

RでLocal Moran's I 求めた話

Last updated at Posted at 2018-08-04

R で Moran's I を求める際につまづいたので、メモ。
shpファイルからじゃなくて、csvから直接位置情報を読み取った。

Global

まず、Global Moran's I に関して、以下のサイトを参考にして、shpファイルからじゃなくてcsvファイルから緯度、経度を読み込んで求めた。

以下では適当に、「空き巣ねらい」の空間的自己相関を求めた

# Moran's I
crime<-read.table("crime.csv",sep=",",header = TRUE)
coords <- matrix(0, nrow=nrow(crime), ncol=2)
coords[,1] <- crime$Latitude
coords[,2] <- crime$Longitude
crime.tri.nb <- tri2nb(coords)
moran.test(crime$あき巣ねらい,nb2listw(crime.tri.nb,style="W"))

こんなかんじでやったらできた。

Local

適当に、

localmoran(crime$あき巣ねらい,nb2listw(crime.tri.nb,style="W"))

って書いたら、結果がでてきた。関数の中身は、Globalの場合と同じで良い。

結果が煩雑で見にくいので、この値を元に地図にプロットするのが良さげ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0