2

I am trying to convert some spatial points into a listw object to run the moran.mc function on my data. The data are not adjacent but the points cluster in spatial patterns. Here is how I have tried to write the code:

library(sp)
library(raster)
library(spdep)

latitude <- c(56.33, 48.12, 51.13, 60.83, 52.46, 60.42, 51.07, 52.02, 52.87, , 55.27)

longitude <- c(84.58, 88.35, -55.93, -101.55, -116.19, -150.90, -89.90, 
-90.13, -89.93, -88.93)

core_locations <- cbind(longitude, latitude)

pts <- *SpatialPoints(core_locations)

I have tried two approaches to converting this into the listw; the first is to create a weights matrix, but I can't figure out how to pass this to moran.mc

dist <- pointDistance(pts, lonlat = TRUE)

weights_matrix <- 1 / dist
weights_matrix[!is.finite(weights_matrix)] <- NA
rtot <- rowSums(weights_matrix, na.rm = TRUE)
weights_matrix <- weights_matrix / rtot

The second is try to convert the points into polygons, but maybe this is just a bad idea....

p <- Polygon(pts)
ps <- Polygons(list(p),1)
sps <- SpatialPolygons(list(ps))
w <- poly2nb(sps)
ww <-  nb2listw(w)

*I have a spatial points data frame for these locations with associated attribute data for each point.

  • The Moran's statistic is not appropriate for unmarked (without associated values) points. However, you are looking for the spdep knearneigh or dnearneigh function to create an appropriate list object. Please read the spdep vignettes on package use and creating neighbors. – Jeffrey Evans Nov 23 '17 at 20:19
  • Thanks - very helpful. I have edited my original post - I should have said that I have a spatial points data frame with associated attributes for each point. – Ollie Perkins Nov 24 '17 at 13:54
5

SpatialPoints has different way to create neighbourhood list than SpatialPolygons. I faced the same problem and this link might help you out. https://stat.ethz.ch/pipermail/r-sig-geo/2009-December/007220.html

You need to create nb using function knn2nb which needs function knearneigh and then using function nb2listw to create the nb list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.