pysal / pointpats

Planar Point Pattern Analysis in PySAL
https://pysal.org/pointpats/
BSD 3-Clause "New" or "Revised" License
83 stars 26 forks source link

(BUG) L function and its Simulation Envelope under the null (CSR) not close to 0 #44

Closed weikang9009 closed 4 years ago

weikang9009 commented 4 years ago

This issue is raised by a user of pointpats - Wei Xie.

The Simulation Envelope under the null of CSR built for the L function is nowhere near 0 (see the following figure), which is not right based on its definition. image

ljwolf commented 4 years ago

I think the equation is implemented incorrectly.. It should read:

    support, kestimate = _k(pp, intervals, dmin, dmax, d).T
    lestimate = np.sqrt(kestimate / np.pi)
    return np.column_stack((support, lestimate))

This is the form on wikipeda and in spatstats.

jGaboardi commented 4 years ago

FWIW, this is the formulation found in O’Sullivan and Unwin (2010). I was going to add it into spaghetti before realizing it is not well-suited for networks.

weikang9009 commented 4 years ago

I think the equation is implemented incorrectly.. It should read:

    support, kestimate = _k(pp, intervals, dmin, dmax, d).T
    lestimate = np.sqrt(kestimate / np.pi)
    return np.column_stack((support, lestimate))

This is the form on wikipeda and in spatstats.

I do not see a major difference between these two implementations - the only difference is that your implementation does not deduct the distance from the "normalized" L function. The current implementation in pointpats follows another routine (as pointed out by @jGaboardi ) and is also shown in the Wikipedia: image I think the main purpose is to make the interpretation more intuitive: under the null, the L function follows a horizontal line at 0.

We have found the bug and Serge has fixed it in https://github.com/pysal/pointpats/pull/45. Another bug is introduced with this PR and it is supposed to be fixed in https://github.com/pysal/pointpats/pull/46. I should have closed this issue (have been waiting for the close of the https://github.com/pysal/pointpats/pull/46) - sorry if this induces any confusion.

ljwolf commented 4 years ago

I see! Feel free to close this then!

the only difference...

Right. The plotting correction is not the L function itself.

I understand the L with this adjustment is interpreted like the J but centered on zero.

I think this needs to be documented + given an option.

weikang9009 commented 4 years ago

The equation is given in the example notebook for distance statistics. I will add the missing equations for the distance functions to the inline docstrings. Thanks for the suggestion.