[R] Moran's I test for spatial autocorrelation - "spdep" package

Thayse Nery thayse.nery at hotmail.com
Thu Nov 10 09:20:49 CET 2016


Dear all,


I would like to use the Moran's I test for residual spatial autocorrelation. My dataset is in the long format [70000 , 17]  and represents a time series of Land Use and Land Cover Changes. Since I have identical x and y coordinates, I am having trouble in performing the Moran's test using the "spdep" package. I am able to perform the Moran's test if I consider only one year at time, but I need to perform the analyse for the whole dataset. My dataframe is called trainData.


Below are the steps I have done:

xy <- as.matrix(trainData [, c(5:6)])

neighb.k1 <- knn2nb(knearneigh(xy , k=2, longlat=FALSE))
distance <- max(unlist(nbdists(neighb.k1, xy, longlat=FALSE)))
summary(distance)

# Error in  assign neighbors based on a specified distance, all values = 0
#Because of this error I am not able to continue the analysis
# Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
#    0       0       0       0       0       0

gc.nb <- dnearneigh(xy, 0, distance, longlat=FALSE)

### 2. Assign weights to the areas that are linked by by creating a spatial weights matrix
MyData_neighb_w <- nb2listw(gc.nb, zero.policy=T) #

## 3. Run statistical test to examine spatial autocorrelation (Moran's I on the DV)
DV_SpatialAut <- moran.test(trainData$currentState, listw=MyData_neighb_w)

### 4. Test the Spatial autocorrelation in residuals:
## 4.1. Run the Multinomial Logit Model

FitVglm is the Model

## Calculate the weighted matrix for the residuals from multinomial logit model
MyDataFinal2 <- MyDataFinal
MyDataFinal2$mlmresid <- residuals(FitVgamx)

lm.morantest(FitVgamx, resfun=MyData_neighb_w)

Is it possible to test for residual spatial autocorrelation for a time series data with identical x and y coordinates using the "spdep" package?

Thank you in advance for any help you can provide.
Regards
Thayse Nery
PhD. Student
The University of Western Australia


	[[alternative HTML version deleted]]



More information about the R-help mailing list