I'm having general trouble with calculating Ripley's K function values.
The following is a simple spatial point pattern, where both X and Y range from 0 to 200:
Here's its corresponding Ripley K chart in R:
The problem is, I'm completely failing to understand how does R get K(10) ~ 21000.
Here's my step by step solution:
The Ripley K function, according to "Spatial point pattern analysis of available and exploited resources", Lancaster, Downes, 2004, is defined as: $$K(r) = {n^{-2}A \sum_{i}^n \sum_{j\ne i}^n w_{ij}I_r(u_{ij})}$$
Where:
- n is the amount of points (3),
- A is the domain area (200x200 = 40000),
- w is the weighting factor, which I understand as the ratio of actual area of the sphere centered in the point i, which is contained within the bounds of the domain, to the area of a sphere centered in the point i.,
- u is the distance between points i and j,
- I is the indicator function, which should be set to 1, if u is smaller or equal to radius, and 0 otherwise.
First off, let's calculate the weights: Weight of point #1 obviously equals 1. However, #2 and #3 are near the domain edge, and since they have the same x coordinate, and aren't near the upper boundaries, they're going to be equal.
The weight will be the blue, boundary area divided by the area of the red sphere. Boundary area is equal to the area of the red sphere minus the area of the white circular segment.
The circular segment's area equals exactly 79.27, so:
$$w_{2,1}=w_{2,3}=w_{3,1}=w_{3,2}= {\pi10^2-79.27\over \pi10^2}={234.73\over 314}\approx0.75$$
Only the points #2 and #3 are within each other's radius, so the indicator function will be set to 1 only twice: between #2 and #3 and vice versa.
So the final result should be:
$$K(r)=3^{-2}\cdot40000 \cdot(1\cdot0+1\cdot0+0.75\cdot0+0.75\cdot1+0.75\cdot0+0.75\cdot1)=\\=4444.(4)\cdot1.5=6666.(6)$$
Which is vastly smaller than R's ~21000.
Also, the Kest function has a different definition of K function:
Kest(r) = (a/(n * (n-1))) * sum[i,j] I(d[i,j] <= r) e[i,j])
In that case:
$$Kest(r)=(40000/(3\cdot(3-1)))\cdot1.5=10000$$
Also wrong.
What am I doing wrong here? Is this some simple math mistake I've made somewhere, or is there something about R's Kest function that I'm missing?