set.seed(123)
# Simulate two groups with different means but same covariance
if (requireNamespace("MASS", quietly = TRUE)) {
X1 = MASS::mvrnorm(20, mu=rep(0, 10), Sigma=diag(10))
X2 = MASS::mvrnorm(35, mu=rep(2, 10), Sigma=diag(10))
Data = rbind(X1, X2)
grp = factor(c(rep("A", nrow(X1)), rep("B", nrow(X2))))
# Sequential processing
# future::plan(future::sequential) # Default sequential processing
# Parallel processing (uncomment to use)
# future::plan(future::multisession, workers = 2) # Use 2 workers
# Bootstrap multivariate variance
boot_res = disparity_resample(
Data, group=grp, n_resamples=200,
statistic="multivariate_variance",
bootstrap_rarefaction="bootstrap"
)
# Direct access to results table
boot_res$results
# Using the print method for formatted output
print(boot_res)
# Using the plot method to visualize results
# plot(boot_res) # Uncomment to create confidence interval plot
# Rarefaction (to the smallest group size) of mean pairwise
# Euclidean distance
rar_res = disparity_resample(
Data, group=grp, n_resamples=200,
statistic="mean_pairwise_euclidean_distance",
bootstrap_rarefaction="rarefaction", sample_size="smallest"
)
# Now simulate a third group with larger variance
X3 = MASS::mvrnorm(15, mu=rep(0, 10), Sigma=diag(10)*1.5)
grp2 = factor(
c(rep("A", nrow(X1)), rep("B", nrow(X2)), rep("C", nrow(X3)))
)
boot_res2 = disparity_resample(
Data=rbind(X1, X2, X3), group=grp2, n_resamples=1000,
statistic="multivariate_variance",
bootstrap_rarefaction="bootstrap"
)
print(boot_res2)
# plot(boot_res2)
# Plot of the obtained (95%) confidence intervals (uncomment to plot)
# Reset to sequential processing when done (optional)
# future::plan(future::sequential)
}
Run the code above in your browser using DataLab