init.quad: Q-dimensional grid of quadrature points.

Description Usage Arguments Details Value See Also Examples

Description

Creates a flattened, rotated grid that incorporates correlation through an eigenvalue decomposition of the covariance matrix.

Usage

1
2
init.quad(Q = 2, prior = list(mu = rep(0, Q), Sigma = diag(Q)),
  adapt = NULL, ip = 6, prune = FALSE, forcePD = FALSE, debug = FALSE)

Arguments

Q

Number of dimensions. Defaults to 2. Only required when mu and Sigma are not provided.

prior

List of prior mean mu, = vector, and covariance matrix Sigma = matrix, defaults to zero vector and identity matrix respectively.

adapt

List of adaptive mean mu, = vector, and covariance matrix Sigma = matrix, if NULL no adaptation is used. Defaults to NULL.

ip

Number of quadrature points per dimension. Defaults to 6. Note that the total number of quadrature points is ip^Q.

prune

Logical, should quadrature points with a very low weight be removed? Defaults to false. See details.

forcePD

Logical, should adapt and prior arguments be forced to the neares positive definite matrix - if not already PD? If TRUE (Default: FALSE), nearPD is used to arrive at the closest PD matrix.

debug

Logical, draws debugging plots when true.

Details

Creates a Q-dimensional grid by calling expand.grid on Q vectors of unidimensional quadrature points obtained with gaussHermiteData. The grid is then corrected for a prior distribution, and can optionally be adapted around a previous estimate. The resultant grid can be pruned to remove quadrature points that are unlikely to add information.

Value

A list with a matrix X of ip^Q by Q quadrature points and a vector W of length ip^Q associated weights.

See Also

gaussHermiteData, used to create unidimensional quadrature points, and eval.quad for evaluating the integral.

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
### basic quadrature grid /w pruning.
mu <- c(0,0)
sigma <- matrix(c(1,.5,.5,1),2,2)
grid <- init.quad(Q = 2, prior = list(mu = mu, Sigma = sigma), ip = 10, prune = FALSE)
grid2 <- init.quad(Q = 2, prior = list(mu = mu, Sigma = sigma), ip = 10, prune = TRUE)
library(mvtnorm)
normal <- rmvnorm(1000, mu, sigma)
# noise
plot(normal, xlim = c(-6,6), ylim = c(-6,6), pch = 19, col = rgb(0,0,0,.5))
# full quad grid
points(grid$X, cex = exp(grid$W)/max(exp(grid$W))*4, col = 'red', pch = 20)
# pruned quad grid
points(grid2$X, cex = exp(grid2$W)/max(exp(grid2$W))*4, col = 'green', pch = 20)


### Adaptive quadrature grid
prior <- list(mu = c(0,0), Sigma = matrix(c(1,.5,.5,1),2,2))
adapt <- list(mu = c(-2,2), Sigma = prior$Sigma / 2)
grid <- init.quad(Q = 2, prior, ip = 10, prune = FALSE)
library(mvtnorm)
normal <- rmvnorm(1000, adapt$mu, adapt$Sigma)
# noise, centered at (-2, 2)
plot(normal, xlim = c(-6,6), ylim = c(-6,6), pch = 19, col = rgb(0,0,0,.5))
# initial quad grid, centered at (0, 0)
points(grid$X, cex = exp(grid$W)/max(exp(grid$W))*4, col = 'red', pch = 20)
# adapted grid
grid2 <- init.quad(Q =2, prior, adapt = adapt, ip = 10, prune = TRUE)
points(grid2$X, cex = exp(grid2$W)/max(exp(grid2$W))*4, col = 'green', pch = 20)
# the grid is adapted to the latest estimate, but weighted towards the prior 

MultiGHQuad documentation built on May 2, 2019, 3:42 a.m.