⌛ 30 minutes
<aside> 💡
Are you thinking of buying a house around Oxford? (Disclaimer: I am not a property agent and I am not selling one. I am just a poor academic complaining about the house prices.) In this practical, you will map house prices and predict them where no sale was recorded:
Oxfordshire is one of the regions with the highest house prices in the UK, so you might want to invest carefully. We use the Price Paid Data (downloaded September 2025: 1,234 Oxfordshire sales, mostly from 2024-2025 but a few back to 1997) to understand the pattern of house prices and interpolate in areas with no sales.
This is the third of five practicals in a 2-hour session. There are seven stations, numbered 0 to 6. Use the times in the table to keep on track. Tasks marked + optional can be skipped if you are short of time.
| Station | Minutes | What you do | You leave with |
|---|---|---|---|
| 0 Set up | 0–4 | Packages, house prices, Oxfordshire boundaries, CRS | hp and ox in the same CRS |
| 1 First look | 4–7 | Map the sales with tmap, find the outliers |
A map you can read |
| 2 Where to predict | 7–10 | Build a 100 × 100 grid and keep the points inside Oxfordshire | Prediction locations coop |
| 3 Closest observation | 10–14 | Voronoi polygons, spatial join, rasterise | Your first interpolated map |
| 4 IDW and nearest neighbours | 14–19 | Two gstat models |
Two more maps |
| 5 Ensemble | 19–21 | Average the three methods | A fourth map |
| 6 Which method is best? | 21–30 | 5-fold cross-validation with RMSE | A winner |
⏱️ 0–4 min
<aside> 📥
Download
</aside>
library(gstat)
library(sf)
library(terra)
library(tmap)
# Root mean squared error, used for cross-validation below
RMSE <- function(observed, predicted) sqrt(mean((observed - predicted)^2, na.rm = TRUE))
Load the hp data and convert it to an sf object.
Load the LAD_DEC_24_UK_BGC data and subset it to the five Oxfordshire districts c("Oxford", "Cherwell", "South Oxfordshire", "Vale of White Horse", "West Oxfordshire") to create ox. What is the CRS of ox?
Reproject ox to EPSG:4326 using st_transform(). (For real analyses, staying in British National Grid is better, because distances and Voronoi polygons are computed in metres rather than degrees; here we practise reprojecting.)