View source: R/svem_significance_test_parallel.R
svem_significance_test_parallel | R Documentation |
Whole-model significance test using SVEM with support for mixture factor groups, parallelizing the SVEM fits for originals and permutations.
svem_significance_test_parallel(
formula,
data,
mixture_groups = NULL,
nPoint = 2000,
nSVEM = 10,
nPerm = 150,
percent = 90,
nBoot = 100,
glmnet_alpha = c(1),
weight_scheme = c("SVEM"),
objective = c("auto", "wAIC", "wBIC", "wGIC", "wSSE"),
auto_ratio_cutoff = 1.3,
gamma = 2,
relaxed = FALSE,
verbose = TRUE,
nCore = parallel::detectCores(),
seed = NULL,
...
)
formula |
A formula specifying the model to be tested. |
data |
A data frame containing the variables in the model. |
mixture_groups |
Optional list describing one or more mixture factor
groups. Each element of the list should be a list with components
|
nPoint |
Number of random points in the factor space (default: 2000). |
nSVEM |
Number of SVEM fits on the original data (default: 10). |
nPerm |
Number of SVEM fits on permuted responses for the reference distribution (default: 150). |
percent |
Percentage of variance to capture in the SVD (default: 90). |
nBoot |
Number of bootstrap iterations within each SVEM fit (default: 100). |
glmnet_alpha |
The alpha parameter(s) for glmnet (default: |
weight_scheme |
Weighting scheme for SVEM (default: "SVEM"). |
objective |
Objective used inside |
auto_ratio_cutoff |
Single cutoff for the automatic rule when
|
gamma |
Penalty weight used only when |
relaxed |
Logical; default |
verbose |
Logical; if |
nCore |
Number of CPU cores for parallel processing (default: all available cores). |
seed |
Optional integer seed for reproducible parallel RNG (default: NULL). |
... |
Additional arguments passed to |
Identical in logic to svem_significance_test()
but runs the expensive
SVEM refits in parallel using foreach
+ doParallel
. Random draws
(including permutations) use RNGkind("L'Ecuyer-CMRG")
for parallel-suitable streams.
A list of class svem_significance_test
containing the test results.
svem_significance_test
set.seed(1)
# Small toy data with a 3-component mixture A, B, C
n <- 40
sample_trunc_dirichlet <- function(n, lower, upper, total) {
k <- length(lower)
stopifnot(length(upper) == k, total >= sum(lower), total <= sum(upper))
avail <- total - sum(lower)
if (avail <= 0) return(matrix(rep(lower, each = n), nrow = n))
out <- matrix(NA_real_, n, k)
i <- 1L
while (i <= n) {
g <- rgamma(k, 1, 1)
w <- g / sum(g)
x <- lower + avail * w
if (all(x <= upper + 1e-12)) { out[i, ] <- x; i <- i + 1L }
}
out
}
lower <- c(0.10, 0.20, 0.05)
upper <- c(0.60, 0.70, 0.50)
total <- 1.0
ABC <- sample_trunc_dirichlet(n, lower, upper, total)
A <- ABC[, 1]; B <- ABC[, 2]; C <- ABC[, 3]
X <- runif(n)
F <- factor(sample(c("red", "blue"), n, replace = TRUE))
y <- 2 + 3*A + 1.5*B + 1.2*C + 0.5*X + 1*(F == "red") + rnorm(n, sd = 0.3)
dat <- data.frame(y = y, A = A, B = B, C = C, X = X, F = F)
mix_spec <- list(list(
vars = c("A", "B", "C"),
lower = lower,
upper = upper,
total = total
))
# Parallel significance test (default relaxed = FALSE)
res <- svem_significance_test_parallel(
y ~ A + B + C + X + F,
data = dat,
mixture_groups = mix_spec,
glmnet_alpha = c(1),
weight_scheme = "SVEM",
objective = "auto",
auto_ratio_cutoff = 1.3,
relaxed = FALSE, # default, shown for clarity
nCore = 2,
seed = 123,
verbose = FALSE
)
print(res$p_value)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.