R Under development (unstable) (2024-04-27 r86487 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(ClassDiscovery) Loading required package: cluster Loading required package: oompaBase > suppressWarnings( RNGversion("3.5.3") ) > set.seed(147676) > # simulate data from two different groups > d1 <- matrix(rnorm(100*30, rnorm(100, 0.5)), nrow=100, ncol=30, byrow=FALSE) > d2 <- matrix(rnorm(100*20, rnorm(100, 0.5)), nrow=100, ncol=20, byrow=FALSE) > dd <- cbind(d1, d2) > cols <- rep(c('red', 'green'), times=c(30,20)) > # peform your basic hierarchical clustering... > hc <- hclust(distanceMatrix(dd, 'pearson'), method='complete') > > # bootstrap the clusters arising from hclust > bc <- PerturbationClusterTest(dd, cutHclust, nTimes=200, k=3, metric='pearson') [1] 100 [2] 100 [3] 100 [4] 100 [5] 100 [6] 100 [7] 100 [8] 100 [9] 100 [10] 100 [11] 100 [12] 100 [13] 100 [14] 100 [15] 100 [16] 100 [17] 100 [18] 100 [19] 100 [20] 100 [21] 100 [22] 100 [23] 100 [24] 100 [25] 100 [26] 100 [27] 100 [28] 100 [29] 100 [30] 100 [31] 100 [32] 100 [33] 100 [34] 100 [35] 100 [36] 100 [37] 100 [38] 100 [39] 100 [40] 100 [41] 100 [42] 100 [43] 100 [44] 100 [45] 100 [46] 100 [47] 100 [48] 100 [49] 100 [50] 100 [51] 100 [52] 100 [53] 100 [54] 100 [55] 100 [56] 100 [57] 100 [58] 100 [59] 100 [60] 100 [61] 100 [62] 100 [63] 100 [64] 100 [65] 100 [66] 100 [67] 100 [68] 100 [69] 100 [70] 100 [71] 100 [72] 100 [73] 100 [74] 100 [75] 100 [76] 100 [77] 100 [78] 100 [79] 100 [80] 100 [81] 100 [82] 100 [83] 100 [84] 100 [85] 100 [86] 100 [87] 100 [88] 100 [89] 100 [90] 100 [91] 100 [92] 100 [93] 100 [94] 100 [95] 100 [96] 100 [97] 100 [98] 100 [99] 100 [100] 100 [101] 100 [102] 100 [103] 100 [104] 100 [105] 100 [106] 100 [107] 100 [108] 100 [109] 100 [110] 100 [111] 100 [112] 100 [113] 100 [114] 100 [115] 100 [116] 100 [117] 100 [118] 100 [119] 100 [120] 100 [121] 100 [122] 100 [123] 100 [124] 100 [125] 100 [126] 100 [127] 100 [128] 100 [129] 100 [130] 100 [131] 100 [132] 100 [133] 100 [134] 100 [135] 100 [136] 100 [137] 100 [138] 100 [139] 100 [140] 100 [141] 100 [142] 100 [143] 100 [144] 100 [145] 100 [146] 100 [147] 100 [148] 100 [149] 100 [150] 100 [151] 100 [152] 100 [153] 100 [154] 100 [155] 100 [156] 100 [157] 100 [158] 100 [159] 100 [160] 100 [161] 100 [162] 100 [163] 100 [164] 100 [165] 100 [166] 100 [167] 100 [168] 100 [169] 100 [170] 100 [171] 100 [172] 100 [173] 100 [174] 100 [175] 100 [176] 100 [177] 100 [178] 100 [179] 100 [180] 100 [181] 100 [182] 100 [183] 100 [184] 100 [185] 100 [186] 100 [187] 100 [188] 100 [189] 100 [190] 100 [191] 100 [192] 100 [193] 100 [194] 100 [195] 100 [196] 100 [197] 100 [198] 100 [199] 100 [200] 100 > summary(bc) Number of perturbation samples: 200. Noise level: 1. A PerturbationClusterTest object. Call: PerturbationClusterTest(data = dd, FUN = cutHclust, nTimes = 200, k = 3, metric = "pearson") Agreement levels: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0000 0.0000 0.6750 0.4848 0.9700 1.0000 > > # look at the distribution of agreement scores > hist(bc, breaks=101) > > # let heatmap compute a new dendrogram from the agreement > image(bc, col=blueyellow(64), RowSideColors=cols, ColSideColors=cols) > > # plot the agreement matrix with the original dendrogram > image(bc, dendrogram=hc, col=blueyellow(64), RowSideColors=cols, ColSideColors=cols) > > # bootstrap the results of K-means > kmc <- PerturbationClusterTest(dd, cutPam, nTimes=200, k=3) [1] 100 [2] 100 [3] 100 [4] 100 [5] 100 [6] 100 [7] 100 [8] 100 [9] 100 [10] 100 [11] 100 [12] 100 [13] 100 [14] 100 [15] 100 [16] 100 [17] 100 [18] 100 [19] 100 [20] 100 [21] 100 [22] 100 [23] 100 [24] 100 [25] 100 [26] 100 [27] 100 [28] 100 [29] 100 [30] 100 [31] 100 [32] 100 [33] 100 [34] 100 [35] 100 [36] 100 [37] 100 [38] 100 [39] 100 [40] 100 [41] 100 [42] 100 [43] 100 [44] 100 [45] 100 [46] 100 [47] 100 [48] 100 [49] 100 [50] 100 [51] 100 [52] 100 [53] 100 [54] 100 [55] 100 [56] 100 [57] 100 [58] 100 [59] 100 [60] 100 [61] 100 [62] 100 [63] 100 [64] 100 [65] 100 [66] 100 [67] 100 [68] 100 [69] 100 [70] 100 [71] 100 [72] 100 [73] 100 [74] 100 [75] 100 [76] 100 [77] 100 [78] 100 [79] 100 [80] 100 [81] 100 [82] 100 [83] 100 [84] 100 [85] 100 [86] 100 [87] 100 [88] 100 [89] 100 [90] 100 [91] 100 [92] 100 [93] 100 [94] 100 [95] 100 [96] 100 [97] 100 [98] 100 [99] 100 [100] 100 [101] 100 [102] 100 [103] 100 [104] 100 [105] 100 [106] 100 [107] 100 [108] 100 [109] 100 [110] 100 [111] 100 [112] 100 [113] 100 [114] 100 [115] 100 [116] 100 [117] 100 [118] 100 [119] 100 [120] 100 [121] 100 [122] 100 [123] 100 [124] 100 [125] 100 [126] 100 [127] 100 [128] 100 [129] 100 [130] 100 [131] 100 [132] 100 [133] 100 [134] 100 [135] 100 [136] 100 [137] 100 [138] 100 [139] 100 [140] 100 [141] 100 [142] 100 [143] 100 [144] 100 [145] 100 [146] 100 [147] 100 [148] 100 [149] 100 [150] 100 [151] 100 [152] 100 [153] 100 [154] 100 [155] 100 [156] 100 [157] 100 [158] 100 [159] 100 [160] 100 [161] 100 [162] 100 [163] 100 [164] 100 [165] 100 [166] 100 [167] 100 [168] 100 [169] 100 [170] 100 [171] 100 [172] 100 [173] 100 [174] 100 [175] 100 [176] 100 [177] 100 [178] 100 [179] 100 [180] 100 [181] 100 [182] 100 [183] 100 [184] 100 [185] 100 [186] 100 [187] 100 [188] 100 [189] 100 [190] 100 [191] 100 [192] 100 [193] 100 [194] 100 [195] 100 [196] 100 [197] 100 [198] 100 [199] 100 [200] 100 > image(kmc, dendrogram=hc, col=blueyellow(64), RowSideColors=cols, ColSideColors=cols) > > # contrast the behavior when all the data comes from the same group > xx <- matrix(rnorm(100*50, rnorm(100, 0.5)), nrow=100, ncol=50, byrow=FALSE) > hct <- hclust(distanceMatrix(xx, 'pearson'), method='complete') > bct <- PerturbationClusterTest(xx, cutHclust, nTimes=200, k=4, metric='pearson') [1] 100 [2] 100 [3] 100 [4] 100 [5] 100 [6] 100 [7] 100 [8] 100 [9] 100 [10] 100 [11] 100 [12] 100 [13] 100 [14] 100 [15] 100 [16] 100 [17] 100 [18] 100 [19] 100 [20] 100 [21] 100 [22] 100 [23] 100 [24] 100 [25] 100 [26] 100 [27] 100 [28] 100 [29] 100 [30] 100 [31] 100 [32] 100 [33] 100 [34] 100 [35] 100 [36] 100 [37] 100 [38] 100 [39] 100 [40] 100 [41] 100 [42] 100 [43] 100 [44] 100 [45] 100 [46] 100 [47] 100 [48] 100 [49] 100 [50] 100 [51] 100 [52] 100 [53] 100 [54] 100 [55] 100 [56] 100 [57] 100 [58] 100 [59] 100 [60] 100 [61] 100 [62] 100 [63] 100 [64] 100 [65] 100 [66] 100 [67] 100 [68] 100 [69] 100 [70] 100 [71] 100 [72] 100 [73] 100 [74] 100 [75] 100 [76] 100 [77] 100 [78] 100 [79] 100 [80] 100 [81] 100 [82] 100 [83] 100 [84] 100 [85] 100 [86] 100 [87] 100 [88] 100 [89] 100 [90] 100 [91] 100 [92] 100 [93] 100 [94] 100 [95] 100 [96] 100 [97] 100 [98] 100 [99] 100 [100] 100 [101] 100 [102] 100 [103] 100 [104] 100 [105] 100 [106] 100 [107] 100 [108] 100 [109] 100 [110] 100 [111] 100 [112] 100 [113] 100 [114] 100 [115] 100 [116] 100 [117] 100 [118] 100 [119] 100 [120] 100 [121] 100 [122] 100 [123] 100 [124] 100 [125] 100 [126] 100 [127] 100 [128] 100 [129] 100 [130] 100 [131] 100 [132] 100 [133] 100 [134] 100 [135] 100 [136] 100 [137] 100 [138] 100 [139] 100 [140] 100 [141] 100 [142] 100 [143] 100 [144] 100 [145] 100 [146] 100 [147] 100 [148] 100 [149] 100 [150] 100 [151] 100 [152] 100 [153] 100 [154] 100 [155] 100 [156] 100 [157] 100 [158] 100 [159] 100 [160] 100 [161] 100 [162] 100 [163] 100 [164] 100 [165] 100 [166] 100 [167] 100 [168] 100 [169] 100 [170] 100 [171] 100 [172] 100 [173] 100 [174] 100 [175] 100 [176] 100 [177] 100 [178] 100 [179] 100 [180] 100 [181] 100 [182] 100 [183] 100 [184] 100 [185] 100 [186] 100 [187] 100 [188] 100 [189] 100 [190] 100 [191] 100 [192] 100 [193] 100 [194] 100 [195] 100 [196] 100 [197] 100 [198] 100 [199] 100 [200] 100 > summary(bct) Number of perturbation samples: 200. Noise level: 1. A PerturbationClusterTest object. Call: PerturbationClusterTest(data = xx, FUN = cutHclust, nTimes = 200, k = 4, metric = "pearson") Agreement levels: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.380 0.655 0.805 0.769 0.890 0.995 > image(bct, dendrogram=hct, col=blueyellow(64), RowSideColors=cols, ColSideColors=cols) > > # cleanup > rm(d1, d2, dd, cols, hc, bc, kmc, xx, hct, bct) > > proc.time() user system elapsed 0.98 0.18 1.17