evalCovFuns: Compute Covariance Function

Description Usage Arguments Value Author(s) See Also Examples

Description

Computes covariance functions (excluding nugget) for a given vector or matrix of distances.

Usage

1
2
evalCovFuns(type = "exp", pars = c(1, 1), d = seq(0, 10, length.out =
  100), diff = c(0, 0))

Arguments

type

Name of covariance functions, see namesCovFuns.

pars

Parameter for the covariance function, see parsCovFuns.

d

Vector/matrix for which to compute the covariance function.

diff

Vector with two components indicating with respect to which parameter(s) that first and/or second derivatives should be computed. E.g. diff=c(0,0) indicates no derivatives, diff=c(1,0) indicates first derivative wrt the first parameter, diff=c(1,2) indicates second cross derivative wrt the first and second parameters, etc.

Value

Covariance function computed for all elements in d.

Author(s)

Johan Lindstrom

See Also

Other covariance functions: crossDist, makeSigmaB, makeSigmaNu, namesCovFuns, parsCovFuns, updateCovf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
##vector of distances
d <- seq(0,10,length.out=1e4);
##just the simplest case (exponential, range=2, sill=0.7)
plot(d, evalCovFuns("exp", c(2,0.7), d), type="l")
     
##create list of ranges
range <- c(1, 2, 3.5, 5);
##list names
name <- list("exp", "exp2", "cubic", "spherical", "cauchy", "cauchy",
             "matern", "matern")
##and list of shapes
shape <- c(vector("list",4), list(1, 5, .25, 5))

##matrix holding results
covf <- array(NA,c(length(d),length(name),length(range)))

##compute a few covariance functions
for(i in 1:length(name)){
  for(j in 1:length(range)){
    pars <- c(range[j],1,shape[[i]])
    covf[,i,j] <- evalCovFuns(name[[i]], pars, d)
  }
}

##plot the covariance function for comparison
par(mfrow=c(2,2))
for(j in 1:length(range)){
  plot(0, 0, type="n", main=range[j],
       xlim=range(d), ylim=range(covf[,,j],na.rm=TRUE))
  for(i in 1:length(name)){
    lines(d, covf[,i,j], col=i)
  }
  abline(v=range[j])
  if(j==1){
    legend("topright", lty=1, col=1:length(name),
           legend=paste("covf:", sapply(name,as.character),
			sapply(shape, function(x){
				      if(is.null(x)){""}else{as.character(x)} })))
  }
}

SpatioTemporal documentation built on May 2, 2019, 8:49 a.m.