if(require("TDAstats"))
{
# create two groups of diagrams
D1 <- TDAstats::calculate_homology(TDAstats::circle2d[sample(1:100,10),],
dim = 0,threshold = 2)
D2 <- TDAstats::calculate_homology(TDAstats::circle2d[sample(1:100,10),],
dim = 0,threshold = 2)
g1 <- list(D1,D2)
g2 <- list(D1,D2)
# run test in dimension 0 with 1 iteration, note that the TDA package function
# "permutation_test" can mask TDApplied's function, so we will specify explicitly
# which function we are using
perm_test <- TDApplied::permutation_test(g1,g2,iterations = 1,
num_workers = 2,
dims = c(0))
# repeat with precomputed distance matrix, gives similar results
# (same but the randomness of the permutations can give small differences)
# just much faster
D <- distance_matrix(diagrams = list(D1,D2,D1,D2),dim = 0,
num_workers = 2)
perm_test <- TDApplied::permutation_test(dist_mats = list(D),group_sizes = c(2,2),
dims = c(0))
}
Run the code above in your browser using DataLab