| tang-norm-decomp | R Documentation |
Density and simulation of a distribution on
\mathcal{S}^{p-1}:=\{\boldsymbol{x}\in
\mathbb{R}^p:\|\boldsymbol{x}\|=1\}, p\ge 2, obtained by the
tangent-normal decomposition. The tangent-normal decomposition of the
random vector \boldsymbol{X}\in \mathcal{S}^{p-1} is
V\boldsymbol{\theta} + \sqrt{1 -
V^2}\boldsymbol{\Gamma}_{\boldsymbol{\theta}}\boldsymbol{U}
where V := \boldsymbol{X}'\boldsymbol{\theta} is a random variable in
[-1, 1] (the cosines of \boldsymbol{X}) and
\boldsymbol{U} :=
\boldsymbol{\Gamma}_{\boldsymbol{\theta}}\boldsymbol{X}/
\|\boldsymbol{\Gamma}_{\boldsymbol{\theta}}\boldsymbol{X}\| is a random
vector in \mathcal{S}^{p-2} (the multivariate signs of
\boldsymbol{X}) and \boldsymbol{\Gamma}_{\boldsymbol{\theta}} is
the p\times(p-1) matrix computed by Gamma_theta.
The tangent-normal decomposition can be employed for constructing
distributions for \boldsymbol{X} that arise for certain choices of
V and \boldsymbol{U}. If V and \boldsymbol{U} are
independent, then simulation from \boldsymbol{X} is
straightforward using the tangent-normal decomposition. Also, the density of
\boldsymbol{X} at \boldsymbol{x}\in \mathcal{S}^{p-1},
f_{{X}}(\boldsymbol{x}), is readily computed as
f_{{X}}(\boldsymbol{x})= \omega_{p-1}c_g
g(t)(1-t^2)^{(p-3)/2}f_{{U}}(\boldsymbol{u})
where t:=\boldsymbol{x}'\boldsymbol{\theta},
\boldsymbol{u}:=\boldsymbol{\Gamma}_{\boldsymbol{\theta}}\boldsymbol{x}/
\|\boldsymbol{\Gamma}_{\boldsymbol{\theta}}\boldsymbol{x}\|, f_{{U}}
is the density of \boldsymbol{U}, and
f_V(v) := \omega_{p-1} c_g g(v) (1 - v^2)^{(p-3)/2} is the density of
V for an angular function g with normalizing constant c_g.
\omega_{p-1} is the surface area of \mathcal{S}^{p-2}.
d_tang_norm(x, theta, g_scaled, d_V, d_U, log = FALSE)
r_tang_norm(n, theta, r_U, r_V)
x |
locations in |
theta |
a unit norm vector of size |
g_scaled |
the scaled angular density |
d_V |
the density |
d_U |
the density |
log |
flag to indicate if the logarithm of the density (or the normalizing constant) is to be computed. |
n |
sample size, a positive integer. |
r_U |
a function for simulating |
r_V |
a function for simulating |
Either g_scaled or d_V can be supplied to
d_tang_norm (the rest of the arguments are compulsory). One possible
choice for g_scaled is g_vMF with scaled = TRUE.
Another possible choice is the angular function g(t) = 1 - t^2,
normalized by its normalizing constant
c_g = (\Gamma(p/2) p) / (2\pi^{p/2} (p - 1)) (see examples). This
angular function makes V^2 to be distributed as a
\mathrm{Beta}(1/2,(p+1)/2).
The normalizing constants and densities are computed through log-scales for numerical accuracy.
Depending on the function:
d_tang_norm: a vector of length nx or 1 with the
evaluated density at x.
r_tang_norm: a matrix of size c(n, p) with the random
sample.
García-Portugués, E., Paindaveine, D., Verdebout, T. (2020) On optimal tests for rotational symmetry against new classes of hyperspherical distributions. Journal of the American Statistical Association, 115(532):1873–1887. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.2019.1665527")}
Gamma_theta, signs,
tangent-elliptical, tangent-vMF,
vMF.
## Simulation and density evaluation for p = 2
# Parameters
n <- 1e3
p <- 2
theta <- c(rep(0, p - 1), 1)
mu <- c(rep(0, p - 2), 1)
kappa_V <- 2
kappa_U <- 0.1
# The vMF scaled angular function
g_scaled <- function(t, log) {
g_vMF(t, p = p, kappa = kappa_V, scaled = TRUE, log = log)
}
# Cosine density for the vMF distribution
d_V <- function(v, log) {
log_dens <- w_p(p = p - 1, log = TRUE) + g_scaled(t = v, log = TRUE) +
0.5 * (p - 3) * log(1 - v^2)
switch(log + 1, exp(log_dens), log_dens)
}
# Multivariate signs density based on a vMF
d_U <- function(x, log) d_vMF(x = x, mu = mu, kappa = kappa_U, log = log)
# Simulation functions
r_V <- function(n) r_g_vMF(n = n, p = p, kappa = kappa_V)
r_U <- function(n) r_vMF(n = n, mu = mu, kappa = kappa_U)
# Sample and color according to density
x <- r_tang_norm(n = n, theta = theta, r_V = r_V, r_U = r_U)
r <- runif(n, 0.95, 1.05) # Radius perturbation to improve visualization
col <- viridisLite::viridis(n)
dens <- d_tang_norm(x = x, theta = theta, g_scaled = g_scaled, d_U = d_U)
# dens <- d_tang_norm(x = x, theta = theta, d_V = d_V, d_U = d_U) # The same
plot(r * x, pch = 16, col = col[rank(dens)])
## Simulation and density evaluation for p = 3
# Parameters
p <- 3
n <- 5e3
theta <- c(rep(0, p - 1), 1)
mu <- c(rep(0, p - 2), 1)
kappa_V <- 2
kappa_U <- 2
# Sample and color according to density
x <- r_tang_norm(n = n, theta = theta, r_V = r_V, r_U = r_U)
col <- viridisLite::viridis(n)
dens <- d_tang_norm(x = x, theta = theta, g_scaled = g_scaled, d_U = d_U)
scatterplot3d::scatterplot3d(x, xlim = c(-1, 1), ylim = c(-1, 1),
zlim = c(-1, 1), color = col[rank(dens)],
pch = 16, xlab = "", ylab = "", zlab = "",
angle = 20)
## A non-vMF angular function: g(t) = 1 - t^2. It is associated to the
## Beta(1/2, (p + 1)/2) distribution.
# Scaled angular function
g_scaled <- function(t, log) {
log_c_g <- lgamma(0.5 * p) + log(0.5 * p / (p - 1)) - 0.5 * p * log(pi)
log_g <- log_c_g + log(1 - t^2)
switch(log + 1, exp(log_g), log_g)
}
# Cosine density
d_V <- function(v, log) {
log_dens <- w_p(p = p - 1, log = TRUE) + g_scaled(t = v, log = TRUE) +
(0.5 * (p - 3)) * log(1 - v^2)
switch(log + 1, exp(log_dens), log_dens)
}
# Simulation
r_V <- function(n) {
sample(x = c(-1, 1), size = n, replace = TRUE) *
sqrt(rbeta(n = n, shape1 = 0.5, shape2 = 0.5 * (p + 1)))
}
# Sample and color according to density
r_U <- function(n) r_unif_sphere(n = n, p = p - 1)
x <- r_tang_norm(n = n, theta = theta, r_V = r_V, r_U = r_U)
col <- viridisLite::viridis(n)
dens <- d_tang_norm(x = x, theta = theta, d_V = d_V, d_U = d_unif_sphere)
# dens <- d_tang_norm(x = x, theta = theta, g_scaled = g_scaled,
# d_U = d_unif_sphere) # The same
scatterplot3d::scatterplot3d(x, xlim = c(-1, 1), ylim = c(-1, 1),
zlim = c(-1, 1), color = col[rank(dens)],
pch = 16, xlab = "", ylab = "", zlab = "",
angle = 20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.