Introduction to Spatial Statistics
Many natural processes take place in space
Spatial data are data which have any form of geographical information attached to them.
The emergence of modelling frameworks for spatial data in areas such as epidemiology, ecology and environmental sciences has been facilitated by the rise of new technologies.
Large amounts of data collected in space:
increased resolution \(\rightarrow\) large, complex datasets
\(\rightarrow\) complex spatial models required
challenges:
We will see that inlabru can help…
Tobler’s first law of geography states that:
Everything is related to everything else, but near things are more related than distant things”
Standard models assume independent observations
Spatial data are often not independent
Two nearby observations are similar \(\rightarrow\) not providing independent information
\(\rightarrow\) spuriously tight confidence intervals
\(\rightarrow\) wrong inference and wrong conclusions
Spatial models include special components to explicitly model dependence.
Inference and prediction are essential in statistics, but spatial dependency can complicate statistical analysis.
Understanding how spatial dependence structures impact on our analyses is crucial.
Spatial dependence may be caused by:
Dependence relationships need to represented in the model –- which observation is related to which other observations?
inlabru) much faster…The overall goal of any piece of spatial analysis is to understand the spatial patterns in the data. This could involve:
Estimating differences in mean, variance, or some other summary statistic across space.
Predicting the value at some unobserved location.
Identifying hotspots with high (or low) values compared to the rest of the region.
aims also vary with different types of spatial data…
Discrete space:
Continuous space:
Geostatistical (geo-referenced) data
Spatial point pattern data
The components of the models we will cover are used to reflect spatial dependence structures in discrete and continuous space.
We can distinguish three types of spatial data structures
Areal data
Geostatistical data
Point pattern data
We can distinguish three types of spatial data structures
Areal data
In areal data our measurements are summarised across a set of discrete, non-overlapping spatial units.
Geostatistical data
Point pattern data
We can distinguish three types of spatial data structures
Areal data
Geostatistical data
In geostatistical data, measurements of a continuous process are taken at a set of fixed locations.
Point pattern data
We can distinguish three types of spatial data structures
Areal data
Geostatistical data
Point pattern data
In point pattern data we record the locations where events occur (e.g. trees in a forest, earthquakes) and the coordinates of such occurrences are our data.
Many public health studies use data aggregated over groups rather than data on individuals - often this is for privacy reasons, but it may also be for convenience.
Respiratory hospitalisations in Glasgow
Observed response(s): Measurement associated with or areal unit
here: spatial structure represented by Gaussian Markov random field (GMRF)
In this example we model the numbers of hospitalisations due to respiratory disease in the Greater Glasgow and Clyde health board
In epidemiology, disease risk is assessed using Standardized Mortality Ratios (SMR):
\[ SMR_i = \dfrac{Y_i}{E_i} \]
Observed response(s): measurements at given locations in continuous space
here: spatial structure represented by Gaussian random field; approximated by a continuously indexed Gauss Markov random field
Data on the Pacific Cod (Gadus macrocephalus) from a trawl survey in Queen Charlotte Sound.
Observed response(s): x,y coordinates (sometimes also additional measurements; “marks”) modelled by a random variable, a spatial point process characterised by intensity \(\lambda(s) \in \mathbb{R}^2\)
here: intensity is a Gaussian random field; approximated by a continuously indexed Gauss Markov random field
locations of forest fires in the Castilla-La Mancha region of Spain between 1998 and 2007
citizen science records of the ringlet butterfly in Scotland’s Cairngorms National Park
inlabruinlabru provides support for sf (Pebesma, 2018) and terra (Hijmans, 2024) spatial data structures.
sf and terra objects can be passed as data and covariates directly to bru_obs() and bru() functions.In this course we will
Understand how eval_spatial() methods are used to extract information from spatial data objects.
Define model components based on spatial information provided in the geometry column of the sf data objects.
Learn about the bru_mapper() mapper system for specifying SPDE random effect.
Use Spatial objects for prediction using predict() and generate().
Fit log-Gaussian Cox process using (i) sf points object to describe the locations of the observed points and (ii) sf polygon object to define the observation window
First, we will cover some of the basics of working sf and terra objects.
sf and terraModern, efficient framework for working with spatial data.
Our spatial analysis begins with how the data are stored:
sf (Simple Features ) package → vector data. Discrete features with exact coordinates: points (a survey location), lines (a transect), polygons (a health board, a national park).
It can also be used to read vector data stored as a shapefiles.
terra → raster data. A continuous surface(s) split into a regular grid, each holding a value: elevation, sea depth, temperature.
sf: vector data as a data frameThe key idea: an sf object is a data frame — with one extra geometry column.
Three functions do most of the work:
st_read() — read a shapefile (.shp) from diskst_as_sf() — turn a data frame of coordinates into spatial pointsst_transform() — reproject to a different coordinate systemPlot it by adding geom_sf() layer to a ggplot() object.
sf: vector data as a data frameMost Tidyverse/dplyr verbs (e.g., filter, mutate,summarise, %>%) work with sf object, providing a seamless bridge between data manipulation and statistical analysis.
A Coordinate Reference System tells R what your coordinates mean — degrees of latitude/longitude, or metres on a projected grid. E.g.,
st_transform()Important
When your spatial data carry a CRS, inlabru uses it directly — so make sure all layers in your data share a consistent and appropriate CRS before you fit. Mismatched coordinate systems are one of the most common sources of error.
terra: raster dataRasters are a convenient way to represents spatially continuous phenomena by dividing a region into a grid of equally-sized cells, each storing a value for the variable of interest
The terra package is a modern and powerful tool for efficiently working with raster data.
Some useful functions are:
rast() — read a raster file (.tif or .tiff) or build one from an x-y-z data framecrs() — assign or match a coordinate systemcrop() — clip a raster to a region of interestext() - get the spatial extensionextend()- Enlarge the spatial extent of a rasterTo plot a raster in ggplot, the tidyterra package adds geom_spatraster() — so raster and sf layers stack on the same figure.
all spatial models discussed are special cases of Latent Gaussian models
different spatial terms are needed for different spatial data structures
the SPDE approach unifies approximation as all data structures are spatially referenced in continuous space
inlabru fits these models efficiently
In the next practical you will explore tools for visualization and wrangling spatial data objects.