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

Xiang Ye x|@ngye @end|ng |rom bu||@|o@edu
Thu Dec 21 07:39:36 CET 2023


Dear Prof. Bivand,

Thank you very much for your crystal-clear answer, my question is well resolved. And thank you for the recommendation of Baddeley, Rubak & Turner (2015), I will read it.

I agree with your comment on the impact of the study area on the statistic itself. As long as the study area/observing window is large enough, any point pattern is clustered. (But it also gives me the sense that, an 'optimal' or 'characteristic' study area may exist for a given point pattern, with the cost that such an 'optimal' study area will be sensitive to the location of a few peripheral points.)

Stay warm, and happy holidays!

Ҷ�� YE, Xiang
THINKING SPATIALLY<http://www.linkedin.com/in/spatialyexiang>.
Ph.D. in Spatial Statistics
________________________________
������: Roger Bivand <Roger.Bivand using nhh.no>
����ʱ��: 2023��12��20�� 19:44
�ռ���: r-sig-geo using r-project.org <r-sig-geo using r-project.org>; Xiang Ye <xiangye using buffalo.edu>
����: Re: How to interpret the "residual" values in plot(quadrat.test(some_data_set))

This is where the open source code matters.

The code here at https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fspatstat%2Fspatstat.explore%2Fblob%2F52a94f6a90314c593472f7b1a80da36e7a99585a%2FR%2Fquadrattest.R%23L286&data=05%7C02%7Cxiangye%40buffalo.edu%7C17b351f8cc724ee5992f08dc0150fe95%7C96464a8af8ed40b199e25f6b50a20250%7C0%7C0%7C638386694590839576%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=rGm5g7sP8BsvEoDG0OlOni8lzPLStxZAow7lz%2ByqeOY%3D&reserved=0<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<https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fspatialyexiang&data=05%7C02%7Cxiangye%40buffalo.edu%7C17b351f8cc724ee5992f08dc0150fe95%7C96464a8af8ed40b199e25f6b50a20250%7C0%7C0%7C638386694590839576%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hrmoR5JjWOoBBG%2Bv1RIAzOnrKEu6qvepZUmPFMTo5%2B8%3D&reserved=0<http://www.linkedin.com/in/spatialyexiang>>.
Ph.D. in Spatial Statistics

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list