unif {rotasym}R Documentation

Uniform distribution on the hypersphere

Description

Density and simulation of the uniform distribution on S^{p-1}:=\{\mathbf{x}\in R^p:||\mathbf{x}||=1\}, p\ge 1. The density is just the inverse of the surface area of S^{p-1}, given by

\omega_p:=2\pi^{p/2}/\Gamma(p/2).

Usage

d_unif_sphere(x, log = FALSE)

r_unif_sphere(n, p)

w_p(p, log = FALSE)

Arguments

x

locations in S^{p-1} to evaluate the density. Either a matrix of size c(nx, p) or a vector of length p. Normalized internally if required (with a warning message).

log

flag to indicate if the logarithm of the density (or the normalizing constant) is to be computed.

n

sample size, a positive integer.

p

dimension of the ambient space R^p that contains S^{p-1}. A positive integer.

Details

If p = 1, then S^{0} = \{-1, 1\} and the "surface area" is 2. The function w_p is vectorized on p.

Value

Depending on the function:

Author(s)

Eduardo García-Portugués, Davy Paindaveine, and Thomas Verdebout.

Examples

## Area of S^{p - 1}

# Areas of S^0, S^1, and S^2
w_p(p = 1:3)

# Area as a function of p
p <- 1:20
plot(p, w_p(p = p), type = "o", pch = 16, xlab = "p", ylab = "Area",
     main = expression("Surface area of " * S^{p - 1}), axes = FALSE)
box()
axis(1, at = p)
axis(2, at = seq(0, 34, by = 2))

## Simulation and density evaluation for p = 1, 2, 3

# p = 1
n <- 500
x <- r_unif_sphere(n = n, p = 1)
barplot(table(x) / n)
head(d_unif_sphere(x))

# p = 2
x <- r_unif_sphere(n = n, p = 3)
plot(x)
head(d_unif_sphere(x))

# p = 3
x <- r_unif_sphere(n = n, p = 3)
if (requireNamespace("rgl")) {
  rgl::plot3d(x)
}
head(d_unif_sphere(x))

[Package rotasym version 1.1.5 Index]