r-spatial / spdep

Spatial Dependence: Weighting Schemes and Statistics
https://r-spatial.github.io/spdep/
122 stars 26 forks source link

calculating G* for permutations in localG_perm #121

Closed rosieluain closed 1 year ago

rosieluain commented 1 year ago

Hello,

I started digging into the code for localG_perm to make sure I am understanding the results correctly.

In the definition of the function permG_int, there is the line:

res_p <- lx_i/(x_star - xi)

I am calculating G, but I believe this is the equation for G (not G), which would mean that I am comparing my G value to simulated G values. Should there be in an option within permG_int to calculate G if gstari or self.included is TRUE?

Thanks! Rosie

rsbivand commented 1 year ago

Thank you for checking. I'll take a look later in the week on return to Bergen. It is quite probable that the local G* case was not tested.

rsbivand commented 1 year ago

On looking at:

https://github.com/r-spatial/spdep/blob/1ec73bd8c2847d627454e43fbbec738a594b32d6/R/lisa_perm.R#L293-L294

the first line divides the nsim simulated lagged values by the sum of x, for the G-star case, and the second divides by the sum of x minus the value of x at i, so the regular G case.

rosieluain commented 1 year ago

Thank you - that code did not match the version I was using at all. I have now updated and the code matches and results are quite different. Sorry I did not check versions first - thank you!

rsbivand commented 1 year ago

Please note that I've opened #123 because of comparison with PySAL and Geoda; the current local G-star conditional permutation does not force the inclusion of the current observation in the lagged samples but perhaps should do so. Until #123 is resolved, conditional permutation of local G-star may diverge from the other two implementations.