# 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.

first image : pattern

second image : random

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

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

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 :

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