The mig
package
provides utilities for kernel density estimation for random vectors
using the multivariate inverse Gaussian distribution defined over the
half space ℋd(β) = {x ∈ ℝd : β⊤x > 0}
with location vector ξ, scale matrix Ω, whose density is
Minami (2003) provides a constructive characterization of the inverse Gaussian as the hitting time of a particular hyperplane by a correlated Brownian motion, simulation requires discretization of the latter, and more accurate simulations come at increased costs.
Let β ∈ ℝd be the vector defining the halfspace and consider a (d − 1) × d matrix Q2, such that Q2⊤β = 0d − 1 and Q2Q2⊤ = Id − 1. Theorem 1 (3) of Minami (2003) implies that, for $\mathbf{Q} = (\boldsymbol{\beta}, \mathbf{Q}_2^\top)\vphantom{Q}^{\top}$ and we have Q−1Z ∼ MIG(β, ξ, Ω).
Consider the symmetric orthogonal projection matrix Mβ = Id − ββ⊤/(β⊤β) of rank d − 1 due to the linear dependency. We build Q2 from the set of d − 1 eigenvectors associated to the non-zero eigenvalues of Mβ. We can then perform forward sampling of Z1 and Z2 ∣ Z1 and compute the resulting vectors.
# Create projection matrix onto the orthogonal complement of beta
d <- 5L # dimension of vector
n <- 1e4L # number of simulations
beta <- rexp(d)
xi <- rexp(d)
Omega <- matrix(0.5, d, d) + diag(d)
# Project onto orthogonal complement of vector
Mbeta <- (diag(d) - tcrossprod(beta)/(sum(beta^2)))
# Matrix is rank-deficient: compute eigendecomposition
# Shed matrix to remove the eigenvector corresponding to the 0 eigenvalue
Q2 <- t(eigen(Mbeta, symmetric = TRUE)$vectors[,-d])
# Check Q2 satisfies the conditions
all.equal(rep(0, d-1), c(Q2 %*% beta)) # check orthogonality
#> [1] TRUE
all.equal(diag(d-1), tcrossprod(Q2)) # check basis is orthonormal
#> [1] TRUE
Qmat <- rbind(beta, Q2)
covmat <- solve(Q2 %*% solve(Omega) %*% t(Q2))
# Compute mean and variance for Z1
mu <- sum(beta*xi)
omega <- sum(beta * c(Omega %*% beta))
Z1 <- rmig(n = n, xi = mu, Omega = omega) # uses statmod, with mean = mu and shape mu^2/omega
# Generate Gaussian vectors in two-steps (vectorized operations)
Z2 <- sweep(TruncatedNormal::rtmvnorm(n = n, mu = rep(0, d-1), sigma = covmat), 1, sqrt(Z1), "*")
Z2 <- sweep(Z2, 2, c(Q2 %*% xi), "+") + tcrossprod(Z1 - mu, c(Q2 %*% c(Omega %*% beta)/omega))
# Compute inverse of Q matrix (it is actually invertible)
samp <- t(solve(Qmat) %*% t(cbind(Z1, Z2)))
# Check properties
mle <- mig::fit_mig(samp, beta = beta)
max(abs(mle$xi - xi))
#> [1] 0.04382827
norm(mle$Omega - Omega, type = "f")
#> [1] 0.135372
max(abs(1 - mle$Omega/Omega))
#> [1] 0.08564657