How to test if values are randomly distributed in a matrix?

Hi !
I build an image from a matrix with (X,Y) coordinates and intensities (I). Do you know a function to score the randomness of the intensities distribution in this matrix. In other words, is there a statistical test or a score able to tell me if my image contains a pattern or if it is random ?
If possible I would like to avoid IA since it would be necessary to generate a lot of matrices for the learning process.
Thanks in advance for your comments !

first image : pattern
motif
second image : random
rand

Do not know of a Julia package to deliver this but, fwiw, would like to point you to the following reference that provides a test for 2D spatial randomness:

Dale Zimmerman (1993), “A Bivariate Cramer-Von Mises Type of Test For Spatial Randomness”, Journal of the Royal Statistical Society, Series C, Applied Statistics, Vol. 42, No. 1, pp. 43-54.

@rafael.guerra Thank you for your answer ! This is indeed the kind of test I search for. Unfortunately I do not have access to the full text of the article and my level in statistics might be far too low to be able to program this test by myself if it is not available in Julia :slight_smile:

Unfortunately I do not have access to the full text of the article

(looks shady from an alley)

Hey kid, did you already heard of Sci-Hub? All the cool kids are doing it.

2 Likes

Moran’s I statistic is commonly used for this in ecology. Not sure if there’s already a Julia implementation, but it shouldn’t be too hard to program yourself.

@ElOceanografo Thank you for your suggestion !
I found the Moran’s I statistic here :
https://github.com/javierbarbero/SpatialDependence.jl
As I understood from Wikipedia, this approach is very sensitive to the weights matrices.

The author also describe the local Geray test
https://javierbarbero.github.io/SpatialDependence.jl/stable/lspatialautocorrelation/#Local-Geary

Yes, Moran’s I may be sensitive to how you choose the weights, but that’s just because “spatial randomness” and “spatial pattern” could mean a variety of different things.

For instance, if your image had a large-scale pattern with a lot of white noise/static on top of it, calculating Moran’s I with a weight of 1 on nearest neighbors and 0 otherwise might appear random, but if you used weights that decay exponentially with distance, it could pick up the large-scale pattern. On the other hand, if you had an image that was, say, a mosaic of thousands of randomly-arranged smaller images, local weights would pick up the nonrandom patterns within the small images, but longer-range weights would smooth over multiple small images and only see the large-scale randomness.

That said (and I don’t know where your images come from), most images from natural processes are most autocorrelated at short scales, so a local weight matrix will probably do a pretty good job of detecting whether or not they’re random or not.

1 Like