Learn R Programming

excursions (version 2.0.6)

tricontour: Calculate contour curves on a triangulation

Description

Calculates contour curves on a triangulation

Usage

tricontour(x, z, nlevels = 10,
           levels = pretty(range(z, na.rm = TRUE), nlevels),
           ...)
## S3 method for class 'inla.mesh':
tricontour(x, z, nlevels = 10,
           levels = pretty(range(z, na.rm = TRUE), nlevels),
           ...)
## S3 method for class 'matrix':
tricontour(x, z, nlevels = 10,
           levels = pretty(range(z, na.rm = TRUE), nlevels),
           loc,
           ...)
## S3 method for class 'list':
tricontour(x, z, nlevels = 10,
           levels = pretty(range(z, na.rm = TRUE), nlevels),
           loc,
           type=c("+", "-"), tol=1e-7,
           ...)

Arguments

x
An object generated by a call to inla.mesh.2d or inla.mesh.create, a triangle-vertex index matrix, or a list of triangulation information, list(loc, graph=list(tv)).
z
a vector containing the values to be contoured (NAs are allowed).
nlevels
number of contour levels desired if and only if levels is not supplied.
levels
numeric vector of levels at which to calculate contour lines.
loc
coordinate matrix, to be supplied when x is given as a triangle-vertex index matrix only.
type
"+" or "-", indicating positive or negative association. For +, the generated contours enclose regions where $u_1 \leq z < u_2$, for - the regions fulfil $u_1 < z \leq u_2$.
tol
tolerance for determining if the value at a vertex lies on a level.
...
Additional arguments passed to the other methods.

Value

  • A list:
  • locA coordinate matrix
  • idxContour segment indexs, as a 2-column matrix, each row indexing a single segment
  • grpA vector of group labels. Each segment has a label, in 1,...,nlevels*2+1, where even labels indicate interior on-level contour segments, and odd labels indicate boundary segments between levels.

Examples

Run this code
if (require(INLA)) {
 #Generate mesh and SPDE model
  n.lattice = 20 #increase for more interesting, but slower, examples
  x=seq(from=0,to=10,length.out=n.lattice)
  lattice=inla.mesh.lattice(x=x,y=x)
  mesh=inla.mesh.create(lattice=lattice, extend=FALSE, refine=FALSE)
  spde <- inla.spde2.matern(mesh, alpha=2)

  #Generate an artificial sample
  sigma2.e = 0.01
  n.obs=1000
  obs.loc = cbind(runif(n.obs)*diff(range(x))+min(x),
                  runif(n.obs)*diff(range(x))+min(x))
  Q = inla.spde2.precision(spde, theta=c(log(sqrt(0.5)), log(sqrt(1))))
  x = inla.qsample(Q=Q)
  A = inla.spde.make.A(mesh=mesh,loc=obs.loc)
  Y = as.vector(A %*% x + rnorm(n.obs)*sqrt(sigma2.e))

  ## Calculate posterior
  Q.post = (Q + (t(A)%*%A)/sigma2.e)
  mu.post = as.vector(solve(Q.post,(t(A)%*%Y)/sigma2.e))
              
  ## Calculate continuous contours
  tric = tricontour(mesh, z=mu.post, levels=as.vector(quantile(x,c(0.25,0.75))))
}

Run the code above in your browser using DataLab