Hello! I'm doing a project of spatial econometrics on r. I have a database of 81 countries which I plotted on the world map using rworldmap.
I have to create a weight matrix to proceed with the Moran diagram and the econometric evaluation, but i would like to find a way to consider only countries which contain data, otherwhise, when i try to plot the Moran diagram, it always returns me the error that the data and the weight matrix don't have the same lenght.
Here are the codes I'm using:
> worldmap <- joinCountryData2Map( databasenoNA, joinCode = "ISO3", nameJoinColumn = "code")
> 81 codes from your data successfully matched countries in the map
> 0 codes from your data failed to match with a country code in the map
> 162 codes from the map weren't represented in your data
> ### Definition of the 3 closest neighbors
> cartePPV3.knn<-knearneigh(coor,k=3)
> cartePPV3.nb<-knn2nb(cartePPV3.knn)
> ### weight matrix for the 2 closest neighbors
> PPV3.w<-nb2listw(cartePPV3.nb,style="W", zero.policy = TRUE)
> print(PPV3.w, zero.policy=TRUE)
Characteristics of weights list object:
Neighbour list object:
Number of regions: 243
Number of nonzero links: 729
Percentage nonzero weights: 1.234568
Average number of links: 3
Non-symmetric neighbours list
Weights style: W
Weights constants summary:
n nn S0 S1 S2
W 243 59049 243 133.8889 1032.444
However the object PPV3.w has lenght 243 and my data have lenght 81. Do you have any suggestion on how to overcome this problem?
Thank you very much!