Tutorial on modelling spatial and spatio-temporal non-Gaussian data with FRK

Matthew Sainsbury-Dale    Andrew Zammit-Mangion    Noel Cressie
Abstract

In this vignette, we provide examples where we model non-Gaussian data using FRK version 2.x and above. All of the functionality that FRK offers in a Gaussian setting extends to a non-Gaussian setting: see the vignette “Introduction to FRK”, which describes how the BAUs and basis functions work; inference over different spatial manifolds (such as the sphere); inference in a spatio-temporal setting; and spatial change of support.

1 Methodology

The statistical model used by FRK in a non-Gaussian setting is a spatial generalised linear mixed (GLMM) model [Diggle et al., 1998], a hierarchical model consisting of two layers. In the process layer, we model the conditional mean of the data as a transformation of a latent spatial process, where the spatial process is modelled as a low-rank spatial random effects model; see Section 1.1. The process layer, which governs the conditional mean of the data, retains many similarities to that in previous versions of the package, as described by Zammit-Mangion and Cressie [2021] and in the vignette “FRK_intro”. In the data layer, we use a conditionally independent exponential-family model for the data; see Section 1.2. In Sections 1.3 and 1.4 we briefly discuss parameter estimation, and spatial prediction and uncertainty quantification.

1.1 The process layer

Denote the latent spatial process as Y⁡(⋅)≡{Y⁡(𝒔):𝒔∈D}, where 𝒔 indexes space in the spatial domain of interest D. The model for Y⁡(⋅) is the so-called spatial random effects (SRE) model [Cressie and Johannesson, 2008],

Y⁡(𝒔)=𝒕⁢(𝒔)⊤⁢𝜶+ϕ⁢(𝒔)⊤⁢𝜼+ξ⁡(𝒔);𝒔∈D, (1)

where 𝒕⁡(⋅) are spatially referenced covariates with associated regression parameters 𝜶, ϕ⁡(⋅)≡(ϕ1⁢(⋅),…,ϕr⁢(⋅))⊤ is an r-dimensional vector of pre-specified spatial basis functions with associated random coefficients 𝜼, and ξ⁡(⋅) is a fine-scale random process that is ‘almost’ uncorrelated.

FRK discretises the domain of interest D into N small, non-overlapping basic areal units (BAUs) {Ai:i=1,…,N} such that D=∪i=1NAi. BAUs are a key element of FRK, as they provide a framework that allows one to use both point-referenced and areal data simultaneously, and one that facilitates the spatial change-of-support problem. After discretisation via the BAUs, we obtain the vectorised version of (1),

𝒀=𝑻𝜶+𝑺𝜼+𝝃, (2)

where 𝒀 is an N-dimensional vector, 𝑻 and 𝑺 are known design matrices, and 𝝃 is the vector associated with the fine-scale process.

We model the fine-scale random effects as being independent and identically distributed Gaussian random variables with variance σξ2; we model 𝜼 as a mean-zero multivariate-Gaussian random variable, typically using a sparse precision matrix parametrisation formualtion in a non-Gaussian setting.

Following standard generalised linear model theory [McCullagh and Nelder, 1989], FRK v.2 uses a link function, g⁡(⋅), to model Y⁡(⋅) as a transformation of the mean process, μ⁡(⋅):

g⁡(μ⁡(𝒔))=Y⁡(𝒔);𝒔∈D.

The mean process evaluated over the BAUs is

μi=g−1(Yi),i=1,…,N,

where g−1⁢(⋅) is the inverse link function. An identity link function and a Gaussian data model yields the standard Gaussian FRK model.

1.2 The data layer

Given m observations with footprints spanning one or more BAUs, we define the observation supports as Bj≡∪i∈cjAi for j=1,…,m, where cj is a non-empty set in the power set of {1,…,N}, and define DO≡{Bj:j=1,…,m}. Let Zj≡Z⁡(Bj), j=1,…,m. The vector of observations (the data vector) is then 𝒁≡(Z1,…,Zm)⊤.

Since each Bj∈DO is either a BAU or a union of BAUs, one can construct an m×N matrix

𝑪Z≡(wi𝕀(Ai⊂Bj):i=1,…,N;j=1,…,m),

where 𝕀⁡(⋅) is the indicator function, which creates a linear mapping from 𝝁≡(μi:i=1,…,N)⊤ to evaluations of the mean process over the observation supports;

𝝁Z≡𝑪Z⁢𝝁. (3)

The normalise_wts argument in SRE() controls whether the linear mapping of 𝑪Z corresponds to a weighted sum or a weighted average; if normalise_wts = TRUE, then the weights wi are normalised so that the rows of 𝑪Z sum to one, and the mapping represents a weighted average.

We assume that [Zj∣μ(⋅),ψ]=[Zj∣𝝁Z,j,ψ], where ψ is a (nuisance) dispersion parameter and, for a generic random quantities A and B, [A∣B] denotes the probability distribution of A given B. That is, a given observation depends only on the value of the mean process at the corresponding observation support, rather than on the process over the whole domain. As a result, conditional on the latent spatial process, all observations are conditionally independent:

[𝒁∣μ(⋅),ψ]=∏j=1m[Zj∣𝝁Z,j,ψ].

We model the conditional distribution [Zj∣𝝁Z,j,ψ] as a member of the exponential family [McCullagh and Nelder, 1989, Sec. 2.2.2], with conditional expectation μ(Bj)≡𝔼{Zj∣𝝁Z,j,ψ}.

The model employed by FRK v.2 can be summarised as follows.

Zj|𝝁Z,j,ψ∼indEF⁢(𝝁Z,j,ψ),j=1,…,m, (4)
𝝁Z=𝑪Z⁢𝝁, (5)
g⁡(𝝁)=𝒀, (6)
𝒀=𝑻𝜶+𝑺𝜼+𝝃, (7)
𝜼|ϑ∼Gau⁢(𝟎,𝑸−1), (8)
𝝃|σξ2∼Gau⁢(𝟎,σξ2⁢𝑽). (9)

where 𝑽 is a known diagonal matrix with positive entries on the diagonal and σξ2 is either unknown and estimated, or provided by the user.

1.3 Estimation

The complete-data likelihood function for our model is

L(𝜽;𝒁,𝜼,𝝃)≡[𝒁,𝜼,𝝃]=[𝒁∣𝝁Z,ψ][𝜼∣ϑ][𝝃∣σξ2], (10)

where 𝜽≡(𝜶⊤,ϑ⊤,σξ2,ψ)⊤ and ϑ are variance components, and its logarithm is

l(𝜽;𝒁,𝜼,𝝃)≡lnL(𝜽;𝒁,𝜼,𝝃)=ln[𝒁∣𝝁Z,ψ]+ln[𝜼∣ϑ]+ln[𝝃∣σξ2]. (11)

Under our modelling assumptions, the conditional density functions [𝜼∣ϑ] and [𝝃∣σξ2] are invariant to the specified link function and assumed distribution of the response variable. Of course, this invariance does not hold for [𝒁∣𝝁Z,ψ]. As we only consider data models in the exponential family, ln[𝒁∣𝝁Z,ψ] may be expressed as

ln[𝒁∣𝝁Z,ψ]=∑j=1m{Zj⁢λ⁢(μZ,j)−b⁡(λ⁡(μZ,j))a⁡(ψ)+c(Zj,ψ)}, (12)

where a⁡(⋅), b⁡(⋅), and c⁡(⋅,⋅) are deterministic functions specific to the exponential family member, and λ⁡(⋅) is the canonical parameter.

The marginal likelihood, which does not depend on the random effects, is given by

L∗⁢(𝜽,𝒁)≡∫ℝpL⁡(𝜽,𝒁,𝒖)⁢d𝒖, (13)

where 𝒖≡(𝜼⊤,𝝃⊤)⊤∈ℝp, and p is the total number of random effects in the model. When the data are non-Gaussian, the integral in (13) is typically intractable and must be approximated either numerically or analytically. In FRK, we use the Laplace approximation, implemented using the R package TMB [Kristensen et al., 2016].

Given as input a C++ template function which defines the complete-data log-likelihood function (11), TMB [Kristensen et al., 2016] computes the Laplace approximation of the marginal log-likelihood, and automatically computes its derivatives, which are then called from within FRK by an optimising function specified by the user (nlminb() is used by default). TMB uses CppAD [Bell, 2005] for automatic differentiation, and the linear algebra libraries Eigen [Guennebaud et al., 2010] and Matrix [Bates et al., 2019] for vector and matrix operations in C++ and R, respectively; use of these packages yields good computational efficiency. TMB’s implementation of automatic differentiation is a key reason why we can cater for a variety of response distributions and link functions, as we do not need to consider each combination on a case-by-case basis.

1.4 Prediction and uncertainty quantification

There are three primary quantities of interest in this framework: The latent process Y⁡(⋅), the mean process μ⁡(⋅), and the noisy data process. To produce predictions and associated uncertainties, we need to determine the posterior distribution of these quantities.

It can be shown that the Laplace approximation implies that the posterior distribution of the random effects, 𝒖|𝒁,𝜽 is approximated to be Gaussian. This, in turn, implies that the posterior distribution of 𝒀 is also approximated to be Gaussian, and hence inference on Y⁡(⋅) can be done using closed form solutions. However, the posterior distribution of non-linear functions of Y⁡(⋅) (e.g., the mean process) are typically not available in closed form, and in this case some form of approximation is required. Hence, we choose to use a Monte Carlo (MC) framework.

For each quantity, we use the posterior expectation as our predictor. A commonly used metric for uncertainty quantification is the root-mean-squared prediction error (RMSPE). In a non-Gaussian setting, it can be difficult to interpret the RMSPE, and it is often more intuitive to quantify uncertainty through the width of the posterior predictive intervals. Hence, in FRK, we also provide the user with user-specified percentiles of the posterior predictive distribution. These quantities can be computed straightforwardly using MC sampling.

1.4.1 Arbitrary prediction regions

Often, one does not wish to predict over a single BAU, but over regions spanning multiple BAUs. Define the set of prediction regions as DP≡{B~k:k=1,…,NP}, where B~k≡∪i∈ckAi, and where ck is some non-empty set in the power set of {1,…,N}. Like the data, the prediction regions {B~k} may overlap. In practice, B~k may not include entire BAUs; in this case, we assume that a prediction region contains a BAU if and only if there is at least some overlap between the BAU and the prediction region. Prediction over DP requires some form of aggregation across relevant BAUs. Since in the non-Gaussian setting aggregation must be done on the original scale, we restrict prediction over arbitrary regions to the mean (or the noisy data process). Therefore, predictions of the latent process Y⁡(⋅) are not allowed over arbitrary prediction regions.

Consider the predictions {μP(B~k):k=1,…,NP}, where μP(⋅)≡μ(⋅∣𝒁,𝜽). These predictions are weighted sums of the predictions over the associated BAUs. Specifically,

μP,k≡μP(B~k)=∑i=1Nw~i𝕀(Ai⊂B~k)μi;i=1,…,N;k=1,…,NP;B~k∈DP,

where, in a similar fashion to the incidence matrix 𝑪Z, the weights {w~i} are optionally provided by the user in the wts field of the BAU object, and may be normalised if normalise_wts = TRUE. If wts is NULL, the BAUs are assumed to be equally weighted. Define 𝝁P≡(μP,k:k=1,…,NP)⊤. Since each element in DP is the union of subsets of DG, one can construct a matrix,

𝑪P≡(w~i:i=1,…,N;k=1,…,NP),

such that 𝝁P=𝑪P⁢𝝁. Again, we use MC sampling to predict 𝝁P.

2 Example: Simulated Non-Gaussian, point-referenced spatial data

First, load the required packages.

library("FRK")       # for carrying out FRK       
library("sp")        # for defining points/polygons
library("dplyr")     # for easy data manipulation
library("ggplot2")   # for plotting

Now, simulate some Poisson distributed spatial data.

m <- 250                                                   # Sample size
RNGversion("3.6.0"); set.seed(1)                           # Fix seed
zdf <- data.frame(x = runif(m), y= runif(m))               # Generate random locs
zdf$Y <- 3 + sin(7 * zdf$x) + cos(9 * zdf$y)               # Latent process
zdf$z <- rpois(m, lambda = exp(zdf$Y))                     # Simulate data
coordinates(zdf) = ~x+y                                    # Turn into sp object

There is an ‘expert’ way of using FRK that involves using the functions auto_BAUs() and auto_basis() to automatically construct BAUs and basis functions from the data, and SRE() and SRE.fit() to initialise and fit the SRE model object. This ‘expert’ way is documented in the vignette “FRK_intro”. Alternatively, there is a ‘simple’ way of using FRK that uses the high-level wrapper function FRK() that calls these functions under-the-hood; in this vignette, we will use the ‘simple’ way.

S <- FRK(f = z ~ 1,               # Formula to FRK
         list(zdf),               # All datasets are supplied in list
         nres = 2,                # Low-rank model to reduce run-time
         response = "poisson",    # data model
         link = "log",            # link function 
         nonconvex_hull = FALSE)  # convex hull                     
pred <- predict(S)                # prediction stage

FRK includes two plotting methods, plot() and plot_spatial_or_ST(); the former takes an SRE object and the result of a call to predict, and returns a list of ‘ggplot’ objects containing the predictions and uncertainty quantification of those predictions, while the latter is a general-purpose function for ‘Spatial*DataFrame’ and ‘STFDF’ objects.

plot_list <- plot(S, pred$newdata)
plot_list <- c(plot_list, plot_spatial_or_ST(zdf, "z"))

This list of plot objects can then be arranged using one of the many functions for arranging ‘ggplot’ objects: See Figure 1.

## Ignoring unknown labels:
## * fill : "data"

Refer to caption
Figure 1: (Left) Simulated Poisson spatial data. (Centre) Prediction of the mean process. (Right) Uncertainty quantification of predictions; specifically the width of the 90% posterior predictive interval.

3 Example: Lognormally distributed soil data, point and block-level predictions

Between 1954 and 1963, nuclear devices were detonated at Area 13 of the Nevada Test Site in the United States, contaminating the surrounding soil with the radioactive element americium (Am). In 1971, the Nevada Applied Ecology Group measured Am concentrations in a region surrounding Ground Zero (GZ), the location where the devices were detonated [Paul and Cressie, 2011]. The total number of measurements (including some that are collocated) is 212. In the following, we load this data set (supplied by FRK), and define GZ.

data("Am_data")
coordinates(Am_data) = ~ Easting + Northing # convert to sp object
GZ_df <- data.frame("Easting" = 219868.09, "Northing" = 285320.8)

The left and centre panels of Figure 2 shows the data on the original scale and on the log scale, respectively. Paul and Cressie [2011] note that these Am concentrations are lognormally distributed, and that soil remediation is often made by averaging the contaminant over pre-specified spatial regions of D called blocks. Hence, this application requires lognormal prediction over blocks, a task well suited to FRK. The right panel of Figure 2 shows a blocking scheme containing five blocks that we will predict over, which is centred on GZ.

Refer to caption
Figure 2: Americium soil data and blocking scheme.

Following Paul and Cressie [2011], we use a piecewise linear trend, where observations within a distance of 30.48m from GZ follow a different trend to those observations beyond 30.48m from GZ. In FRK, covariates must be defined at the BAU level.

BAUs <- auto_BAUs(manifold = plane(),
                  type = "grid",
                  data = Am_data,
                  nonconvex_hull = FALSE)

## Add covariates to the BAUs
d_cutoff <- 30.48
d_BAU <- distR(coordinates(BAUs), GZ_df)
BAUs$x1 <- as.numeric(d_BAU < d_cutoff)
BAUs$x2 <- d_BAU * BAUs$x1
BAUs$x3 <- as.numeric(d_BAU >= d_cutoff)
BAUs$x4 <- d_BAU * (BAUs$x3)

In the following, we indicate that a scalar covariance matrix should be used for the fine-scale variation term (implicit when allowing FRK() to construct that BAUs), and we replicate lognormal kriging by fixing the measurement-error standard deviation to a small value. Then, we run FRK() as usual, set est_error = FALSE so that the measurement-error standard deviation is not estimated.

BAUs$fs     <- 1
Am_data$std <- 1

S <- FRK(f = Am ~ -1 + x1 + x2 + x3 + x4, data = list(Am_data),
         response = "gaussian",
         link = "log",
         BAUs = BAUs,
         nres = 2,
         est_error = FALSE)

By predicting over the BAUs, one may generate predictions over the entire spatial domain. In predict(), we set type = c("link", "mean") to obtain predictions for both the latent process Y⁡(⋅), and the mean process μ⁡(⋅). Figure 3 shows BAU level predictions and uncertainty using FRK.

pred <- predict(S, type = c("link", "mean"))
plot_list <- plot(S, pred$newdata)
Refer to caption
Figure 3: Americium point predictions.

Alternatively, by passing a ‘SpatialPolygonsDataFrame’ object into the newdata argument of predict(), one may straightforwardly generate block-level predictions. When predicting over arbitrary spatial regions, FRK is limited to prediction of the mean process.

pred <- predict(S, newdata = blocks)

These block level predictions may be plotted with the help of SpatialPolygonsDataFrame_to_df(); see Figure 4.

Refer to caption
Figure 4: Americium block level predictions.

References

  • Bates et al. (2019) D. Bates, M. Maechler, and T. A. Davis Matrix: sparse and dense matrix classes and methods. Note: R package version 1.2-17 External Links: Link Cited by: §1.3.
  • Bell (2005) B. M. Bell CppAD: a package for C++ algorithmic differentiation.. Note: https://coin-or.github.io/CppAD/doc/cppad.htmAccessed: 2019-06-15 Cited by: §1.3.
  • Cressie and Johannesson (2008) N. Cressie and G. Johannesson Fixed rank kriging for very large spatial data sets. Journal of the Royal Statistical Society 70, pp. 209–226. Cited by: §1.1.
  • Diggle et al. (1998) P. J. Diggle, J. A. Tawn, and R. A. Moyeed Model-based geostatistics. Journal of the Royal Statistical Society 47, pp. 299–350. Cited by: §1.
  • Guennebaud et al. (2010) G. Guennebaud B. Jacob et al. Eigen v3. Note: https://libeigen.gitlab.io/Accessed: 11-05-2019 Cited by: §1.3.
  • Kristensen et al. (2016) K. Kristensen, A. Nielsen, C. W. Berg, H. Skaug, and B. M. Bell TMB: Automatic differentiation and Laplace approximation. Journal of Statistical Software 70, pp. 1–21. Cited by: §1.3, §1.3.
  • McCullagh and Nelder (1989) P. McCullagh and J. A. Nelder Generalized Linear Models. Chapman & Hall, London, UK. Cited by: §1.1, §1.2.
  • Paul and Cressie (2011) R. Paul and N. Cressie Lognormal block kriging for contaminated soil. European Journal of Soil Science 62, pp. 337–345. Cited by: §3, §3, §3.
  • Zammit-Mangion and Cressie (2021) A. Zammit-Mangion and N. Cressie FRK: an R package for spatial and spatio-temporal prediction with large datasets. Journal of Statistical Software In press. Cited by: §1.