Description Usage Arguments Value Author(s) Examples
Calculates contour curves and/or regions between them, for functions defined on a triangulation
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 69 70 71 72 73 74 75 76 77 78 | 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-07,
...
)
tricontourmap(
x,
z,
nlevels = 10,
levels = pretty(range(z, na.rm = TRUE), nlevels),
...
)
## S3 method for class 'inla.mesh'
tricontourmap(
x,
z,
nlevels = 10,
levels = pretty(range(z, na.rm = TRUE), nlevels),
...
)
## S3 method for class 'matrix'
tricontourmap(
x,
z,
nlevels = 10,
levels = pretty(range(z, na.rm = TRUE), nlevels),
loc,
...
)
## S3 method for class 'list'
tricontourmap(
x,
z,
nlevels = 10,
levels = pretty(range(z, na.rm = TRUE), nlevels),
loc,
type = c("+", "-"),
tol = 1e-07,
output = c("sp", "inla.mesh.segment"),
...
)
|
x |
An object generated by a call to |
z |
A vector containing the values to be contoured
( |
nlevels |
Number of contour levels desired, if and only if
|
levels |
Numeric vector of levels at which to calculate contour lines. |
... |
Additional arguments passed to the other methods. |
loc |
coordinate matrix, to be supplied when |
type |
|
tol |
tolerance for determining if the value at a vertex lies on a level. |
output |
The format of the generated output. Implemented options
are |
For tricontour
, a list some of the same fields that
inla.mesh.segment
objects have:
loc |
A coordinate matrix |
idx |
Contour segment indices, as a 2-column matrix, each row indexing a single segment |
grp |
A vector of group labels. Each segment has a label, in
|
For tricontourmap
, a list:
contour |
A list of |
map |
A list of |
Finn Lindgren finn.lindgren@gmail.com
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 | ## Not run:
if (require.nowarnings("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))))
## Discrete domain contours
map <- contourmap(n.levels = 2, mu = mu.post, Q = Q.post,
alpha=0.1, compute = list(F = FALSE), max.threads=1)
## Calculate continuous contour map
setsc <- tricontourmap(mesh, z = mu.post,
levels = as.vector(quantile(x, c(0.25, 0.75))))
## Plot the results
reo <- mesh$idx$lattice
idx.setsc <- setdiff(names(setsc$map), "-1")
cols2 <- contourmap.colors(map, col=heat.colors(100, 0.5),
credible.col = grey(0.5, 0))
names(cols2) <- as.character(-1:2)
par(mfrow = c(1,2))
image(matrix(mu.post[reo], n.lattice, n.lattice),
main = "mean", axes = FALSE)
plot(setsc$map[idx.setsc], col = cols2[idx.setsc])
par(mfrow = c(1,1))
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.