0

I am trying to assess the spatial homogeneity of cells I have cultured. I have successfully managed to obtain the x,y coordinates of the cells in a square image using Image J (an image of cell nucleuses stained with DAPI). After importing the coordinates into R, I have created a ppp object using the spatstat package, and am trying to perform a Kolmogorov-Smirnov test of Complete Spatial Randomness (CSR) using the cdf.test.ppp function in spatstat. However, I can't figure out the what exactly the "covariate" in the cdf.test function is. The points (cells) don't have marks (because they are all the same cells, no difference to be noted). Putting the values "x" or "y" into the covariate argument does seem to produce expected results (the p-value of the KS test is significant for images with clustered cells and not for homogenously distributed cells), but I need an exact understanding of what this covariate means.

### Read in Coordinates from ImageJ
DATA <- read.delim("clipboard", header = F)
### The columns V6,V7 are the X,Y Coordinates
pts <- ppp(DATA$V6,DATA$V7, window = square(1946))
plot(pts) ### Checked to see if the ppp object matches the image, no problem here
cdf.test.ppp(pts, 
         test = "ks", 
         covariate = "x")

The results go as: Spatial Kolmogorov-Smirnov test of CSR in two dimensions

data: covariate ‘function(x, y) {’ evaluated at points of ‘pts’ and transformed to uniform distribution under CSR D = xxx, p-value = xxx alternative hypothesis: two-sided

I can produce desired results using covariate = "x", but I have no idea what this means and whether it is appropriate. Tried asking ChatGPT about it, and also did quite a lot of searching, but couldn't find much about it, it is only stated that the covariate should be a function of x,y or an image, without an explanation about what it is and what should be used in what situation.

  • From the documentation I'd say that, if you're using "x" as covariate, the distribution of "column sums" (total of cells per x-value) is tested against what you'd expect (a Poisson distribution [1]) if the horizontal position has no influence on cell occurence. If the test is positive for x, you can stop (= spatial distribution not random), if negative, continue with testing for y). [1] https://en.wikipedia.org/wiki/Poisson_point_process – I_O Jun 23 '23 at 06:32

1 Answers1

1

The covariate used in cdf.test can be any spatial function (any function of spatial location x,y) that you choose, including observed data, artificially-constructed functions, and the spatial coordinates themselves. Then cdf.test performs a test of the null hypothesis that the points are homogeneous, against the alternative hypothesis that the density of points depends on the chosen covariate. That is, the choice of covariate determines the alternative hypothesis (and therefore determines the kinds of deviations from the null hypothesis which the test will be good at detecting.) If you select covariate ="x" then you're performing a test of the null hypothesis of homogeneity against the alternative hypothesis that the point density is a non-constant function of the x coordinate. Usually you would do this if you suspect that the density might depend on x. If you really have no idea of the possible deviation from homogeneity, then it's conventional to try cdf.test with covariate="x" and again with covariate="y" which will at least detect many kinds of inhomogeneous spatial trend. See section 10.5.2 of the spatstat book.

Adrian Baddeley
  • 2,534
  • 1
  • 5
  • 8
  • Thank you for your comment, I looked up the book, and I think I have a rough understanding of how this works. To elaborate just a little more, I have two groups I want to compare, have n=3 samples per group, and 16 images per sample.I was planning on using the D-value of the KS test as a statistic to compare the 2 groups (using the t-test). I found the quadrat.test in the spatstat book, and this seems to yield one chi^2 value. Maybe this would serve my purpose better than having two D-values per image (one for covariate = "x" and one for covariate = "y")? – 작은과학자 Jun 30 '23 at 06:50