Tutorials¶
Here are the many tutorials I’ve written [1] dealing with various aspects of spatial statistics. Please note the dates of each one, the older ones may be partly obsolete or require some adjustment to new versions of the computer programs.
Geostatistics¶
An introduction to (geo)statistics with R
A brief introduction to exploratory and inferential geo statistical analysis. At the same time, it introduces the R environment for statistical computing and visualisation] and several R packages, notably
sp
for spatial data structures andgstat
for conventional geostatistics. The exercise assumes no prior knowledge of either geostatistics nor the R environment.R code
 Introduction to: Rikken, M. G. J., & Van Rijn, R. P. G. (1993). Soil pollution with heavy metals—An inquiry into spatial variation, cost of mapping and the risk evaluation of copper, cadmium, lead and zinc in the floodplains of the Meuse west of Stein, the Netherlands. Dept. of Physical Geography, Utrecht University. This is the orignal report from which the “Meuse dataset” was created.
Cokriging with the gstat package of the R environment for statistical computing
Improving the mapping of an undersampled attribute that is coregionalized with a more intensively sampled attribute.
Distance education course Geostatistics & Opensource statistical computing
Interactive Excel worksheets explaining spatial autocorrelation, variograms and kriging
(XLS, compressed)Written by prof.dr.ir. Alfred Stein (University of Twente), formatted and with some more explanation by me. (1) Simulation of spatial correlation in one dimension, (2) Ordinary Kriging, (3) Universal Kriging, (4) Cokriging, (5) Selecting a grid spacing for kriging. Distributed by permission.
R Markdown minitutorials¶
These illustrate some details of geostatistics. Load into R Studio and compile (“knit”) to HTML, or execute chunkbychunk
Constructing a prediction grid
Shows how to create a regular grid onto which kriging or another prediction method can be applied.

A direct application of the ordinary kriging equations to derive kriging weights.

Shows how to map class probabilities over a grid using indicator kriging in
gstat
, and then make a map of the most probable, along with a map of prediction reliability, represented by the maximum probability of any class. It also has a section on using classification trees and random forests to classify the same dataset. 
Random numbers in R; simulation of binomial, normal, and mixed distributions; application to simulating random fields.
Spatial analysis¶
Trend surfaces in R by Ordinary and Generalized Least Squares
Kansas aquifer dataset
(TXT)R code
Thin plate spline interpolation with R
Areal Data and Spatial Autocorrelation R
This tutorial gives an overview of spatial analysis of areal data, that is, attributes of polygonal entities on a map. Typical examples are political divisions, census tracts, and ownership or management parcels. The attribute relates to the whole area of the polygon, and can not be further localized.
Central NY 8county census tracts leukemia incidence
(shapefile, neighbours, zipped)R code
Exercise: Exploratory Data Analysis with GeoDa
GeoDa is an opensource program, crossplatform program designed as a simple tool for exploratory spatial data analysis (ESDA) and some spatial modelling of spatial polygon data, that is, maps of polygon units such as census tracts or political divisions with a set of attributes measured on each one. This uses a portion of the 8county data of the R exercise (see item just above).
Syracuse census tracts leukemia incidence
(shapefile, neighbours, zipped)

This tutorial gives an overview of spatial pointpattern analysis. This considers the distribution of one or more sets of points in some bounded region as the result of some stochastic process which produces a finite number of “events” or “occurrences”.
Optimal partitioning of soil transects with R
Applies the split moving window approach to optimally partition linear series of observations to find “natural” boundaries.
General statistical methods¶

A systematic analysis of a simple dataset: the Mercer & Hall wheat yield uniformity trial: exploratory graphics, descriptive statistics, univariate & bivariate modelling, bootstrapping, robust methods, multivariate modelling, principal components analysis, model evaluation, crossvalidation, spatial analysis, spatial structure, generalized least squares, geographicallyweighted regression, periodicity (spectral analysis).
Mercer & Hall wheat yield dataset
(CSV)R code
(compressed)
An example of statistical data analysis using the R environment for statistical computing
This tutorial presents a data analysis sequence which may be applied to environmental datasets, using a small but typical data set of multivariate point observations: 147 soil profile observations representative of the humid forest region of southwestern Cameroon . It is aimed at students in geoinformation application fields who have some experience with basic statistics, but not necessarily with statistical computing. Five aspects are emphasised:
 Placing statistical analysis in the framework of research questions;
 Moving from simple to complex methods: first exploration, then selection of promising modelling approaches;
 Visualising as well as computing;
 Making correct inferences;
 Statistical computation and visualization.
R code
(compressed)
Analyzing land cover change with logistic regression in R
Land cover change at 1 064 grid cells from the Chapare region of Cochabamba province, Bolivia
point dataset
(CSV)R code
(compressed)
Curve fitting with the R Environment for Statistical Computing
R Markdown minitutorials¶
Explaining the concept of variance
Explains the concept of variance and how it is affected by classification.

Box and Cox (1964) developed a family of transformations designed to reduce nonnormality of the errors in a linear model. Applying this transform often reduces nonlinearity and heteroscedascity as well.
Explaining Ordinary Least Squares (OLS) regression with R
Shows how linear models are computed by ordinary least squares (OLS) and by a robust regression variant of OLS.
Demonstrating Generalized Least Squares regression
GLS accounts for autocorrelation in the linear model residuals. This example is of spatial autocorrelation, using the
Mercer & Hall wheat yield dataset
(CSV)Meuse heavy metals exercise — CART and random forests
Illustrates the use of regression trees, classification trees, Cubist, knearest neighbours, and spatiallyexplicit random forests

Shows how
rpart
decides on splits when building a regression tree. Variability of Regression Trees
Demonstrates the sensivity of regression trees to small changes in the training dataset, using the Meuse heavy metals dataset.
Finding the proper complexity parameter for a Regression Tree
Shows how crossvalidation is used to assess the proper complexity parameter for a regression tree. This is the graph shown by
printcp
, based on crossvalidation computations inrpart
.Comparing Random Forest packages
Compares the
randomForest
andranger
packages.Nonlinear Principal Components Analysis, a.k.a. Multivariate Analysis with Optimal Scaling
Practice with the “Gifi” approach of de Leeuw and colleagues. “The data analytic approach does not start with a model, but looks for transformations and combinations of [categorical] variables with the explicit purpose of representing the data in a simple and comprehensive, and usually graphical, way.”
example dataset
(RData) compiled HTML
Regional mapping¶
Regional mapping of climate variables from point samples (PDF)
Various methods for regional mapping of climate variables from station information using as predictors coördinates (Northing, Easting) and elevation, as well as the local neighbourhood: Ordinary Least Squares trend; Generalized Least Squares trend; Regression Kriging; Kriging with External Drift; Generalized Additive Models trend; Geographicallyweighted regression; Datadriven methods: Regression trees, Random Forests, Cubist Thinplate splines; Local interpolators: Ordinary kriging, inversedistance, Thiessen polygons. Uses the
ggplot2
,nlme
,rgdal
,sp
,gstat
,rpart
,randomForest
,ranger
,Cubist
,raster
,plotKML
andfields
R packages.Datasets used in this tutorial:
weather station climate summaries
(shapefiles, zipped, 2.5 Mb) documentation of U.S. Climate Normals 19712000 products (PDF)
48states SRTM DEM
(ESRI ASCII grid, zipped, 22.3 Mb)4state bounding box 4km resolution DEM (NJ, NY, PA, VT)
(RData)4state 4km resolution DEM (NJ, NY, PA, VT)
(RData)USA state boundaries
(shapefile, zipped, 3.2 Mb)
Additional covariates
The above exercise uses only three regional predictors as well as the local neighbourhood. Additional covariates might have a relation to regional or local climate, and thus might improve the regional mapping. These are: distance to the Great Lakes shoreline, distance to the Atlantic Ocean coast, two terrain indices (Multiresolution ValleyBottom Flatness MRVBF and Terrain Ruggedness Index TRI), and population density within two radii around stations or prediction points (nominally 2.5’ and 15’).
Setting up the additional covariates
(R Markdown source)Lakes Erie & Ontario
(OGC Geopackage)Atlantic Ocean coastline, NE USA
(OGC Geopackage)multiresolution index of valley bottom flatness (MRVBF)
(SAGA raster)Terrain Ruggedness Index
(SAGA raster)World population density (15' resolution)
(GeoTiff, 1 Mb)World population density (2.5' resolution)
(GeoTiff, 23.6 Mb)
Using the additional covariates
(R Markdown source)Prepared dataset of additional covariates
(RData, 2.5 Mb)
Regional mapping of climate variables from point samples: Northeast China
This applies many of the methods of the above tutorial to a region in China.
Inclass exercises Regional mapping of climate variables (R Markdown sources):
Setting up the dataset
 procedure to set up the dataset (PDF)
Procedure to set up the dataset
(R Markdown source)Temperature summaries 19812010
(CSV)Precipitation summaries 19812010
(CSV)Administrative boundaries of China
(Geopackage, 72.6 Mb)
Procedure to set up a prediction grid
(R Markdown source)World SRTM 1km resolution DEM
(ESRI grid, compressed, 195.2 Mb)
Additional covariates
The above exercise uses only three regional predictors as well as the local neighbourhood. Additional covariates might have a relation to regional or local climate, and thus might improve the regional mapping. These are: one terrain index (Multiresolution ValleyBottom Flatness MRVBF) and population density within two radii around stations or prediction points (nominally 2.5’ and 15’).
Setting up the additional covariates
(R Markdown source)Multiresolution index of valley bottom flatness (MRVBF)
(SAGA raster)World population density (15' resolution)
(GeoTiff, 1 Mb)World population density (2.5' resolution)
(GeoTiff, 23.6 Mb)
Using the additional covariates
(R Markdown source)
Prepared dataset of additional covariates
(RData, 6 Mb)
Geographic information systems (GIS)¶

Water pollution hazard for a drinking water reservoir in Tompkins County, NY (USA), using QGIS 3.4
Creating geometricallycorrect photointerpretations, photomosaics, and base maps for a project GIS
Timeseries analysis¶

tutorial datasets
(compressed)R code
Spatiotemporal geostatistics, includes a section on temporal structure
Fitting rational functions to time series in R
Rational functions are ratios of any two polynomials in a single variable. In this example we fit linear/quadratic rational functions to an irregular timeseries of proportional changes from an initial condition of a soil property in response to land use. The fitted equation can be interpreted to find the time to reach a maximum proportional deviation, and the value of that deviation.
tutorial dataset
(CSV)
[1]  or adapted from others 
Last modified 27March2020