Learn R Programming

RandomFields (version 3.0.32)

RFcov: Evaluate Covariance and Variogram Functions

Description

RFcov returns the values of a covariance function; RFvariogram returns the values of a variogram; RFpseudovariogram returns the values of a pseudovariogram; RFcovmatrix returns the covariance matrix for a set of points RFfctn returns the values of a shape function;

Usage

RFcov(model, x, y = NULL, z = NULL, T = NULL, grid, distances, dim,
      fctcall = c("Cov", "CovMatrix", "Variogram", "Pseudovariogram",
                  "Fctn"),
       ...)

RFvariogram(model, x, y = NULL, ...)

RFpseudovariogram(model, x, y = NULL, ...)

RFcovmatrix(...)

RFfctn(...)

Arguments

model
object of class RMmodel; the covariance or variogram model, which is to be evaluated
x
vector or $(n \times \code{dim})$-matrix, where $n$ is the number of points at which the covariance function is to be evaluated; in particular, if the model is isotropic or dim=1 then x is a vector. x
y
second vector or matrix for non-stationary covariance functions
z
z-component of point if xyzT-specification of points is used
T
T-component of point if xyzT-specification of points is used
grid
boolean; whether xyzT specify a grid
distances
vector; only if the function RFcovmatrix is used; the lower triangular part of the distance matrix column-wise; equivalently the upper triangular part of the distance matrix row-wise; either
dim
dimension of the coordinate space in which the model is applied
fctcall
internal. This argument should not be considered by the user
...
arguments passed to RFcov (RFcovmatrix) and arguments passed to RFoptions

Value

  • RFcov returns a vector of values of the covariance function. RFvariogram returns a vector of values of the variogram model.

    RFpseudovariogram returns a vector of values of the variogram model.

    RFcovmatrix returns a covariance matrix.

Details

RFcovmatrix returns a covariance matrix. Here a matrix of of coordinates (x) or a vector or a matrix of distances is expected. RFcovmatrix allows also for variogram models. Then the negative of the variogram matrix is returned.

See Also

RMmodel, RFsimulate, RFfit.

Examples

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

# locations:
X <- matrix(runif(15), ncol=3)
 # coordinate matrix of 5 arbitrary points
 # p1, p2, p3, p4, p5 in 3-dimensional space
Y <- matrix(runif(15),ncol=3)
 # coordinate matrix of 5 arbitrary points
 # q1, q2, q3, q4, q5 in 3-dimensional space


#####################################################
# evaluate covariance function C(x,y) #
# or variogram gamma(x,y) #
# at given locations #
#####################################################

RFgetModelNames() # returns available models


#####################################################
# a stationary covariance model

model <- RMexp()

# covariance only depends on differences
# of locations hi=pi-qi in 3-dimensional space
# therefore, the following 2 commands yield the same

RFcov(model=model, x=X, y=Y)
RFcov(model=model, x=X-Y)
 # yields 5 values C(hi)=C(pi,qi) for i=1,2,3,4,5

#####################################################
# get covariance matrix C(x_i,x_j) #
# at given locations x_i, i=1,...,n #
#####################################################


#####################################################
# in particular compare the following two evaluations

x <- c(1,2,1)
y <- c(4,5,6)
RFcov(model=model,
 x=as.matrix(x), y=as.matrix(y), grid=FALSE)
 # coord space 1-dim'l
 # evaluate at 3 points
RFcov(model=model,
 x=t(x),y=t(y)) # coord space 3-dim'l
 # evaluate at 1 point

#####################################################
# an isotropic stationary covariance model

model <- RMexp()
# the covariance function C(x,y)=C(r) of this model
# depends only on the distance r between x and y

RFcovmatrix(model=model, distances=c(5,3,2.5,4,2.5,2.5),
 dim=4)

## yields a 4 times 4 covariance matrix of the form
## C(0) C(5) C(3) C(2.5)
## C(5) C(0) C(4) C(2.5)
## C(3) C(4) C(0) C(2.5)
## C(2.5) C(2.5) C(2.5) C(0)

#####################################################
# a variogram model

model <- RMfbm(alpha=1)
 # fractal Brownian Motion is a variogram model

RFvariogram(model=model, x=X, y=Y)
 # yields 5 values gamma(pi,qi) for i=1,2,3,4,5
RFvariogram(model=model, x=X-Y)
 # gives same output

\dontrun{
#####################################################
# a non-isotropic covariance model

model <- RMnonstwm(nu=RMexp())
C <- RFcovmatrix(model=model, x=X)
# yields covariance matrix C(xi,xj) for i,j=1,2,3,4,5
C
}
FinalizeExample()

Run the code above in your browser using DataLab