Learn R Programming

spStack

spStack is an R package that delivers Bayesian inference for point-referenced spatial data by assimilating posterior inference over a collection of candidate models using stacking of predictive densities. Currently, it supports point-referenced Gaussian, Poisson, binomial and binary outcomes. Users can supply candidate values of spatial process parameters and certain auxiliary model parameters, based on which the collection of models will be created. spStack utilizes the Bayesian conjugate linear modelling framework for Gaussian data and the generalized conjugate multivariate distribution theory for non-Gaussian exponential family data. Learn more in vignette("spStack"). Technical details of the methodology are available in Zhang, Tang, and Banerjee 2024 and Pan, Zhang, Bradley, and, Banerjee 2024.

Installation

For a quick installation of the development version, run the following command in R.

# Install development version from GitHub
# install.packages("pak")
pak::pak("SPan-18/spStack-dev")

If installing from CRAN, use the following.

install.packages("spStack")

Installing from source

To install the package from source, download the tarball spStack_X.X.XX.tar.gz file. After setting the working directory at the file location, either issue R CMD install spStack_X.X.XX.tar.gz in the terminal, or run the following command in R to install the package.

install.packages("spStack_X.X.XX.tar.gz", type = "source", repos = NULL)

Please note that the package is written in C/C++ and hence contains a Makevars file for cross-platform portability. So, it is important to set the correct path to FORTRAN libraries as well as BLAS and LAPACK on your computer. For example, if you are working on MacOS, create a file ~.R/Makevars and set global configurations for the libraries to link with R. The following is an example of such a Makevars file.

# Set Fortran library paths
FLIBS = -L/opt/homebrew/opt/gcc/lib/gcc/14 -lgfortran -lquadmath -lm

# BLAS and LAPACK libraries (using Accelerate framework on macOS)
BLAS_LIBS = -L/System/Library/Frameworks/Accelerate.framework/Versions/Current/ -framework Accelerate
LAPACK_LIBS = -L/System/Library/Frameworks/Accelerate.framework/Versions/Current/ -framework Accelerate

It tells R to use the Accelerate framework, that comes pre-installed with Mac for BLAS and LAPACK functions. If you do not have gfortran, simply run brew install gcc on the terminal which will install the gcc compiler and gfortran comes bundled with gcc. If gcc is installed using Homebrew, then the path should be the same as above, otherwise the path for gfortran needs to set correctly.

Usage

Once successfully installed, load the library in R.

library(spStack)

View the vignette by running vignette("spStack") and see example code to implement predictive stacking for different Bayesian hierarchical spatial models.

Acknowledgement

The graphics used in the logo has been obtained from the page Gaussian RF (Boris Kozintsev, 1999). It represents a realization of an isotropic Gaussian random field under Matérn correlation function with parameters 5 and 2.

Copy Link

Version

Install

install.packages('spStack')

Monthly Downloads

153

Version

1.0.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Soumyakanti Pan

Last Published

October 8th, 2024

Functions in spStack (1.0.1)

sim_spData

Simulate spatial data on unit square
simBinary

Synthetic point-referenced binary data
cholUpdate

Different Cholesky factor updates
spGLMstack

Bayesian spatial generalized linear model using predictive stacking
spGLMexact

Univariate Bayesian spatial generalized linear model
get_stacking_weights

Optimal stacking weights
spLMstack

Bayesian spatial linear model using predictive stacking
spLMexact

Univariate Bayesian spatial linear model
stackedSampler

Sample from the stacked posterior distribution
spStack-package

spStack: Bayesian Geostatistics Using Predictive Stacking
surfaceplot

Make a surface plot
surfaceplot2

Make two side-by-side surface plots
iDist

Calculate distance matrix
simBinom

Synthetic point-referenced binomial count data
simPoisson

Synthetic point-referenced Poisson count data
simGaussian

Synthetic point-referenced Gaussian data