Using Intamap
The INTAMAP System
Examples using the intamap package
- Example 1 - predicting means and kriging error
- Example 2 - predicting means and kriging error using copula-method
- Example 3 - detailed calls
- Example 4 - block kriging
- Example 5 - block kriging - other prediction types
> ?interpolate
Most of the examples below uses the Meuse data set, which consists of 155 observations of heavy metal concentrations together with soil properties and distance to the river, and 3103 prediction locations in the object meuse.grid, both from the gstat-package. For more description, type: > ?meuse
Example 1 - predicting means and kriging error
In the example below, we are predicting the logarithms of the zinc concentrations of the meuse data set at the locations in meuse.grid. We are interested in the predicted mean and prediction variance of the log(zinc) values, in addition to the probability of the value being above 7 (the exceedance probability). We let the system choose the method itself, i.e. the methodName is set to automatic. There is still a time limitation though, the method has to be estimated to finish within the maximumTime of 30 seconds.
library(intamap)data(meuse)
meuse$value = log(meuse$zinc)
coordinates(meuse) = ~x+y
data(meuse.grid)
gridded(meuse.grid)=~x+y
spplot(meuse,"value",col.regions = bpy.colors())
output = interpolate(observations = meuse,
predictionLocations = meuse.grid,
outputWhat = list(mean=T, variance=T, excprob = 7),
maximumTime = 30,
methodName = "automatic",
optList = list() )
plot(output)
output$variogramModel summary(output) summary(t(output$outputTable))
The last three commands are there to check the result. First the result is plotted, the fitted variogram model can be examined, and there is a summary function that can give an overview of the final object. This object contains observations, predictions and some of the temporary results. The simplest predictions are mostly stored in the element called vardictions, whereas the more complicated results are stored in the element outputTable. This is particularly designed for the WPS, and needs to be transposed for interactive use.
Most of the arguments above are default values, and therefore not necessary to pass to the system. By calling: output = interpolate(meuse, meuse.grid) we only miss the probability of the value being above 7. The methodName can either be set to automatic, which gives the (presumebly) best interpolation method for the current problem, given the time available set with maximumTime, or it is possible to call one of the many methods directly. Possible options are:
- automap based on the geostatistical methods implemented in the automap-package
- copula using the copula-methods
- idw inverse distance interpolation (from gstat)
- linearVariogram linear variogram (from gstat)
- psgp using the projected spatial gaussian process methods in the psgp-package
- transGaussian transGaussian kriging from (from gstat)
- yamamoto similar to ordinary kriging but giving an alternative kriging variance, based on the local variance
optList is a parameter list where it is possible to give different arguments to the interpolation routine. Some of these are:
- confProj = TRUE Change corrections if they are different for observations and prediction locations
- doAnisotropy = TRUEEstimate the anisotropy and use it if significant
- nsim = 100Number of simulations when simulations are needed for a certain prediction type
- ngrid = 100Number of grid points in each block when simulations are necessary for aggregated predictions
- nmax = 50 The number of neighbours for local kriging
- formulaString = "value~1" A string indicating the relationship between dependent and independent variables (the "~1" term indicates ordinary kriging in this case)
- nmax = 50 The number of neighbours for local kriging
- mean, variance
- quantiles
- cumulative distribution (cumdistr)
- exceedance probabilities (excprob)
- unbiased prediction (mok or iwqsel)
Example 2 - predicting means and kriging error using copula-method
In the example below, we remove some of the observation locations to reduce computation time. Using the same maximumTime, the system will now choose the copula methods: observations = meuse[rnorm(155)>0.7,] predictionLocations = coarsenGrid(meuse.grid,5) output2 = interpolate(observations = observations, predictionLocations = predictionLocations, outputWhat = list(mean=T, variance=T, excprob = 7), maximumTime = 30, methodName = "automatic", optList = list() ) plot(output2)Example 3 - detailed calls
The function interpolate is a wrapper around a series of S3 class functions in R. Among these are: preProcess estimateParameters spatialPredict postProcessIt is also possible to call the single functions that are called from the interpolate function. First we have to create the interpolation object, and then do some sanity checks on this object (check if there are enough observations for interpolation, if some observation locations are duplicated, if the observations and prediction locations appear to be at different locations etc): krigingObject = createIntamapObject( observations = meuse, predictionLocations = meuse.grid, formulaString = "value~1", outputWhat = list(mean=TRUE, variance=TRUE, excprob = 7), params = list(confProj = TRUE), class = "automap") checkSetup(krigingObject) This function takes many of the same arguments as the interpolate function. The optList above is here referred to as params. methodName is here referred to as class. This class is the one that helps R choose between the different methods for each of the S3 functions in the list above. The command methods() give an overview over methods for a certain function.
> methods(estimateParameters) [1] estimateParameters.automap* estimateParameters.copula* [3] estimateParameters.default* estimateParameters.idw* [5] estimateParameters.linearVariogram* estimateParameters.transGaussian* [7] estimateParameters.yamamoto* Non-visible functions are asterisked The functions that does the interpolation can then be called: > krigingObject = preProcess(krigingObject) > krigingObject = estimateParameters(krigingObject) > krigingObject = spatialPredict(krigingObject) > krigingObject = postProcess(krigingObject) > plot(krigingObject)