# Smoothing spatial data with KNN and local G statistic

When trying to smooth spatial data, I found this very helpful tutorial regional smoothing.

There are two steps to estimate a "smoothed" value for a geographical point:

• Finding K nearest neighbors
• Calculate the local G statistics

My initial idea was only to calculate the average value with the KNN, to smooth the data across the geographical zone. But from this article, I also discovered Gettis-Ord statistic/local G statistic with the `localG` function. The author indicated that it can also smooth the spatial data.

But the locla G statistic is a zero centered variable, and the value can not directly represent an estimation of the initial variable.

Is it possible to use local G statistics to really "smooth" the data and,if so, then how?

In this example of local G official documentation of the spdep package, we can see that initial values (xyz\$val) are between 30 and 120, and the g statistic value are between -5 and 5.

## 1 Answer

The local G* values for some quantity Q have no further use in making "smoothing" maps of Q. They show how Q_i compares to the neighbours (defined however: KNN, or adjacency, or distance) and for large neighbourhoods will naturally appear smooth (because two neighbouring points will share a large fraction of neighbours). The G* statistic is used in the maps of the linked article because they want to show smoothed maps of where Q is higher or lower than average.

If you want to show smoothed maps of Q, then compute the average Q over neighbours (+self), which I showed how to do in an answer to your previous question. There's no use for G* here.

The rationale for using G* in analyses is that there is a distributional model involved, which means you can make inferences about the values like saying "this area is statistically significantly higher than the average". If you compute means of Q then its not so straightforward to say if "27" is statistically significantly higher than "20" because there's no statistical distributional model there.

If you just want a smoothed map then averaging Q over neighbours will do that. If you want to make a smoothed map based on some underlying rationale, then you need a statistical model which you can justify - for example your data as a sample from a random field with some structure - and then your smoothing has meaning beyond "looking smooth". It all depends what your big question is...