# enable txt progressbar
progressr::handlers("txtprogressbar")
# enable parallel computation
if (requireNamespace("future")) {
future::plan(future::multisession)
}
K <- 3
N <- 2
costm <- cost_matrix_lp(1:N)
# use higher number to better approximate null distribution and get more accurate p-value
num.sim <- 10
n <- c(300, 360, 200)
# underlying probability vectors
mu <- matrix(1 / N, K, N, TRUE)
# to run this, a LP solver must be available for ROI (ROI.plugin.glpk by default)
if (requireNamespace("ROI.plugin.glpk")) {
solver <- ot_test_lp_solver("glpk")
set.seed(123)
samples <- tab_sample(n, mu)
progressr::with_progress({
res <- ot_barycenter_test(samples, costm, num.sim = num.sim, solver = solver)
})
print(res)
}
# measures are not equal anymore
mu[2, ] <- 1:N / sum(1:N)
if (requireNamespace("ROI.plugin.glpk")) {
solver <- ot_test_lp_solver("glpk")
set.seed(123)
samples <- tab_sample(n, mu)
progressr::with_progress({
res2 <- ot_barycenter_test(samples, costm, num.sim = num.sim, solver = solver)
})
print(res2)
}
# \dontshow{
## R CMD check: make sure any open connections are closed afterward
if (requireNamespace("future") && !inherits(future::plan(), "sequential")) future::plan(future::sequential)
# }
Run the code above in your browser using DataLab