Hi @jlacko , I have implemented the Morans.test with `spdep::knearneigh()`

(since my data is sparse in some locations), and received a different observed Moran's I to my initial result using vedoa 's suggested approach.

Here's my code.

The first approach uses the 10 **nearest neighbours** to calculate the weights, and results in (Morans I = 0.3631838298, expected = -0.0006680027).

```
### Using the nearest neighbours approach
# extract longitude and latitude from the data (hd)
longlats <- cbind(long = hd$longitude, lat = hd$latitude) %>% as.data.frame()
nb_list <- knn2nb(knearneigh(longlats, k=10, longlat = TRUE, use_kd_tree=FALSE))
nb_weights <- nb2listw(nb_list, style="W")
spdep::moran.test(hd$price, nb_weights)
```

This second approach, uses the **inverse distance matrix**, results = (observed = 0.1266674, expected = -0.0006680027)

```
## Using distance matrix approach
# creating distance matrix
dist_matrix <- as.matrix(dist(longlats))
inv_dist_matrix <- 1/dist_matrix
diag(inv_dist_matrix) <- 0
inv_dist_matrix[is.infinite(inv_dist_matrix)] <- 0
# Morans I for distance.
ape ::Moran.I(hd$price, inv_dist_matrix)
```

My understanding is that the observed Moran's I differ since the first approach only considers 10 neighbours, whereas the second approach is considering all of the data.

Can you provide any support on which approach is preferred?

For context: I am looking to report Moran's I on residuals for different spatial models. I'm new to this so I really appreciate your support, and any advice on my approach!