install.packages(c(
"sf",
"stars",
"terra",
"s2",
"gstat",
"spatstat",
"spdep",
"spatialreg",
"mgcv"
))Spatiotemporal Modelling with R
Introduction
Required packages
The following packages may be used during the course; it is assumed that you know how to install packages, and have permission to do so on your computer.
R version
We require at least R 4.1.0 (as we’ll be using the native pipe |>), but it is recommended to always work with the latest released version of R.
CRAN packages:
non-CRAN packages:
starsdata and spDataLarge:
options(timeout = 3600) # 1 hr instead of 1 min
install.packages("spDataLarge", repos = "https://nowosad.github.io/drat/",
type = "source") # 23 Mb
install.packages("starsdata", repos = "http://cran.uni-muenster.de/pebesma/",
type = "source") # 1 Gb!Course schedule
Schedule Thu:
- 9:00 - 10:00 lecture part 1a
- 10:00 - 10:15 coffee break
- 10:15 - 11:00 lecture part 1b
- 11:00 - 12:00 exercise 1 answers
- 12:00 - 13:00 lunch break
- 13:00 - 14:00 lecure part 2a
- 14:00 - 15:00 exercises 2a
- 14:00 - 15:00 lecure part 2b
- 16:00 - 17:00 exercises 2b answers
Schedule Fri:
- 9:00 - 10:00 lecture part 3a
- 10:00 - 10:15 coffee break
- 10:15 - 11:00 lecture part 3b
- 11:00 - 12:00 exercises 3 answers
- 12:00 - 13:00 lunch break
- 13:00 - 14:00 lecure part 4
- 14:00 - 15:00 exercises 4 answers
Further:
- please raise hands or speak up whenever something comes up
- please also share questions you run into in your actual research, preferably with (example) data and R code
Syllabus
- part 1: the new spatial stack in R: simple features, DE-9IM, vector and raster data, data cubes; the spatial statistics data types
- part 2 geometry operations, raster-vector, vector-raster: geometry measures, predicates, and transformers; spherical geometry; raster-vector: polygonizing, extracting; vector-raster: rasterize, interpolate, density; up- and down-scaling: aggregation, sampling, area-weighted interpolation, dasymetric mapping;
- part 3. inference: spatial correlation, fitting models: spatial correlation for point patterns, geostatistical data, and lattice data; fitting regression models under spatial correlation
- part 4 prediction and simulation; point patterns: fitting densities, simulating point patterns; geostatistics: kriging interpolation, conditional simulation
Resources
- Spatial Data Science: With applications in R, by Pebesma and Bivand 2023 (open online, hard copy from CRC)
- Vignettes of sf: tab “Articles”
- Vignettes of stars: tab “Articles”
All these material were written using quarto or R-markdown
Reading as preparation: students may want to read from this book chapters: 3-7, 10-12, 14-16
Why R for spatial statistics / geospatial data science?
(skip)
- R is old! Think of the advantages!
- R is as good as any data science language, but is more in focus with the statistical community
- Most researchers in spatial statistics who share code have used or use R
- R has a strong ecosystem of users and developers, who communicate and collaborate (and compete, mostly in a good way)
- R spatial packages have gone full cycle:
- the first generation has been deprecated (
rgdal,rgeos,maptools), - then removed from CRAN, and
- superseded by modern versions (
sfandstarsreplacedsp,terrareplacedraster)
- the first generation has been deprecated (
- R is a data science language that allows you to work reproducibly
- Because we have CRAN and CRAN Taskviews: Spatial, SpatioTemporal, Tracking
Reproducing or recreating the current course
(skip)
- Go to https://github.com/edzer/ethz/
- Go to “Code”, then “copy URL to clipboard”
- Clone this repo to your hard drive
- Start RStudio by double clickign the
ethz.Rprojfile in the source directory - Reproduce these course materials by installing quarto and
- in RStudio: run
build-render book, or - on the command line: run
quarto renderin the course directory
- in RStudio: run
- Run individual code sections in RStudio, and modify them!
Exercises
- Install the
spDataLargepackage (see instructions above) - Copy (or clone) the course material from GitHub to your local machine
- Open it in RStudio
- Open the
part1.qmdfile. Try to identify a code chunk. - Run the first code chunk.
- Skip to the last code chunk; run all code chunks above it (by a single click), and then run this last code chunk.
- Render the entire course “book”, view the result by opening
_book/index.htmlin a web browser (from Rstudio)