| fields {fields} | R Documentation |
fields is a collection of functions for curve and function
fitting with an emphasis on spatial data and spatial statistics. It was developed over 20+ years to provide easy to use but sophistciated tools for analyzing
spatial data, particularly that encountered in the environemental sciences.
Please send bugs and questions to Doug Nychka nychka@mines.edu. Positive
comments are also welcome!
The
major methods implemented include cubic and thin plate splines,
universal
Kriging and Kriging for large data sets. A more modern terminology for Kriging is
spatial process estimation with covariance parameters determined by maximum likelihood and the uncertainty derived from assumptions of a Gaussian process.
Thoughout we try to include reasonable defaults in functions that reflect
our experience with analyzing spatial data.
One main feature of the spatial methods is any
covariance function implemented in R code can be used for spatial prediction.
Another important feature is that fields will take advantage of compactly
supported covariance functions in a seamless way through
the spam package.
See library( help=fields) for a listing of all the
fields contents. We also recommend the thoughtful vignette created by Ashton Weins, Mitchell Krock, and Emma Lilly (fieldsVignette.pdf) int the
fields github repository.
fields stives to have readable and tutorial code. Take a look at the
source code for mKrig to see how things work
"under the hood" and how a linear algebra computation is
overloaded to handle sparse matrices and how an output is built up sequentially throughout a computation.
The fields source code is liberally commented. Unfortunately on loading
this package, R will
strip comments from the source. However, you can go to
CRAN fields page to download
the latest "tarball" ( aka Package Source) and unzip to get code with comments.
We also keep the most recent version of this package at the
fields github repository.
and for commented source go to the
the subdirectory fields/src. This may be a more recent version than what is posted to CRAN.
Major methods
spatialProcess An easy to use method that fits a spatial process model
( e.g. Kriging) but also estimates the key spatial parameters: nugget variance, sill variance and range by maximum likelihood. Default covariance model is a Matern covariance function. This function and related functions called by this are the core methods in fields and have much flexibility.
spatialProcess allows one to supply a covariance function that is
written in native R code. See (stationary.cov) that includes
several families of covariances including the
Matern and several distance metrics including great circle distance.
Tps Thin Plate spline
regression including GCV and REML estimates for the smoothing parameter.
mKrig (micro Krig) and
fastTps
fast efficient Universal Kriging and spline-like functions, that can take advantage of sparse covariance
functions and thus handle very large numbers of spatial locations.
QTps A easy to use extension of thin plate splines for quantile and robust surface fitting.
mKrigMLEGrid and mKrigMLEJoint for maximum likelihood estimates of covariance parameters. These functions also
handle replicate fields, assumed to be independent realizations, at the same locations and can also take any covariate function function written in R following the fields format
Other noteworthy functions
vgram and vgram.matrix find variograms for spatial data (and
with temporal replications.
cover.design Generates space-filling designs where the distance
function is expresed in R code.
Many
convenient functions for working with image data and rationally (well,
maybe reasonably) creating and placing a color scale on plots:
as.image, imagePlot, bubblePlot,
drape.plot, quilt.plot
add.image, crop.image, half.image,
average.image,
designer.colors, color.scale,
in.poly
See also grid.list for how fields works with grids and
US
and world for adding a map quickly.
sreg splint Fast 1-D cubic smoothing
splines and interpolating cubic splines.
Generic functions that support the methods
plot - diagnostic plots of fit
summary- statistical summary of fit
print- shorter version of summary
surface- graphical display of fitted surface
predict- evaluation fit at arbitrary points
predictSE- prediction standard errors at arbitrary points.
sim.rf- Simulate a random fields on a 2-d grid.
Getting Started
Try some of the examples from help files for Tps or
spatialProcess.
Graphics tips
help( fields.hints)
gives some R code tricks for setting up common legends and axes.
And has little to do with this package!
Testing
See help(fields.tests) for testing fields.
Some fields datasets
CO2 Global satelite CO2 concentrations (simulated field)
RCMexample Regional climate model output
lennon Image of John Lennon
COmonthlyMet Monthly mean temperatures and precip for Colorado
RMelevation Digital elevations for the Rocky Mountain Empire
ozone2 Daily max 8 hour ozone concentrations for the US midwest
for summer 1987.
PRISMelevation Digital elevations for the
continental US at approximately 4km resolution
NorthAmericanRainfall 50+ year average and trend for summer rainfall at
1700+ stations.
rat.diet Small paired study on rat food intake over time.
WorldBankCO2 Demographic and carbon emission data
for 75 countries and for 1999.
DISCLAIMER: The authors can not guarantee the correctness of any function or program in this package.
## Not run:
# some air quality data, daily surface ozone measurements for the Midwest:
data(ozone2)
x<-ozone2$lon.lat
y<- ozone2$y[16,] # June 18, 1987 , there are some missing values
# pixel plot of spatial data
quilt.plot( x,y)
US( add=TRUE) # add US map
# fitting a thin plate spline surface (always a good way to start)
fit0<- Tps(x,y)
# fits a GCV thin plate smoothing spline surface to ozone measurements.
# Hey, it does not get any easier than this!
summary(fit0) #diagnostic summary of the fit
set.panel(2,2)
plot(fit0) # four diagnostic plots of fit and residuals.
# quick plot of predicted surface
set.panel()
surface(fit0) # contour/image plot of the fitted surface
US( add=TRUE, col="magenta", lwd=2) # US map overlaid
title("Daily max 8 hour ozone in PPB, June 18th, 1987")
####
fit2<- spatialProcess( x,y)
# a "Kriging" model. The covariance defaults to a Matern with smoothness 1.0.
# the nugget, sill and range parameters are found by maximum likelihood
# summary, plot, and surface also work for fit2 !
surface(fit2) # contour/image plot of the fitted surface
US( add=TRUE, col="magenta", lwd=2) # US map overlaid
title("Daily max 8 hour ozone in PPB, June 18th, 1987")
## End(Not run)