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