I have a dataset of about 77,000 points of which I want to test autocorrelation. I have tried to compute the test statistic using the testSpatialAutocorrelation tool in the DHARMa package, which uses "a simulation-based approach to create readily interpretable scaled (quantile) residuals for fitted (generalized) linear mixed models." However when I try to run the test, I run into a memory error. What is a way to easily calculate Moran's I for a large dataset?

  • Tried moran from spdep, which computes Moran's I and nothing much else? What's your adjacency list like?
    – Spacedman
    Commented Aug 1, 2018 at 6:45
  • What datatype and values you use as weigths?
    – Matte
    Commented Aug 1, 2018 at 6:48

1 Answer 1


I had this same problem. I created an R package that calculates the distance matrix on the fly, so it takes much less memory to calculate Moran's I. Its also quite fast. You can find it at github.com/mcooper/moranfast.

  • This looks interesting! Thanks for answering an old question. I'll see if this runs well with my data.
    – Douglas
    Commented Jul 29, 2020 at 18:03
  • This worked pretty well. Less than a minute on a 70,000 point dataset and about 5-6 minutes for a 300,000 dataset.
    – Douglas
    Commented Jul 29, 2020 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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