computeV: Compute Covariance Matrix

Description Usage Arguments Author(s) Examples

Description

Observations are averages over congruent rectangular plots that like in a lattice. For extensive observations one needs to multiply the matrix by the $area^2$ where $area$ is the common area of each plot.

Various different classes of covariance functions, generalised covariance functions and their derivatives wrt parameters are built into this library. These include the Cauchy and Mat\'ern covariance functions as well as specific sub models such as the Bessel$_0$, Exponential, Bessel$_1$, spline and logarithmic covariance functions.

Usage

1
2
3
computeV(info, class = "ldt", params, rel.tol = .Machine$double.eps^0.25,
         abs.tol = rel.tol, cat.level = 0, K = NULL)
 

Arguments

info

Result of the precompute stage

class

The class of covariance functions,"ldt", "bess0", "exp", "bess1", "power", "powerNI", "matern", "spline", "cauchy". Can also be used to compute the derivatives of the covariance matrices for specific models, for example "dbess0", "dexp", "dexp2", "dbess1", "dpowerNI". Can also be used for any isotropic function K, simply define a function K in the workspace that has two arguments, distance and a vector of parameters. Then call computeV with class="special".

params

Parameters that go with a specific class of models, for the "matern" class it requires an inverse range parameter and a smoothness parameter, for example params=c(1,0.5), this corresponds to the case when class="exp", params=c(1).

rel.tol

Relative Tolerance for one dimensional numerical integration

abs.tol

Absolute Tolerance for one dimensional numerical integration

cat.level

Controls level of time output, takes values 0, 0.5, 1

K

If class="misc" pass your own covariance function K here, see example below

Author(s)

David Clifford

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
## Example for extensive variables - variances of combined plots
library(spatialCovariance)
nrows <- 1
ncols <- 2
rowwidth <- 1.1
colwidth <- 1.2
rowsep <- 0
colsep <- 0

info <- precompute(nrows,ncols,rowwidth,colwidth,rowsep,colsep)
V <- computeV(info,class="matern",params=c(1,1))

info2 <- precompute(nrows=1,ncols=1,rowwidth=rowwidth,colwidth=colwidth*2,0,0)
V2 <- computeV(info2,class="matern",params=c(1,1))

c(1,1) 

(rowwidth * (2*colwidth))^2 * V2

## Bring in anisotropy
V
info <- precompute.update(info,aniso=2)  ## geometric anisotropy update
V <- computeV(info,class="matern",params=c(1,1))
V
info <- precompute.update(info,aniso=5)  ## geometric anisotropy update
V

## Second Example - define your own covariance function, here we use a
## spherical one

library(spatialCovariance)

K <- function(d,params) {
  frac <- d/params
  ret <- rep(0,length(d))
  ind <- which(frac<1)
  if(length(ind)) ret[ind] <- (1 - 2/pi*(frac[ind]*sqrt(1 - frac[ind]^2) + asin(frac[ind])))
  return(ret)
}

dVals <- seq(0,10,l=1001)
plot(dVals,K(dVals,8),type="l")
lines(dVals,K(dVals,7),col=2)

nrows <- 1
ncols <- 3
rowwidth <- 2
colwidth <- 2
rowsep <- 0
colsep <- 0

info <- precompute(nrows,ncols,rowwidth,colwidth,rowsep,colsep)
V <- computeV(info,class="misc",params=c(8),K=K)
V

## Now if we have a low value of theta_2 we should see that the first
## and third plot are independent as there is a 2 unit gap between
## them, so that term in V will be zero
V <- computeV(info,class="misc",params=c(1),K=K)
V

## If theta_2 gets a little bigger than 2 then we should see no
## non-zero entries in V
V <- computeV(info,class="misc",params=c(2.005),K=K)
V

## Check V is positive definite
eigen(V)$values ## should all be positive

david-clifford/spatialCovariance documentation built on June 4, 2019, 11:29 p.m.