# Generating a small random graph
set.seed(123)
graph <- rgraph_ba(t = 4)
w <- sna::geodist(as.matrix(w))
x <- rnorm(5)
# Computing Moran's I
moran(x, w)
# Comparing with the ape's package version
moran(x, w/rowSums(as.array(w)))
ape::Moran.I(x, w)
Run the code above in your browser using DataLab