Home
Download
R/S-plus
What's new
Manual
Examples
Screenshots
Mailing lists
Qt GUI front end
Idrisi32 front end
PCRaster support
GRASS support
links
Known bugs

The gstat R package and S-Plus library: multivariable geostatistics for S

Introduction

The S port of gstat (R package, S-Plus library) is now available. It provides the essential parts of gstat functionality to S users, aside from the added bonus of being in a very rich environment. See below for the source trees. New features to S users are the combination of
  • multivariable geostatistics (direct/cross variogram modelling; cokriging; cosimulation)
  • block kriging, for both regular and irregular blocks
  • kriging/sequential simulation in a local neighbourhood
  • three-dimensional kriging/simulation
in a single package. See below for the full feature list.

Reference

If you use the gstat S package/library for your publications, you can do me a favour by using the following reference:
Pebesma, Edzer J, 2004. Multivariable geostatistics in S: the gstat
package. Computers & Geosciences, 30: 683-691 
Note that in this publication, all forward quotes ' were erroneously replaced by back-quotes `.

Interface

gstat uses two formulae to define the (universal kriging) regression model and spatial locations. A sample run is:
# calculate sample variogram:
v <- variogram(log(zinc) ~ 1, locations = ~ x + y, data = meuse)
# fit a model to sample variogram:
v.fit <- fit.variogram(v, model = vgm(1, "Sph", 900, 1))
# plot both:
plot(v, model = v.fit) # view result
# use ordinary kriging on a regular grid, in meuse.grid:
z <- krige(formula = log(zinc) ~ 1, locations = ~ x + y, data = meuse, 
        newdata = meuse.grid, model = v.fit) 
# view ordinary kriging prediction and prediction error
levelplot(var1.pred ~ x + y, z, aspect=mapasp(z), 
        main = "ordinary kriging prediction") # view result
levelplot(sqrt(var1.var) ~ x + y, z, aspect=mapasp(z), 
        main = "ordinary kriging prediction error") # view result
The linear model for the data is in the first formula:
log(zinc) ~ 1
means that log-zinc values are modelled as an intercept (unknown constant mean) and an intrinsically stationary residual; the second formula
~ x + y
defines the spatial coordinates for the observations, found in the same data set. Note that data and newdata need to be defined to find the regressors and spatial coordinates of the observed variable (data) and of the prediction locations (newdata).

Alternatively,

~ x + y + z
is used for three-dimensional data, and
~ x
for one-dimensional data.

Documentation

Documentation (printed R manual pages) are available (pdf, dvi).

Examples

An example R script shows how most of the 17 original gstat examples are done in R, with links to the graphics. In the package they are the output of the command
demo(examples)
and works in S-Plus (6.1) as well, if preceded by:
data <- function(x) { } # make empty function
meuse <- meuse # make locally modifyable copy
Examples of gstat, used within R on top of grass can be found in
demo(grass)
but it requires the meuse data base to be a grass data base. This link provides such a data base (grass5).

Feature list

  1. uses S formulae for the linear data model and the spatial locations
  2. data may be 1-, 2- or 3-dimensional
  3. sample variogram, cross variogram, and directional variogram estimation
  4. variogram cloud estimation; interactive variogram cloud point pair identification
  5. nested variogram model fitting
  6. fitting of a linear model of coregionalization using nested models
  7. simple kriging, ordinary kriging, or universal kriging given arbitrary base functions (regressors)
  8. plotting functions for direct, directional or multivariable variograms and fitted models using lattice/trellis graphics
  9. point, regular block, or irregular block kriging
  10. univariate, multiple (uncorrelated), or multivariable (correlated) cokriging
  11. global kriging or kriging in a local neighbourhood
  12. any combination of the above three items (e.g., universal irregular block cokriging)
  13. sequential Gaussian or indicator simulation equivalents of any of the above combination chosen
  14. n-fold or leave-one-out cross validation for kriging
  15. support functions for plotting images using xyplot, image or levelplot
  16. efficient (fast) sequential simulation of many realisations in one pass of the random path
  17. fast local neighbourhood selection algorithm that uses the bucket PR quadtree algorithm
  18. most of the code is in C, most of the C code has been used for a long time
  19. optional debug output for many aspects of the process

Installation instructions

R is easy: read help(INSTALL) within R to find out how to install packages from source code.

the gstat S-Plus library (unix, >= 6.0) requires a few steps:

  • unpack the tree in an empty directory,
  • in this directory, run:
    ./configure
    
  • followed by one of:
    • if you are using ksh or bash:
       SPLUS=Splus6 make library
       
    • if you are using tcsh or csh
       setenv SPLUS Splus6
       make library
       
    where Splus6 is replaced by the script that starts your S-Plus version (assumed to be Splus 6.0 or higher)
  • optionally, add the command:
    make veryclean
    
    to got rid of some (now obsolete) files
  • and finally, move the gstat directory to the directory where you want to keep S-Plus libraries, say /home/user/S, and load it in an S-Plus session with the command:
    library(gstat, lib.loc="/home/user/S")
    

Install on R for Windows:

A compiled version of gstat is on CRAN. To install it on a connected computer, start R, choose from the menu: Packages, Install from CRAN, and choose gstat. Alternatively (if you're not connected) download gstat.zip from here, and install: start R, choose Packages, Install from local zip file, and enter the location of gstat.zip on your computer.

Install on S-Plus 6.0 or 6.1 for Windows

  • Download the zip file for S-Plus for Windows version 6.0 or 6.1;
  • unzip the file, this results in a directory called "gstat";
  • move this directory to the library directory in the S-Plus source tree, typically
    c:\Program Files\Insightful\splus61\library
  • start S-Plus
  • File, Load library, select gstat from list.
There's no on-line documentation yet, but you can use the printed R documentation mentioned above (PDF, DVI). The port was made with MinGW, with crucial help from Brian Ripley (-m rtd compiler flag; use of __cdecl for functions in qsort() calls).

Download source tree:

The current gstat R package in source form is available from CRAN; try this link . Download he source tree for the
Last modified: January 24, 2005
Page contents by Edzer J. Pebesma, page layout by Kor de Jong. Send comments.