R 中的全局和空间相关性

问题描述

我有 10 年来粮农组织关于各国营养不良发生率的数据。数据包含国家代码和流行率值。现在,我想使用 R 找出全局和局部空间自相关。我是研究空间分析的新手,因此,我的概念不清楚。 首先,我使用以下代码将一年的数据可视化:

data=read.csv("C:\\Users\\User\\OneDrive\\Desktop\\Research Work\\Spatial Analysis Journal Articles\\Prevalence of Undernourishment World Data.csv")
head(data)
View(data)
sPDF <- joinCountryData2Map(data,joinCode="ISO3",nameJoinColumn="ISO3V10")
mapDevice() #create world map shaped window
mapCountryData(sPDF,nameColumnToPlot='UNDERNOURISHMENT2018')

我将单独这样做 10 年,以了解营养不良的变化。但是使用这些数据,我不知道如何制作邻域矩阵。所以,我使用了一组不同的数据和自然地球图:

# load the data 
area <- readOGR("C:\\Users\\User\\Downloads\\ne_110m_admin_0_countries")
plot(area)
countries=area
############################ FINDING NEIGHBOURS ##############################
# Load libraries
library(dplyr)
library(tidyr)
library(spdep)



# Extract the ISO codes and map them to the numeric row names
country.names <- data_frame(id = row.names(countries@data),country_iso3 = as.character(countries@data$SOV_A3),neighbor_iso3 = country_iso3)

# Determine which countries are neighbors
# Adapted from http://stackoverflow.com/a/32318128/120898
#
# spdep::poly2nb/nb2mat method is faster and more accurate than rgeos::gtouches
#
# gtouches gives wrong results; doesn't see Russia-north Korea border; is suuuuuuuper slow
#   neighbor.matrix <- gtouches(countries,byid=TRUE)
#
neighbor.list <- poly2nb(countries)
neighbor.matrix <- nb2mat(neighbor.list,style="B",zero.policy=TRUE)
colnames(neighbor.matrix) <- rownames(neighbor.matrix)

# Clean up and transform the neighbor matrix
all.neighbors <- as.data.frame(neighbor.matrix) %>%
  mutate(country = row.names(.)) %>%  # Convert row names to actual column
  gather(neighbor,present,-country) %>%  # Convert to long
  filter(present == 1) %>%  # Only look at cells with a match
  # Add country names
  left_join(select(country.names,-neighbor_iso3),by=c("country" = "id")) %>%
  left_join(select(country.names,-country_iso3),by=c("neighbor" = "id")) %>%
  filter(country_iso3 != "-99",neighbor_iso3 != "-99") %>%  # Remove missing countries
  select(contains("iso3"))  # Just get the ISO columns
head(all.neighbors)
#
#   country_iso3 neighbor_iso3
# 1          CHN           AFG
# 2          IRN           AFG
# 3          PAK           AFG
# 4          TJK           AFG
# 5          TKM           AFG
# 6          UZB           AFG

neighbor.summary <- all.neighbors %>%
  group_by(country_iso3) %>%
  summarise(num = n()) %>%
  arrange(desc(num))
neighbor.summary
#
#    country_iso3   num
#           (chr) (int)
# 1           CHN    16
# 2           RUS    14
# 3           SRB    12
# 4           BRA    10
# 5           FRA    10
# 6           COD     9
# 7           DEU     9

我在网上得到了这个代码,但对结果感到困惑。这就是我找到邻域矩阵的方式吗?但是如何将其附加到我的营养不良数据中?另外,如何使用它找到全局和空间相关性?我是否必须制作空间权重矩阵,如果需要,如何制作?

我是一名硕士生,目前没有人帮我理清这个概念。即使很少,也请提出建议。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)