Hello, I have India district shape file with 591 districts. However I have gini variable data for 393 districts for the year 2014 only in my csv file with remaining 198 districts as NA values. I have tried to merge these two files as I want to compute global Moran's statistic on my gini variable using queen contiguity. The following is my code:
## Gini data in csv file of 393 districts for the year 2014 ##
Gini2014<-read.csv("C:\Users\USER\OneDrive\Desktop\DistrictAvailableGini2014_393.csv")
colnames(Gini2014)
dim(Gini2014)
install.packages("rgdal")
library(rgdal)
install.packages("dplyr")
library(dplyr)
## Read India District shape file in R ##
Shape11<-readOGR(dsn = "C:\Users\USER\OneDrive\Desktop\IndiaShape", layer = "IND_adm5")
names(Shape11)
## Merging shape file with csv file ##
GiniMerged2014<-merge(Shape11, Gini2014, by = 'ID_2')
names(GiniMerged2014)
install.packages("spdep")
library(spdep)
GiniMerged2014 = GiniMerged2014[!is.na(GiniMerged2014$GINI),]
class(GiniMerged2014)
Create Queen contiguity matrix for India District Shape File
queen.w<-poly2nb(GiniMerged2014, row.names = GiniMerged2014$ID_2, queen = TRUE)
summary(queen.w)
queen.w[[3]]
queen.w[[393]]
str(queen.w)
queen.w1<-nb2listw(queen.w, style = "W", zero.policy = TRUE)
class(queen.w)
summary(queen.w1)
attributes(queen.w1)
is.symmetric.nb(queen.w)
*# Calculate Global Moran's I for Gini 2014 and 999-Permutation based inference ##
set.seed(1234)
GlobalMI.q<-moran.mc(GiniMerged2014$GINI, listw = nb2listw(queen.w), nsim = 999, alternative="two.sided")
GlobalMI.q
But it is showing error:
Error in nb2listw(queen.w) : Empty neighbour sets found.
Please help me out with how to address this problem.