楼主: 明日月明
5258 3

[问答] 空间计量Moran计算 R程序问题请教 [推广有奖]

  • 0关注
  • 0粉丝

高中生

22%

还不是VIP/贵宾

-

威望
0
论坛币
80 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
8928 点
帖子
9
精华
0
在线时间
36 小时
注册时间
2012-3-30
最后登录
2018-3-12

楼主
明日月明 发表于 2015-4-26 10:54:43 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
在计算Moran指数时,先通过Geoda建立的空间权重矩阵并生成了.GWT格式的文件。
在R中输入语句后,提示:
Error in moran(x, xdw, length(xgwt), Szero(xdw)) :
  objects of different length

求问各位大神如何解决
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:moran 空间计量 R程序 RAN Different 程序 空间

沙发
nieqiang110 学生认证  发表于 2015-4-26 16:18:44
NOTE: This page has been delinked.  It is no longer being maintained, and information on this page may be out of date. Because this page has been delinked, we cannot not answer questions regarding this page.
R FAQ:
How can I calculate Moran's I in R?
Moran's I is a measure of spatial autocorrelation--how related the values of a variable are based on the locations where they were measured.  Using functions in the ape library, we can calculate Moran's I in R.  To download and load this library, enter install.packages("ape") and then library(ape).

Let's look at an example. Our dataset, ozone, contains ozone measurements from thirty-two locations in the Los Angeles area aggregated over one month. The dataset includes the station number (Station), the latitude and longitude of the station (Lat and Lon), and the average of the highest eight hour daily averages (Av8top). This data, and other spatial datasets, can be downloaded from the University of Illinois' Spatial Analysis Lab. We can look at a summary of our location variables to see the range of locations under consideration.
ozone<-read.table("http://www.ats.ucla.edu/stat/r/faq/ozone.csv", sep=",", header=T)
head(ozone, n=10)

   Station   Av8top      Lat       Lon
1       60 7.225806 34.13583 -117.9236
2       69 5.899194 34.17611 -118.3153
3       72 4.052885 33.82361 -118.1875
4       74 7.181452 34.19944 -118.5347
5       75 6.076613 34.06694 -117.7514
6       84 3.157258 33.92917 -118.2097
7       85 5.201613 34.01500 -118.0597
8       87 4.717742 34.06722 -118.2264
9       88 6.532258 34.08333 -118.1069
10      89 7.540323 34.38750 -118.5347

To calculate Moran's I, we will need to generate a matrix of inverse distance weights.  In the matrix, entries for pairs of points that are close together are higher than for pairs of points that are far apart.  For simplicity, we will treat the latitude and longitude as values on a plane rather than on a sphere--our locations are close together and far from the poles. When using latitude and longitude coordinates from more distant locations, it's wise to calculate distances based on spherical coordinates (the geosphere package can be used).

We can first generate a distance matrix, then take inverse of the matrix values and replace the diagonal entries with zero:
ozone.dists <- as.matrix(dist(cbind(ozone$Lon, ozone$Lat)))

ozone.dists.inv <- 1/ozone.dists
diag(ozone.dists.inv) <- 0
       
ozone.dists.inv[1:5, 1:5]
         1        2        3        4        5
1 0.000000 2.539795 2.446165 1.627570 5.391160
2 2.539795 0.000000 2.667061 4.531428 1.741071
3 2.446165 2.667061 0.000000 1.954357 2.002389
4 1.627570 4.531428 1.954357 0.000000 1.258716
5 5.391160 1.741071 2.002389 1.258716 0.000000

We have created a matrix where each off-diagonal entry [i, j] in the matrix is equal to 1/(distance between point i and point j).  Note that this is just one of several ways in which we can calculate an inverse distance matrix.  This is the formulation used by Stata.  In SAS, inverse distance matrices have entries equal to 1/(1+ distance between point i and point j) and there are numerous scaling options available.

We can now calculate Moran's I using the command Moran.I.  
Moran.I(ozone$Av8top, ozone.dists.inv)

$observed
[1] 0.2265501

$expected
[1] -0.03225806

$sd
[1] 0.03431138

$p.value
[1] 4.596323e-14


Based on these results, we can reject the null hypothesis that there is zero spatial autocorrelation present in the variable Av8top at alpha = .05.

Alternatively, one could use a binary distance matrix.  This might be used in looking at networking problems where two points are either connected or not connected.  In this example, we can choose a distance d such that pairs of points with distance less than d are considered connected and pairs with distance greater than d are not and use this weights matrix to calculate Moran's I.  The code below does this for d = .75.  
ozone.dists.bin <- (ozone.dists > 0 & ozone.dists <= .75)
Moran.I(ozone$Av8top, ozone.dists.bin)


$observed
[1] 0.2045738

$expected
[1] -0.03225806

$sd
[1] 0.04771132

$p.value
[1] 6.910876e-07

藤椅
nieqiang110 学生认证  发表于 2015-4-26 16:19:17
http://www.ats.ucla.edu/stat/r/faq/morans_i.htm

板凳
xjmayuan123 发表于 2016-5-19 18:00:26
请问您的该问题解决了么?遇到同样问题,求解答!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 11:17