unif_stat_MC | R Documentation |
Utility for performing Monte Carlo simulation of several
statistics for assessing uniformity on the (hyper)sphere
S^{p-1}:=\{{\bf x}\in R^p:||{\bf x}||=1\}
, p\ge 2
.
unif_stat_MC
provides a convenient wrapper for parallel
evaluation of unif_stat
, the estimation of critical values under the
null distribution, and the computation of empirical powers under the
alternative.
unif_stat_MC(n, type = "all", p, M = 10000, r_H1 = NULL,
crit_val = NULL, alpha = c(0.1, 0.05, 0.01), return_stats = TRUE,
stats_sorted = FALSE, chunks = ceiling((n * M)/1e+05), cores = 1,
seeds = NULL, CCF09_dirs = NULL, CJ12_reg = 3, cov_a = 2 * pi,
Cressie_t = 1/3, K_CCF09 = 25, Poisson_rho = 0.5, Pycke_q = 0.5,
Rayleigh_m = 1, Riesz_s = 1, Rothman_t = 1/3, Sobolev_vk2 = c(0, 0,
1), Softmax_kappa = 1, Stereo_a = 0, ...)
n |
sample size. |
type |
type of test to be applied. A character vector containing any of
the following types of tests, depending on the dimension
If |
p |
integer giving the dimension of the ambient space |
M |
number of Monte Carlo replications. Defaults to |
r_H1 |
if provided, the computation of empirical powers is
carried out for the alternative hypothesis sampled with |
crit_val |
if provided, must be the critical values as returned by
|
alpha |
vector with significance levels. Defaults to
|
return_stats |
return the Monte Carlo statistics? If only the critical
values or powers are desired, |
stats_sorted |
sort the returned Monte Carlo statistics? If
|
chunks |
number of chunks to split the |
cores |
number of cores to perform the simulation. Defaults to |
seeds |
if provided, a vector of size |
CCF09_dirs |
a matrix of size |
CJ12_reg |
type of asymptotic regime for CJ12 test, either |
cov_a |
|
Cressie_t |
|
K_CCF09 |
integer giving the truncation of the series present in the
asymptotic distribution of the Kolmogorov-Smirnov statistic. Defaults to
|
Poisson_rho |
|
Pycke_q |
|
Rayleigh_m |
integer |
Riesz_s |
|
Rothman_t |
|
Sobolev_vk2 |
weights for the finite Sobolev test. A non-negative
vector or matrix. Defaults to |
Softmax_kappa |
|
Stereo_a |
|
... |
optional arguments to be passed to the |
It is possible to have a progress bar if unif_stat_MC
is wrapped with
progressr::with_progress
or if
progressr::handlers(global = TRUE)
is invoked (once) by the user.
See the examples below. The progress bar is updated with the number of
finished chunks.
All the tests reject for large values of the test statistic
(max_gap = TRUE
is assumed for the Range test), so the critical
values for the significance levels alpha
correspond to the
alpha
-upper quantiles of the null distribution of the test statistic.
The Monte Carlo simulation for the CCF09 test is made conditionally
on the choice of CCF09_dirs
. That is, all the Monte Carlo statistics
share the same random directions.
Except for CCF09_dirs
, K_CCF09
, and CJ12_reg
, all the
test-specific parameters are vectorized.
A list with the following entries:
crit_val_MC
: a data frame of size
c(length(alpha), length(type))
, with column names given by
type
and rows corresponding to the significance levels alpha
,
that contains the estimated critical values of the tests.
power_MC
: a data frame of size
c(nrow(crit_val), length(type))
, with column names given by
type
and rows corresponding to the significance levels of
crit_val
, that contains the empirical powers of the tests. NA
if crit_val = NULL
.
stats_MC
: a data frame of size c(M, length(type))
, with
column names given by type
, that contains the Monte Carlo
statistics.
## Critical values
# Single statistic, specific alpha
cir <- unif_stat_MC(n = 10, M = 1e2, type = "Ajne", p = 2, alpha = 0.15)
summary(cir$stats_MC)
cir$crit_val_MC
# All circular statistics
cir <- unif_stat_MC(n = 10, M = 1e2, p = 2)
head(cir$stats_MC)
cir$crit_val_MC
# All spherical statistics
sph <- unif_stat_MC(n = 10, M = 1e2, p = 3)
head(sph$stats_MC)
sph$crit_val_MC
## Using a progress bar
# Define a progress bar
require(progress)
require(progressr)
handlers(handler_progress(
format = paste("(:spin) [:bar] :percent Iter: :current/:total Rate:",
":tick_rate iter/sec ETA: :eta Elapsed: :elapsedfull"),
clear = FALSE))
# Call unif_stat_MC() within with_progress()
with_progress(unif_stat_MC(n = 10, M = 1e2, p = 3, chunks = 10))
# With several cores
with_progress(unif_stat_MC(n = 10, M = 1e2, p = 3, chunks = 10, cores = 2))
# Instead of using with_progress() each time, it is more practical to run
# handlers(global = TRUE)
# once to activate progress bars in your R session
## Power computation
# Single statistic
cir_pow <- unif_stat_MC(n = 10, M = 1e2, type = "Ajne", p = 2,
crit_val = cir$crit_val_MC)
cir_pow$crit_val_MC
cir_pow$power_MC
# All circular statistics
cir_pow <- unif_stat_MC(n = 10, M = 1e2, p = 2, crit_val = cir$crit_val_MC)
cir_pow$crit_val_MC
cir_pow$power_MC
# All spherical statistics
sph_pow <- unif_stat_MC(n = 10, M = 1e2, p = 3, crit_val = sph$crit_val_MC)
sph_pow$crit_val_MC
sph_pow$power_MC
## Custom r_H1
# Circular
r_H1 <- function(n, p, M, l = 0.05) {
stopifnot(p == 2)
Theta_to_X(matrix(runif(n * M, 0, (2 - l) * pi), n, M))
}
dirs <- r_unif_sph(n = 5, p = 2, M = 1)[, , 1]
cir <- unif_stat_MC(n = 50, M = 1e2, p = 2, CCF09_dirs = dirs)
cir_pow <- unif_stat_MC(n = 50, M = 1e2, p = 2, r_H1 = r_H1, l = 0.10,
crit_val = cir$crit_val_MC, CCF09_dirs = dirs)
cir_pow$crit_val_MC
cir_pow$power_MC
# Spherical
r_H1 <- function(n, p, M, l = 0.5) {
samp <- array(dim = c(n, p, M))
for (j in 1:M) {
samp[, , j] <- mvtnorm::rmvnorm(n = n, mean = c(l, rep(0, p - 1)),
sigma = diag(rep(1, p)))
samp[, , j] <- samp[, , j] / sqrt(rowSums(samp[, , j]^2))
}
return(samp)
}
dirs <- r_unif_sph(n = 5, p = 3, M = 1)[, , 1]
sph <- unif_stat_MC(n = 50, M = 1e2, p = 3, CCF09_dirs = dirs)
sph_pow <- unif_stat_MC(n = 50, M = 1e2, p = 3, r_H1 = r_H1, l = 0.5,
crit_val = sph$crit_val_MC, CCF09_dirs = dirs)
sph_pow$power_MC
## Pre-built r_H1
# Circular
dirs <- r_unif_sph(n = 5, p = 2, M = 1)[, , 1]
cir_pow <- unif_stat_MC(n = 50, M = 1e2, p = 2, r_H1 = r_alt, alt = "vMF",
kappa = 1, crit_val = cir$crit_val_MC,
CCF09_dirs = dirs)
cir_pow$power_MC
# Spherical
dirs <- r_unif_sph(n = 5, p = 3, M = 1)[, , 1]
sph_pow <- unif_stat_MC(n = 50, M = 1e2, p = 3, r_H1 = r_alt, alt = "vMF",
kappa = 1, crit_val = sph$crit_val_MC,
CCF09_dirs = dirs)
sph_pow$power_MC
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.