[R-sig-Geo] How to interpret the "residual" values in plot(quadrat.test(some_data_set))

Roger Bivand Roger@B|v@nd @end|ng |rom nhh@no
Wed Dec 20 12:44:12 CET 2023


This is where the open source code matters.

The code here at https://github.com/spatstat/spatstat.explore/blob/52a94f6a90314c593472f7b1a80da36e7a99585a/R/quadrattest.R#L286 shows:

residuals = (OBS - EXP)/sqrt(EXP)

and:

> all.equal((a$observed - a$expected)/sqrt(a$expected), a$residuals)
[1] TRUE

This is also documented in the big Spatial Point Patterns book, Baddeley, Rubak & Turner (2015), p. 166, described as Pearson residuals.

The definition you refer to is:

(a$observed - a$expected)^2/a$expected

which is the vector summed to perform the basic Chi-square test.

?quadrat.test and the book section are worth reading, especially the criticism of quadrat tests in general, as they are badly affected by the number and position of the chosen rectangles, just as histograms are badly affected by the positioning of the breaks.

Hope this clarifies,

Roger

--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
Roger.Bivand using nhh.no

________________________________________
From: R-sig-Geo <r-sig-geo-bounces using r-project.org> on behalf of Xiang Ye via R-sig-Geo <r-sig-geo using r-project.org>
Sent: 20 December 2023 06:56
To: r-sig-geo using r-project.org
Subject: [R-sig-Geo] How to interpret the "residual" values in plot(quadrat.test(some_data_set))

Dear community,

I am recently digging into the quadrat test in library(spatstat). It is known that if you plot the result of quadrat.test, you will get three numbers in each grid: the observed number of points, the expected number of points assuming CSR holds, and the "residual".

For example:
library(spatstat)
plot(ponderosa, pch=16, cex=0.5, cols='grey50')
quadrat.test(ponderosa, 3, 4) -> a
plot(a, add=TRUE)

And you get:
[cid:16f82480-6395-4498-9ce8-742cbbd41660]

According to what I learnt about the quadrat test (Rogersson and Yamada 2005, p. 48), and the help document from quadrat.test, I assume the "residual" should be (observed-expected)^2/expected. However, the numbers in the above figure does not support my guess. Take the first grid as an example, in this grid 15 points are observed, with an expectation of 9. So the "residual" should be (15-9)^2/9=4, rather than 2.

Moreover, if you look at the 2nd, 3rd, and 5th grids, you will find that when the observed number of points is deviating from the expectation, the "residual" grows linearly rather than squarely, indicating there is no squared term in the numerator when calculating the "residual", letting alone the sum of them does not agree with the reported chi-squared statistic.

I will be grateful if someone can shed some light on how this "residual" calculated.
Thanks in advance!

叶翔 YE, Xiang
THINKING SPATIALLY<http://www.linkedin.com/in/spatialyexiang>.
Ph.D. in Spatial Statistics



More information about the R-sig-Geo mailing list