Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

RFinterpolate

Interpolation methods


Description

The function allows for different methods of interpolation. Currently, only various kinds of kriging are installed.

Usage

RFinterpolate(model, x, y = NULL, z = NULL, T = NULL, grid=NULL,
              distances, dim, data, given=NULL, params, err.model, err.params,
              ignore.trend = FALSE, ...)

Arguments

model,params

object of class RMmodel, RFformula or formula; best is to consider the examples below, first.
The argument params is a list that specifies free parameters in a formula description, see RMformula.

x

vector of x coordinates, or object of class GridTopology or raster; for more options see RFsimulateAdvanced.

y,z

optional vectors of y (z) coordinates, which should not be given if x is a matrix.

T

optional vector of time coordinates, T must always be an equidistant vector. Instead of T=seq(from=From, by=By, len=Len), one may also write T=c(From, By, Len).

grid

logical; the function finds itself the correct value in nearly all cases, so that usually grid need not be given. See also RFsimulateAdvanced.

distances,dim

another alternative for the argument x to pass the (relative) coordinates, see RFsimulateAdvanced.

data

matrix, data.frame or object of class RFsp;
If a matrix is given the ordering of the colums is the following: space, time, multivariate, repetitions, i.e. the index for the space runs the fastest and that for repetitions the slowest. If given is not given and data is a matrix or data is a data.frame, RandomFields tries to identify where the data and the coordinates are, e.g. by names in formulae or by fixed names, see Coordinate systems. See also RFsimulateAdvanced. If all fails, the first columns are interpreted as coordinate vectors, and the last column(s) as (multiple) measurement(s) of the field. Notes that also lists of data can be passed.

If the argument x is missing, data may contain NAs, which are then replaced through imputing.

given

optional, matrix or list. If given matrix then the coordinates can be given separately, namely by given where, in each row, a single location is given.
If given is a list, it may consist of x, y, z, T, grid.
If given is provided, data must be a matrix or an array containing the data only.

err.model,err.params

For conditional simulation and random imputing only.
In case of (assumed) error-free measurements (which is mostly the case in geostatistics) the argument err.model is not given. In case of measurement errors we have err.model=RMnugget(var=var).
err.param plays the same role as params for model.

ignore.trend

logical. If TRUE only the covariance model of the given model is considered, without the trend part.

...

for advanced use: further options and control arguments for the simulation that are passed to and processed by RFoptions. If params is given, then ... may include also the variables used in params.

Details

In case of repeated data, they are kriged separately; if the argument x is missing, data may contain NAs, which are then replaced by the kriged values (imputing);

In case of intrinsic cokriging (intrinsic kriging for multivariate random fields) the pseudo-cross-variogram is used (cf. Ver Hoef and Cressie, 1991).

Value

The value depends on the additional argument variance.return, see RFoptions.

If variance.return=FALSE (default), Kriging returns a vector or matrix of kriged values corresponding to the specification of x, y, z, and grid, and data.

data: a vector or matrix with one column
* grid=FALSE. A vector of simulated values is returned (independent of the dimension of the random field)
* grid=TRUE. An array of the dimension of the random field is returned (according to the specification of x, y, and z).

data: a matrix with at least two columns
* grid=FALSE. A matrix with the ncol(data) columns is returned.
* grid=TRUE. An array of dimension d+1, where d is the dimension of the random field, is returned (according to the specification of x, y, and z). The last dimension contains the realisations.

If variance.return=TRUE, a list of two elements, estim and var, i.e. the kriged field and the kriging variances, is returned. The format of estim is the same as described above. The format of var is accordingly.

Note

Important options are

  • method (overwriting the automatically detected variant of kriging)

  • return_variance (returning also the kriging variance)

  • locmaxm (maximum number of conditional values before neighbourhood kriging is performed)

  • fillall imputing estimates location by default

  • varnames and coordnames in case data.frames are used to tell which column contains the data and the coordinates, respectively.

Author(s)

Author(s) of the code:

References

Chiles, J.-P. and Delfiner, P. (1999) Geostatistics. Modeling Spatial Uncertainty. New York: Wiley.

Cressie, N.A.C. (1993) Statistics for Spatial Data. New York: Wiley.

Goovaerts, P. (1997) Geostatistics for Natural Resources Evaluation. New York: Oxford University Press.

Ver Hoef, J.M. and Cressie, N.A.C. (1993) Multivariate Spatial Prediction. Mathematical Geology 25(2), 219-240.

Wackernagel, H. (1998) Multivariate Geostatistics. Berlin: Springer, 2nd edition.

See Also

Examples

RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
##                   RFoptions(seed=NA) to make them all random again

## Preparation of graphics
dev.new(height=7, width=16) 

## creating random variables first
## here, a grid is chosen, but does not matter
p <- 3:8
points <- as.matrix(expand.grid(p,p))
model <- RMexp() + RMtrend(mean=1)
dta <- RFsimulate(model, x=points)
plot(dta)
x <- seq(0, 9, 0.25)


## Simple kriging with the exponential covariance model
model <- RMexp()
z <- RFinterpolate(model, x=x, y=x, data=dta)
plot(z, dta)

## Simple kriging with mean=4 and scaled covariance
model <- RMexp(scale=2) + RMtrend(mean=4)
z <- RFinterpolate(model, x=x, y=x, data=dta)
plot(z, dta)

## Ordinary kriging
model <- RMexp() + RMtrend(mean=NA)
z <- RFinterpolate(model, x=x, y=x, data=dta)
plot(z, dta)



## Co-Kriging
n <- 100
x <- runif(n=n, min=1, max=50)
y <- runif(n=n, min=1, max=50)



rho <- matrix(nc=2, c(1, -0.8, -0.8, 1))
model <- RMparswmX(nudiag=c(0.5, 0.5), rho=rho)

## generation of artifical data
data <- RFsimulate(model = model, x=x, y=y, grid=FALSE)
## introducing some NAs ...
print(data)
len <- length(data)
data@data$variable1[1:(len / 10)] <- NA
data@data$variable2[len - (0:len / 100)] <- NA
print(data)
plot(data)

## co-kriging
x <- y <- seq(0, 50, 1)

k <- RFinterpolate(model, x=x, y=y, data= data)
plot(k, data)

## conditional simulation
z <- RFsimulate(model, x=x, y=y, data= data) ## takes some time
plot(z, data)








close.screen(all = TRUE)

RandomFields

Simulation and Analysis of Random Fields

v3.3.10
GPL (>= 3)
Authors
Martin Schlather [aut, cre], Alexander Malinowski [aut], Marco Oesting [aut], Daphne Boecker [aut], Kirstin Strokorb [aut], Sebastian Engelke [aut], Johannes Martini [aut], Felix Ballani [aut], Olga Moreva [aut], Jonas Auel[ctr], Peter Menck [ctr], Sebastian Gross [ctr], Ulrike Ober [ctb], Paulo Ribeiro [ctb], Brian D. Ripley [ctb], Richard Singleton [ctb], Ben Pfaff [ctb], R Core Team [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.