Last chance! 50% off unlimited learning
Sale ends in
Density and simulation of a distribution on
Gamma_theta
.
The tangent-normal decomposition can be employed for constructing
distributions for
d_tang_norm(x, theta, g_scaled, d_V, d_U, log = FALSE)r_tang_norm(n, theta, r_U, r_V)
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.
locations in c(nx, p)
or a vector of length p
. Normalized
internally if required (with a warning
message).
a unit norm vector of size p
giving the axis of
rotational symmetry.
the scaled angular density g_scaled <- function(t, log = TRUE) {...}
. See examples.
the density d_V <- function(v, log = TRUE) {...}
. See examples.
the density d_U <- function(u, log = TRUE) {...}
. See examples.
flag to indicate if the logarithm of the density (or the normalizing constant) is to be computed.
sample size, a positive integer.
a function for simulating
a function for simulating
Eduardo García-Portugués, Davy Paindaveine, and Thomas Verdebout.
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
The normalizing constants and densities are computed through log-scales for numerical accuracy.
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. 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 - 1, kappa = kappa_V, scaled = TRUE, log = log)
}
# Cosine density for the vMF distribution
d_V <- function(v, log) {
log_dens <- g_scaled(v, log = log) + (p - 3)/2 * 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)
if (requireNamespace("rgl")) {
rgl::plot3d(x, col = col[rank(dens)], size = 5)
}
## A non-vMF angular function: g(t) = 1 - t^2. It is sssociated 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
if (requireNamespace("rgl")) {
rgl::plot3d(x, col = col[rank(dens)], size = 5)
}
Run the code above in your browser using DataLab