Earth & Environmental Computing · Week 11 · Course session · 27 slides
Download HTML
Earth & Environmental Computing | Computational Methods for Earth & Environmental Science | 16-Week Course

Geostatistics and Spatial Prediction

A map between observations is a claim. Cross-validation is how the claim gets tested.

Spatial correlation · Semivariogram · IDW · Cross-validation
Week 11·Course session·Open Course Materials | Adapt for your classroom·Week 11 | Course session
Learning Objectives

By the end of this lecture, you will be able to...

  • Explain spatial autocorrelation in plain terms
  • Read nugget, sill, and range off a semivariogram
  • Write the IDW formula and predict the power parameter's effect
  • Explain leave-one-out cross-validation
Contents

Today's Lecture

01Spatial Autocorrelation
03Validation
02Inverse Distance Weighting
04Putting It to Work
Recap

Last Week in Sixty Seconds

  • Reference answers before edits; verify after every change
  • Agents draft; you own units, plausibility, and the claim
  • Disclosure in the log, explanation at the podium
  • Today: the verification instinct meets MAPS
Motivation

Eighty Probes, One Field

The problem

  • 80 soil-moisture measurements, irregular locations
  • The manager wants a value everywhere
  • Between probes: no data, only claims

The bigger picture

  • Every gridded map you have seen is an interpolation
  • Precipitation maps, soil maps, temperature surfaces
  • This week you make one, and test it
01

Spatial Autocorrelation

Near things are more alike, and the semivariogram measures how much.

01 · Spatial autocorrelation

Spatial Autocorrelation

  • Tobler (1970): near things are more related than distant things
  • Quantify it: how different are pairs, as distance grows?
  • Close pairs differ little; distant pairs differ up to a ceiling
  • 80 points make 3,160 pairs: the raw material
01 · Spatial autocorrelation

Half the Squared Difference, Binned

gamma(h) = mean of 0.5 * (z_i - z_j)^2 for pairs at distance h

z_i, z_j = values at two locations

h = separation distance (binned)

gamma = semivariance at that distance

small gamma = the pair still resembles

  • One curve turns 3,160 pair comparisons into a spatial story
01 · Spatial autocorrelation

Three Features Carry the Science

Nugget

Intercept near zero distance: measurement noise plus variation finer than the sampling.

Sill

The plateau: the field's overall variance. The resemblance budget runs out.

Range

Distance where the curve reaches the sill. Beyond it, points stop informing each other.

Pause and think

?

Your variogram's range is 3 km. Your sensors sit 5 km apart. What does the map between them rest on?

Very little: beyond the range, interpolation is barely supported
The range is directly actionable: it prices sensor spacing
02

Inverse Distance Weighting

Twelve lines that carry the whole idea.

02 · Inverse distance weighting

Inverse Distance Weighting

z_hat = sum(w_i * z_i) / sum(w_i), w_i = 1 / d_i^p

z_hat = predicted value at the target

d_i = distance to observation i

p = the power parameter

at an observation: return it exactly

  • A weighted average where distance sets the weights
02 · Inverse distance weighting

What the Power Does

p near 0

Everything weighs equally: the field mean, everywhere. Maximum smoothing.

p = 2

The convention, not a law. Balanced borrowing from neighbors.

p large

Only the nearest point counts: nearest-neighbor patches, bullseyes on the map.

The lab draws the same field at p = 1, 2, 4 and lets validation pick.

02 · Inverse distance weighting

Twelve Lines, the Whole Idea

Python

def idw(x_target, power):
    distance = np.abs(x_obs - x_target)
    if np.any(distance == 0):
        return values[np.argmin(distance)]
    weights = 1.0 / distance**power
    return np.sum(weights * values) / np.sum(weights)

for p in [0.5, 2, 8]:
    print(p, idw(5.0, p))
  • Watch the prediction drift toward the nearest observation as p grows
03

Validation

Leave one out, and what that number does and does not say.

03 · Validation

Leave-One-Out Cross-Validation

1

Remove

Take one observation out of the dataset.

2

Predict

Interpolate its location from the remaining 79.

3

Compare

Prediction versus the held-out truth.

4

Repeat

All 80 points; the RMSE is the map's honest error.

03 · Validation

What LOO Does and Does Not Say

  • Scores the method AT observation locations
  • Far from all observations, the map is extrapolating
  • LOO is silent there: mask or caveat those areas
  • The 1:1 scatter shows compression: highs under, lows over
Pause and think

?

IDW with a very high power reproduces every observation exactly. Why does it usually validate WORSE?

Fitting the points is free; predicting between them is the test
Bullseye maps memorize; smooth maps generalize (sound familiar?)
04

Putting It to Work

The full workflow, the distance matrix, and where kriging would start.

04 · Putting it to work

The Lab's Full Workflow

01

Given

80 synthetic soil-moisture points with coordinates, elevation, land cover.

02

Solve

Variogram with range estimate; IDW maps at p = 1, 2, 4; LOO RMSE for each.

03

Interpret

Pick a power with evidence; state where the map should not be trusted.

04 · Putting it to work

Everything Starts from the Distance Matrix

Python

from earthcourse.spatial import pairwise_distances_xy

D = pairwise_distances_xy(points["x_km"], points["y_km"])
D.shape          # (80, 80)
D[3, 17]         # distance between points 3 and 17
# upper triangle: 80 * 79 / 2 = 3,160 unique pairs
  • The variogram bins these pairs; IDW weights them
  • One matrix, two methods
04 · Putting it to work

What Kriging Adds (and Why We Stop Here)

  • Kriging picks weights FROM the variogram, not from a fixed power
  • It attaches an uncertainty map to the prediction map
  • The price: fitting a variogram model and heavier assumptions
  • IDW plus honest validation covers this course's needs
04 · This week's lab

Group Lab 5: Geostatistics and IDW

Lab session

  • Empirical semivariogram, range by eye
  • Three-power map comparison
  • LOO table

Studio session

  • 1:1 validation scatter with RMSE and MAE
  • max_distance sensitivity
  • Land-cover group means
Pitfalls

Where This Week Goes Wrong

  • Reading wiggles in bins with a handful of pairs
  • Confusing semivariance with variance
  • Judging maps by prettiness: detailed-looking bullseyes validate worst
  • Reporting values far outside the observed network
Bridge

Connection to Next Week

This weekNext weekBridge idea
Predict in space, validate by holdoutEnvironmental modelingPredict in time with physics, validate on the year the model never saw
Summary

Key Takeaways

  • Near things resemble; the variogram quantifies how far that lasts
  • Nugget, sill, range: noise, budget, reach
  • IDW power trades smoothness against bullseyes
  • LOO gives the map an honest error bar
Discussion · Next week: simple environmental modeling

?

Your campus installs 10 new soil sensors. Using this week's vocabulary, what one number would you estimate first to place them, and why?