Exercise 0-A. Spatial Dependence Before Anything Else
Part 0. Fundamentals and Their Failure Modes
Part 0. Fundamentals and Their Failure Modes
GeoAI Risks discusses hot spot maps, interpolated surfaces and spatial aggregation as concepts and leaves the statistics behind them to its reader. A reader trained in geospatial intelligence brings that background, and the broader readership this book deserves often does not. Part 0 closes the gap by running the fundamental methods, showing what each one assumes, and demonstrating what each produces when its assumptions do not hold. The treatment stays deliberately practical, since the objective is a reader who can state what a method assumed and check whether the assumption held.
The danger the book describes throughout depends on this material. Advanced spatial statistics now arrive as a menu item in software that asks the user for a field name and nothing else, and the tool returns a confident answer whether or not the data can support one. A user who cannot state what the tool assumed cannot tell a real cluster from an artifact of the weights matrix, and the resulting map carries the same authority either way. The exercises in this Part put numbers on how large that difference can be, which is the only form of the argument that survives contact with a skeptical reader.
Instructors whose students have completed a spatial statistics course may skip Part 0 entirely. Every later Part opens with a short fundamentals block naming the methods it puts in play and their failure modes, so a class that skips Part 0 still meets the assumptions of the models it uses. Nothing in Parts I through VI depends on Part 0 having been assigned. Instructors uncertain about their students should assign Exercise 0-A alone, since it stands on its own and it exposes the misconception that most reliably damages later work.
| At a glance | |
|---|---|
| Textbook sections | sections 2.3, 2.8, 4.2, 5.6.2, 8.14, 15.8, and the fundamentals behind the hot spot maps the book discusses from Chapter 4 onward |
| Fundamentals covered | spatial weights matrices, global Moran's I, permutation inference, local Moran's I and cluster types, Getis-Ord Gi*, multiple comparisons |
| Technical demand | Tier 1 and Tier 2 required, Tier 3 optional. Python with pandas, numpy, scipy and matplotlib. No GIS, no key, no account |
| Effort | three hours including the write up |
| Prerequisites | none |
Overview
A hot spot analysis answers the question of where values cluster, and it answers that question whether or not the data clusters at all. Software that presents Getis-Ord Gi* as a menu item accepts a field name, applies a default spatial weights matrix, tests every unit at the conventional threshold, and returns a map covered in red and blue polygons. Nothing in that sequence asks whether the pattern is clustered, which weights matrix suits the phenomenon, or how many of the significant units would appear by chance in data with no structure. This exercise runs all three checks and reports what each one costs.
The exercise works on Mississippi census tract poverty, which is genuinely clustered, and on three synthetic fields whose answers are known in advance. Synthetic data matters here because a student who only ever analyzes real data can never distinguish a method that works from a method that agrees with their expectations. A random field with no clustering in it, analyzed by the default procedure, produces significant hot spots, and seeing that happen is worth more than reading that it can. The three synthetic fields are generated in code from a stated seed, so a student can change their parameters and watch a known answer move.
Figure, three panels. The synthetic random, checkerboard and clustered fields rendered as lattices, with the Moran's I value printed on each.
The closing step is the handoff. The program writes every statistic it computed into a table a person can open, and writes a second file listing the eight decisions it made without being asked. The student answers the questions in that second file, which is the work the machine could not do. Answering them requires the evidence gathered in the preceding steps, so a student who skipped the parameter changes will find the final step impossible to complete honestly.
Step by step
- Run the exercise. Tier 1. Change to the toolkit folder inside GeoAI_Exercises and type python exercise_0a.py. The program prints five blocks, writes one figure into figures and writes two handoff files into handoff. Read the printed report once before you look at the map, because the map is persuasive and the numbers are not, and reading them in that order guards against believing the picture.
- Record the weights matrix sensitivity. Tier 1. Block 1 computes global Moran's I on the same tract poverty values under five spatial weights schemes: rook contiguity, queen contiguity, four and eight nearest neighbors, and a forty kilometer distance band. Record all five coefficients, the average neighbor count under each, and the verdict each returns. Then answer two questions in writing. Does the verdict change across the five schemes, and does the magnitude change? Those are different questions with different answers here, and conflating them is the error the step exists to catch.

- Record what happens on data whose answer you know. Tier 1. Block 2 analyzes three synthetic fields on a thirty by thirty lattice. The first is spatially independent noise, the second is a checkerboard that alternates high and low, and the third is smoothed noise carrying genuine positive autocorrelation. Record the rook and queen coefficients for each field, the count of units Gi* flags at the conventional threshold, and the count that survives a false discovery correction. The checkerboard row is the one to study, because the two weights schemes disagree about it completely and only one of them is right.
- Record the cost of the correction on real data. Tier 1. Block 3 runs Gi* on the Mississippi tracts under queen contiguity and reports the count of significant units before and after a Benjamini-Hochberg false discovery correction. Record both counts and the difference. Then look at the second and third panels of exercise_0a_clusters.png and write one paragraph describing what a decision maker shown only the middle panel would conclude, and what the same decision maker shown only the right panel would conclude.
- Record the cluster types. Tier 1. Block 4 reports local Moran's I cluster membership in four categories, being high values surrounded by high values, low surrounded by low, and the two mixed cases. Record all four counts and the count of tracts reaching no significance. Then explain what a high value surrounded by low values means substantively, and why a map that shows only the hot spots and hides that category is misleading about the geography.
- Change the weights and rerun. Tier 2. Open exercise_0a.py and find the line where the Gi* and local Moran calls select
Ws["queen"]. Change that toWs["rook"], then toWs["knn8"], rerunning after each change. Record the significant counts under all three, and state which of the three you would defend to a reviewer and why. A phenomenon that travels along roads and rivers has different neighbors from one that spreads across shared borders, and the weights matrix is where that belief gets encoded.
- Read the code. Tier 1. The exercise names one block for annotation, being the function
build_weightsin spatial_stats.py, and specifically the branch that builds contiguity from shared polygon vertices. Write a plain language annotation of that branch, stating what it consumes, what it produces, and what would change if the thresholdneedwere set to 1 in place of 2. Then explain why comparing floating point coordinates for exact equality can miss neighbors, and use the average neighbor counts from Block 1 to judge whether the shipped GeoJSON preserved the shared vertices the technique needs.
- Complete the handoff. Tier 1. Open exercise_0a_decisions.json from the handoff folder. It lists eight decisions the program made without asking you, and five questions a person must answer before the map is published. Answer all five in writing, using the evidence from Steps 2 through 6. Then add a sixth question of your own that the program failed to raise, and explain why it belongs on the list.
- Put the assistant to work. Tier 3, optional, ten points. Open a fresh session with any assistant and give it this, with no other context.
I have a table of Mississippi census tracts with a poverty percentage.
Run a hot spot analysis and tell me where the poverty hot spots are.
Record what it produced, then record what it did not ask you. Specifically, did it choose a spatial weights matrix and tell you which one, did it test whether the pattern is clustered before looking for clusters, and did it mention multiple comparisons at all. Then write one paragraph on which of those three omissions would have been hardest for a non-specialist to notice in the delivered result.
Key takeaways
A hot spot analysis rests on three decisions, and commercial software supplies a default for each that runs whether or not the user ever reads it. The weights matrix encodes a belief about how the phenomenon travels, the significance threshold governs how much evidence a cluster needs, and the multiple comparison correction determines how many of the findings survive contact with the number of tests performed. A user who states none of the three has still made all three. The distinction that matters is between a decision taken deliberately and a decision inherited from a default, because only the first can be defended to a reviewer.
Global pattern tests and local cluster tests answer different questions and neither substitutes for the other. A globally random field can hold one real local cluster, so a non-significant global statistic is no absolute prohibition on local analysis. What it does is shift the burden, because a local cluster found inside a globally random field needs stronger evidence and an explanation for its existence, and the correction becomes mandatory in that setting. Students should carry that formulation into every later chapter, since the same asymmetry between global and local evidence recurs whenever a system reports local findings.
Local Moran cluster map beside Getis-Ord before and after a false discovery correction. The middle and right panels differ by one methodological choice.
The weights matrix can change the answer completely and the checkerboard proves it. Two schemes that both look reasonable return different verdicts on identical data, which means the analyst chose the answer at the moment they accepted a default. That result belongs beside the modifiable areal unit problem in Chapter 4, since both describe a representational decision that determines the finding while remaining invisible in the output. The two failures also compound, because an analyst who has chosen a geography has already constrained which weights matrices are even available.
Correction is not a formality. The two counts recorded in Step 4 measure how much of the apparent finding came from testing one hypothesis per tract. The uncorrected map is the one most practitioners produce and the one most decision makers see. Correcting it costs a single function call and changes nothing else in the workflow, which makes the omission difficult to defend once it has been pointed out.
Questions
- Compare how the verdict and the coefficient behave across the five weights schemes in Block 1, explain what you find, and state a circumstance in which the verdict would change.
- Compare the checkerboard coefficients under rook and queen contiguity, explain the geometry that produces the difference, and state which of the two schemes you would use to detect a dispersed pattern.
- A colleague argues that applying a false discovery correction is too conservative because it hides real clusters. Using the synthetic results in Block 2, state what the correction cost on the genuinely clustered field and what it cost on the random field, then answer the colleague.
- Section 8.14 distinguishes human-in-the-loop from meaningful human authority, which requires authority to disagree, sufficient information, time, competence, alternative evidence and institutional protection. Using the handoff file from Step 8, state which of the eight machine decisions a person could meaningfully override in a real workflow and which would require rebuilding the analysis.
Challenge, optional, up to ten extra credit points
The distance band scheme in Block 1 uses forty kilometers, which nobody justified. Rerun the analysis across bands from ten to one hundred kilometers in ten kilometer steps, plot the coefficient against the band width, and identify the distance at which the statistic stops changing materially. State what that distance means about the geographic scale of the process, and whether it matches the scale at which poverty policy is actually administered in Mississippi. A mismatch between the two is itself a finding, since a process operating at one scale governed by a program operating at another will produce persistent allocation errors.