When Location Matters: The Hidden Traps of Spatial Data
Matrix Geoscience
Dr Kane Maxwell
Director & Principal Consultant
Matrix Geoscience
PhD, Geology & Machine Learning
MAusIMM (CP Geology)
Geologist and Data Scientist with more than 20 years of experience in the minerals and coal mining sector.
Director and Principal Consultant at Matrix Geoscience, applying advanced analytics and machine learning to geological and resource estimation problems.
Specialist in resource estimation, geostatistics, spatial modelling and machine learning.
What changes when observations have locations?
Spatial data are observations connected to a location or geometry.
In R, this may look like:
For this lecture, we mostly focus on spatial point/sample data.
A map is not just a picture of a table. It can reveal relationships that the table alone hides.
The same set of values can tell a very different story once we look at where they occur.
The question changes from:
what values do we have?
To:
how are those values arranged in space?
That is the starting point for spatial EDA.
Same distribution, different spatial structure: location changes what the data can tell us.
Spatial methods are useful whenever observations are sparse, locations carry information, and decisions are made between samples.
The shared structure is the same: location helps explain variation, and we often need to predict or decide between observations.
How do we store, map and analyse spatial objects?
A point dataset often starts as a normal table:
| hole | Easting | Northing | Ash |
|---|---|---|---|
| DH01 | 630120 | 7565320 | 10.4 |
| DH02 | 630540 | 7565480 | 11.2 |
After conversion to an sf object, coordinates become a geometry column with a coordinate reference system.
The geometry column lets R understand location, not just store coordinates as ordinary numbers.
sf: vector data, points, lines, polygonsggplot2: mapping with geom_sf()terra: raster and gridded datagstat: variograms, interpolation, krigingThe details change by problem, but the core workflow is usually similar.
This is the workflow the lecture keeps returning to.
holes <- readr::read_csv("data/holes.csv")
holes_sf <- sf::st_as_sf(
holes,
coords = c("Easting", "Northing"),
crs = 20355
)
ggplot2::ggplot(holes_sf) +
ggplot2::geom_sf(ggplot2::aes(colour = Ash))
vgm_emp <- gstat::variogram(Ash ~ 1, holes_sf)
vgm_fit <- gstat::fit.variogram(
vgm_emp,
gstat::vgm("Sph")
)
pred <- gstat::krige(
Ash ~ 1,
holes_sf,
newdata = grid_sf,
model = vgm_fit
)Code is not the focus today, but the spatial workflow is reproducible and programmable.
Start with distributions, relationships, sampling pattern and trend.
A dataset can have coordinates without behaving like the kind of spatial process we want to model.
Households in a suburb:
Nearby houses are not necessarily more similar in household size than far houses.
Coal quality, soil chemistry, grade, rainfall:
Nearby samples may be more similar than distant samples.
For this lecture, spatial data means more than coordinates: it means there is evidence of spatial dependence worth modelling.
For the methods in this lecture, the central assumption is:
near samples tend to be more similar than far samples.
Before modelling spatial dependence, ask:
The goal is to identify large-scale structure, sampling artefacts and possible groups/domains before choosing a spatial model.
Conventional EDA helps us understand:
The limitation is not EDA itself. The limitation is using EDA without asking where samples are, and what they are near.
A histogram or boxplot can flag a value as unusual; it cannot tell you whether it is isolated, supported by nearby samples, or part of a separate group or process.
Trend is part of EDA. If the mean changes through space, we need to recognise that broad structure before modelling local spatial dependence.
A simple trend surface is not the final spatial model.
It is a diagnostic question:
This is why EDA comes before spatial modelling.
So far, we have mostly talked about separation as distance. But two observations the same distance apart may not have the same relationship.
Euclidean distance is one definition of separation, not a universal law. Direction, barriers, networks and time can all change what “near” means.
How do we test whether near observations tend to be more similar than far observations?
At the start we made the key spatial assumption:
near samples tend to be more similar than far samples.
The variogram is one way to check and quantify that idea.
It asks:
Variogram clouds are useful for seeing scatter, short-distance discontinuities, possible outliers, boundaries or domain mixing before binning hides individual pairs.
Binning turns a noisy cloud of pairwise comparisons into an average dissimilarity trend by lag distance.
The empirical variogram is useful, but it is still noisy and only exists at chosen lag distances.
A fitted model gives us a continuous, interpretable summary of spatial dependence over distance.
The fitted model is used to:
For pairs of samples separated by approximately the same lag distance \(h\):
\[ \gamma(h) = \frac{1}{2N(h)} \sum_{(i,j) \in h} \left[ Z(s_i) - Z(s_j) \right]^2 \]
Semivariance is half the average squared difference between observations separated by approximately the same distance.
Short-range variability, measurement/support effects, or structure below sampling scale.
Approximate distance over which one sample informs another.
The variance level reached once samples are effectively no longer spatially correlated.
The range connects directly to sampling redundancy: two very close observations may add less independent information than observations separated by a meaningful fraction of the range.
Pairs come from broadly the same process or population.
The mean and variance are reasonably stable across the area being modelled.
Pairs span strong trends, distinct environments, changing populations or boundaries between processes.
The variogram may still compute, but it may not answer the right question.
A variogram can be calculated even when the assumptions are poor. The question is whether the spatial relationship it summarises is meaningful.
What changes when exploration explicitly uses location?
Spatial EDA is not only about finding extreme values. It asks how values relate to location, spatial regions and nearby samples.
Is there a broad trend, gradient or clustering pattern across the whole study area?
Examples: value maps, smoothers, spatial clustering diagnostics.
Do mapped regions, zones or environments behave differently?
Examples: compare values within spatially defined areas rather than pooling everything.
Is a sample surprising relative to nearby samples?
Example: nearest-neighbour residuals.
None of these automatically means bad data. They identify questions to investigate.
Global spatial EDA asks whether the whole map shows a broad trend, gradient, cluster or gap pattern.
Domain EDA becomes spatial when the groups are mapped regions, environments or zones. The same value may be ordinary in one domain and unusual in another.
A nearest-neighbour residual is one simple local spatial EDA method. It asks whether a value is unusual relative to the closest available spatial support, not just relative to the full dataset.
\[ r_i^{NN}=Z(s_i)-Z(s_{NN(i)}) \]
A large positive or negative value is locally surprising.
A nearest-neighbour residual is a screen for investigation, not a deletion rule.
A spatial outlier is not just an extreme value. It is a value that disagrees with its local support.
Spatial EDA is not only about measured values.
It also asks how the samples are arranged:
Sampling pattern affects what the data can tell us before we even look at the measured values.
A cluster may give detailed local information while adding little coverage elsewhere; a gap may dominate uncertainty.
Use spatial structure to estimate values between observations.
Spatial prediction algorithms try to infill between observations using the assumption:
near samples are more informative than far samples.
Common choices
The method changes, but the spatial construct is the same: neighbourhood matters.
\[ \hat Z(s_0)=\frac{\sum_i w_i Z(s_i)}{\sum_i w_i},\qquad w_i=\frac{1}{d_i^p} \]
IDW is easy to understand, but it does not estimate spatial covariance or model-based uncertainty.
The closer a sample is to the prediction point, the more influence it has. Increasing the power makes this local influence stronger.
Kriging adds a spatial covariance model, but it does not add contextual knowledge by itself.
A smooth surface can hide a bad process assumption.
Model-based uncertainty from:
Interpretive uncertainty from:
Low kriging error does not guarantee low decision risk.
Validation should match the spatial prediction task.
A random split and a spatial split are not just different sampling choices. They test different prediction tasks.
If the operational task is step-out prediction, the test set should look like step-out prediction.
Same synthetic spatial field, same IDW interpolation algorithm:
The exact numbers are not the point. The validation design defines the task.
A random 70/30 score can be optimistic or pessimistic. The deeper problem is that it may answer the wrong question.
The split should match the decision you care about.
Can I predict between nearby samples?
Random CV may be acceptable if this is truly the task.
Can I predict into nearby but less-drilled space?
Use spatial blocks or leave-area-out tests.
Can I predict into a new area or new domain?
This is the hardest problem and may not be supported by the data.
After fitting a model, is there spatial structure left behind?
After fitting a model, ask whether what remains is just random noise:
\[ Y_i=f(X_i)+\varepsilon_i \]
Spatially structured residuals do not automatically mean the model is useless. They mean the remaining errors may not be independent noise, and there may be spatial structure still left to explain.
A trend model can explain broad structure, but the residuals may still have spatial dependence.
Residual maps ask whether model errors are spatially random or spatially organised.
A residual variogram asks whether remaining errors are still spatially structured.
A useful way to think about the workflow is:
\[ \text{observed pattern} = \text{explained trend} + \text{remaining spatial structure} \]
The key question is simple: after the model, is the leftover pattern just noise, or does location still help explain it?
Use the workflow to make a spatial decision.
For the tutorial, we switch from generic examples to a synthetic mineral-exploration dataset based on the Mavis Downs deposit in Queensland.
The detailed geological context is introduced in the tutorial, when it becomes decision-relevant.
You will use the Mavis Downs case study to choose six new drill-hole locations.
Your decision must use:
The highest-uncertainty location is not always the best drill target.
SPATIAL DATA → EDA & TREND → VARIOGRAM → SPATIAL EDA → PREDICT → VALIDATE & DIAGNOSE → DECIDE
ETC5521 Lecture 10 | ddde.numbat.space