unif | R Documentation |
Density and simulation of the uniform distribution on S^{p-1} := {x \in R^p : ||x|| = 1}, p≥ 1. The density is just the inverse of the surface area of S^{p-1}, given by
ω_p := 2π^{p/2} / Γ(p/2).
d_unif_sphere(x, log = FALSE) r_unif_sphere(n, p) w_p(p, log = FALSE)
x |
locations in S^{p-1} to evaluate the density. Either a
matrix of size |
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. |
If p = 1, then S^{0} = \{-1, 1\} and the "surface area" is
2. The function w_p
is vectorized on p
.
Depending on the function:
d_unif_sphere
: a vector of length nx
or 1
with
the evaluated density at x
.
r_unif_sphere
: a matrix of size c(n, p)
with the
random sample.
w_p
: the surface area of S^{p-1}.
Eduardo García-Portugués, Davy Paindaveine, and Thomas Verdebout.
## 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.