Building Spatial Models

To this point in Spatial Modelling (I or II), we’ve really primarily dealt with regression models about spatial data. We have not really examined or understood how spatial structures or relationships themselves must be modeled. In the Regression module, we did talk a little bit about spatial fixed effects, which allow for there to be different mean/baselines in each area.

library(sf)
library(mosaic)
library(spdep)
bristol = sf::read_sf('./data/bristol-imd.shp')

Check Yourslf: Spatial Joins

Let’s say we need to have the ward ID for each LSOA. Right now, the LSOAs don’t have information on their wards built into the dataframe. If we have Bristol ward boundaries in the following geojson file:

Read in the data on ward boundaries:

wards = sf::read_sf('./data/wards.geojson')

What steps are necessary to join up the LSOAs that are within each ward? One workflow you’ve learned already might be:

Projection

First, we need to ensure that our data is in the same map projection.

To reproject the wards dataframe into the same projection as your bristol data, we use the sf::st_transform method. I find it easiest to set projections based on the exact projection string from the data we’re targeting:

wards = sf::st_transform(wards, sf::st_crs(bristol))

After we do the reprojection, we can check to see if the data is in exactly in the same projection by:

sf::st_crs(wards) == sf::st_crs(bristol)
## [1] TRUE

and, we can check if everything “looks right” by making a map:

plot(bristol['imd_score'], reset=FALSE, lwd=.1)
plot(sf::st_geometry(wards), border='white', lwd=2, add=TRUE)