Skip to article frontmatterSkip to article content

Learning purpose: Study a fixed window of synthetic observations, compare quadrat counts and nearest-neighbour distances. A geographical study window must be specified independently of its observed points.

Format: guided learner notebook. Part 1 supplies the conceptual background; try the exercises before consulting the linked solution.

Data: entirely synthetic, generated with a fixed seed. Software: NumPy, Matplotlib and relevant SciPy/scikit-learn functions. No private course datasets or Google Drive required.

After you attempt the exercises: Open the complete solution notebook on GitHub.

1. Generate and inspect the observations

import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import cKDTree
rng = np.random.default_rng(5230)
window = (0., 1000., 0., 1000.)  # x min/max, y min/max in fictional metres
observed = np.vstack([rng.normal((300, 300), 60, size=(75, 2)),
                      rng.normal((720, 700), 65, size=(75, 2))])
observed = np.clip(observed, 0, 1000)
fig, ax = plt.subplots()
ax.scatter(observed[:, 0], observed[:, 1], s=9)
ax.set(xlim=(0, 1000), ylim=(0, 1000), aspect="equal", title="Observed synthetic events")
plt.show()
print("Points:", len(observed))

2. Analyse and evaluate

First, estimate where most observations occur. Then ask whether the distribution is consistent with uniform CSR within the fixed window.

TODO 1 — quadrats. Use a 5×5 grid with np.histogram2d. Report the range of quadrat counts; explain why a few high counts alone cannot establish a statistically significant departure from CSR.

# TODO: compute a 5×5 count matrix for observed[:,0] and observed[:,1].

TODO 2 — NNA. Find each point’s nearest other neighbour and compute Clark–Evans R using the uncorrected infinite-plane CSR expectation. Explain the edge-effect limitation.

# TODO: query cKDTree(...).query(observed, k=2); compute R.

3. Interpretation

An R below 1 is descriptive evidence of short distances relative to the infinite-plane expectation, not by itself a valid significance test. Boundary effects and the chosen observation window matter.

Write your own interpretation: How might parameter selection or observation design change the result?

Check your understanding

Try the exercises and write down your interpretation before comparing your work with the complete answers.

Open the worked solution