diff --git a/DESCRIPTION b/DESCRIPTION index 9960402..459a3f9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,7 +54,8 @@ Imports: magrittr, flipr, cli, - withr + withr, + furrr RoxygenNote: 7.1.2 Roxygen: list(markdown = TRUE) URL: https://astamm.github.io/nevada/, https://github.com/astamm/nevada/ diff --git a/R/simulations.R b/R/simulations.R index 3307b13..3ba0597 100644 --- a/R/simulations.R +++ b/R/simulations.R @@ -56,32 +56,35 @@ power2 <- function(model1 = "gnp", model2 = "k_regular", if (!is.null(seed)) withr::local_seed(seed) - pvalues <- replicate( - R, - test2_global( - x = nvd( - model = model1, - n = n1, - num_vertices = num_vertices, - model_params = model1_params, - seed = NULL - ), - y = nvd( - model = model2, - n = n2, - num_vertices = num_vertices, - model_params = model2_params, - seed = NULL - ), - representation = representation, - distance = distance, - stats = stats, - B = B, - test = test, - k = k, - seed = 1234 - )$pvalue - ) + pvalues_function <- function(R) { + test_function <- function(x){ + test2_global( + x = nvd( + model = model1, + n = n1, + num_vertices = num_vertices, + model_params = model1_params, + seed = NULL + ), + y = nvd( + model = model2, + n = n2, + num_vertices = num_vertices, + model_params = model2_params, + seed = NULL + ), + representation = representation, + distance = distance, + stats = stats, + B = B, + test = test, + k = k, + seed = 1234 + )$pvalue + } + y <- furrr::future_map_dbl(1:R, test_function, .options = furrr::furrr_options(seed = TRUE)) + } + pvalues <- pvalues_function(R) mean(pvalues <= alpha) }