cola Report for GDS4813

Date: 2019-12-25 21:49:25 CET, cola version: 1.3.2

Document is loading...


Summary

All available functions which can be applied to this res_list object:

res_list
#> A 'ConsensusPartitionList' object with 24 methods.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows are extracted by 'SD, CV, MAD, ATC' methods.
#>   Subgroups are detected by 'hclust, kmeans, skmeans, pam, mclust, NMF' method.
#>   Number of partitions are tried for k = 2, 3, 4, 5, 6.
#>   Performed in total 30000 partitions by row resampling.
#> 
#> Following methods can be applied to this 'ConsensusPartitionList' object:
#>  [1] "cola_report"           "collect_classes"       "collect_plots"         "collect_stats"        
#>  [5] "colnames"              "functional_enrichment" "get_anno_col"          "get_anno"             
#>  [9] "get_classes"           "get_matrix"            "get_membership"        "get_stats"            
#> [13] "is_best_k"             "is_stable_k"           "ncol"                  "nrow"                 
#> [17] "rownames"              "show"                  "suggest_best_k"        "test_to_known_factors"
#> [21] "top_rows_heatmap"      "top_rows_overlap"     
#> 
#> You can get result for a single method by, e.g. object["SD", "hclust"] or object["SD:hclust"]
#> or a subset of methods by object[c("SD", "CV")], c("hclust", "kmeans")]

The call of run_all_consensus_partition_methods() was:

#> run_all_consensus_partition_methods(data = mat, mc.cores = 4, anno = anno)

Dimension of the input matrix:

mat = get_matrix(res_list)
dim(mat)
#> [1] 51941    51

Density distribution

The density distribution for each sample is visualized as in one column in the following heatmap. The clustering is based on the distance which is the Kolmogorov-Smirnov statistic between two distributions.

library(ComplexHeatmap)
densityHeatmap(mat, top_annotation = HeatmapAnnotation(df = get_anno(res_list), 
    col = get_anno_col(res_list)), ylab = "value", cluster_columns = TRUE, show_column_names = FALSE,
    mc.cores = 4)

plot of chunk density-heatmap

Suggest the best k

Folowing table shows the best k (number of partitions) for each combination of top-value methods and partition methods. Clicking on the method name in the table goes to the section for a single combination of methods.

The cola vignette explains the definition of the metrics used for determining the best number of partitions.

suggest_best_k(res_list)
The best k 1-PAC Mean silhouette Concordance Optional k
SD:pam 3 1.000 1.000 1.000 ** 2
SD:NMF 3 1.000 1.000 1.000 ** 2
CV:hclust 3 1.000 1.000 1.000 ** 2
CV:kmeans 3 1.000 0.991 0.964 **
CV:NMF 3 1.000 1.000 1.000 ** 2
MAD:hclust 3 1.000 0.968 0.987 ** 2
MAD:kmeans 3 1.000 0.977 0.943 **
MAD:mclust 3 1.000 0.998 0.999 **
MAD:NMF 3 1.000 1.000 1.000 ** 2
ATC:hclust 3 1.000 1.000 1.000 ** 2
ATC:pam 3 1.000 1.000 1.000 ** 2
ATC:mclust 3 1.000 0.999 1.000 ** 2
ATC:NMF 3 1.000 0.998 0.999 ** 2
MAD:skmeans 5 0.969 0.939 0.968 ** 2,3
CV:skmeans 5 0.947 0.922 0.956 * 3
CV:mclust 4 0.936 0.905 0.932 * 2,3
ATC:skmeans 4 0.936 0.966 0.978 * 2,3
SD:hclust 4 0.934 0.992 0.983 * 2,3
MAD:pam 5 0.924 0.921 0.962 * 2,3,4
SD:skmeans 5 0.909 0.819 0.929 * 3
SD:mclust 5 0.909 0.882 0.944 * 3,4
CV:pam 6 0.902 0.890 0.950 * 2,3
SD:kmeans 3 0.681 0.990 0.947
ATC:kmeans 3 0.681 0.996 0.973

**: 1-PAC > 0.95, *: 1-PAC > 0.9

CDF of consensus matrices

Cumulative distribution function curves of consensus matrix for all methods.

collect_plots(res_list, fun = plot_ecdf)

plot of chunk collect-plots

Consensus heatmap

Consensus heatmaps for all methods. (What is a consensus heatmap?)

collect_plots(res_list, k = 2, fun = consensus_heatmap, mc.cores = 4)

plot of chunk tab-collect-consensus-heatmap-1

collect_plots(res_list, k = 3, fun = consensus_heatmap, mc.cores = 4)

plot of chunk tab-collect-consensus-heatmap-2

collect_plots(res_list, k = 4, fun = consensus_heatmap, mc.cores = 4)

plot of chunk tab-collect-consensus-heatmap-3

collect_plots(res_list, k = 5, fun = consensus_heatmap, mc.cores = 4)

plot of chunk tab-collect-consensus-heatmap-4

collect_plots(res_list, k = 6, fun = consensus_heatmap, mc.cores = 4)

plot of chunk tab-collect-consensus-heatmap-5

Membership heatmap

Membership heatmaps for all methods. (What is a membership heatmap?)

collect_plots(res_list, k = 2, fun = membership_heatmap, mc.cores = 4)

plot of chunk tab-collect-membership-heatmap-1

collect_plots(res_list, k = 3, fun = membership_heatmap, mc.cores = 4)

plot of chunk tab-collect-membership-heatmap-2

collect_plots(res_list, k = 4, fun = membership_heatmap, mc.cores = 4)

plot of chunk tab-collect-membership-heatmap-3

collect_plots(res_list, k = 5, fun = membership_heatmap, mc.cores = 4)

plot of chunk tab-collect-membership-heatmap-4

collect_plots(res_list, k = 6, fun = membership_heatmap, mc.cores = 4)

plot of chunk tab-collect-membership-heatmap-5

Signature heatmap

Signature heatmaps for all methods. (What is a signature heatmap?)

Note in following heatmaps, rows are scaled.

collect_plots(res_list, k = 2, fun = get_signatures, mc.cores = 4)

plot of chunk tab-collect-get-signatures-1

collect_plots(res_list, k = 3, fun = get_signatures, mc.cores = 4)

plot of chunk tab-collect-get-signatures-2

collect_plots(res_list, k = 4, fun = get_signatures, mc.cores = 4)

plot of chunk tab-collect-get-signatures-3

collect_plots(res_list, k = 5, fun = get_signatures, mc.cores = 4)

plot of chunk tab-collect-get-signatures-4

collect_plots(res_list, k = 6, fun = get_signatures, mc.cores = 4)

plot of chunk tab-collect-get-signatures-5

Statistics table

The statistics used for measuring the stability of consensus partitioning. (How are they defined?)

get_stats(res_list, k = 2)
#>             k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> SD:NMF      2 1.000           1.000       1.000          0.297 0.704   0.704
#> CV:NMF      2 1.000           1.000       1.000          0.297 0.704   0.704
#> MAD:NMF     2 1.000           0.999       1.000          0.298 0.704   0.704
#> ATC:NMF     2 1.000           1.000       1.000          0.297 0.704   0.704
#> SD:skmeans  2 0.633           0.897       0.915          0.424 0.506   0.506
#> CV:skmeans  2 0.633           0.897       0.915          0.424 0.506   0.506
#> MAD:skmeans 2 1.000           1.000       1.000          0.495 0.506   0.506
#> ATC:skmeans 2 1.000           1.000       1.000          0.297 0.704   0.704
#> SD:mclust   2 0.639           0.932       0.945          0.464 0.506   0.506
#> CV:mclust   2 1.000           0.984       0.986          0.485 0.506   0.506
#> MAD:mclust  2 0.633           0.903       0.919          0.427 0.506   0.506
#> ATC:mclust  2 1.000           0.964       0.977          0.316 0.704   0.704
#> SD:kmeans   2 0.506           0.758       0.824          0.327 0.704   0.704
#> CV:kmeans   2 0.506           0.815       0.854          0.323 0.704   0.704
#> MAD:kmeans  2 0.421           0.676       0.802          0.386 0.633   0.633
#> ATC:kmeans  2 0.500           0.819       0.850          0.329 0.704   0.704
#> SD:pam      2 1.000           1.000       1.000          0.297 0.704   0.704
#> CV:pam      2 1.000           1.000       1.000          0.297 0.704   0.704
#> MAD:pam     2 1.000           1.000       1.000          0.297 0.704   0.704
#> ATC:pam     2 1.000           1.000       1.000          0.297 0.704   0.704
#> SD:hclust   2 1.000           1.000       1.000          0.297 0.704   0.704
#> CV:hclust   2 1.000           1.000       1.000          0.297 0.704   0.704
#> MAD:hclust  2 1.000           1.000       1.000          0.297 0.704   0.704
#> ATC:hclust  2 1.000           1.000       1.000          0.297 0.704   0.704
get_stats(res_list, k = 3)
#>             k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> SD:NMF      3 1.000           1.000       1.000          0.949 0.718   0.599
#> CV:NMF      3 1.000           1.000       1.000          0.949 0.718   0.599
#> MAD:NMF     3 1.000           1.000       1.000          0.946 0.718   0.599
#> ATC:NMF     3 1.000           0.998       0.999          0.952 0.718   0.599
#> SD:skmeans  3 1.000           1.000       1.000          0.367 0.915   0.833
#> CV:skmeans  3 1.000           1.000       1.000          0.367 0.915   0.833
#> MAD:skmeans 3 1.000           0.999       0.999          0.171 0.915   0.833
#> ATC:skmeans 3 1.000           0.959       0.985          1.004 0.693   0.563
#> SD:mclust   3 0.969           0.941       0.973          0.286 0.915   0.833
#> CV:mclust   3 0.977           0.967       0.984          0.215 0.915   0.833
#> MAD:mclust  3 1.000           0.998       0.999          0.356 0.915   0.833
#> ATC:mclust  3 1.000           0.999       1.000          0.834 0.718   0.599
#> SD:kmeans   3 0.681           0.990       0.947          0.630 0.718   0.599
#> CV:kmeans   3 1.000           0.991       0.964          0.705 0.718   0.599
#> MAD:kmeans  3 1.000           0.977       0.943          0.465 0.788   0.665
#> ATC:kmeans  3 0.681           0.996       0.973          0.677 0.718   0.599
#> SD:pam      3 1.000           1.000       1.000          0.949 0.718   0.599
#> CV:pam      3 1.000           1.000       1.000          0.949 0.718   0.599
#> MAD:pam     3 1.000           1.000       1.000          0.949 0.718   0.599
#> ATC:pam     3 1.000           1.000       1.000          0.949 0.718   0.599
#> SD:hclust   3 1.000           1.000       1.000          0.949 0.718   0.599
#> CV:hclust   3 1.000           1.000       1.000          0.949 0.718   0.599
#> MAD:hclust  3 1.000           0.968       0.987          0.977 0.718   0.599
#> ATC:hclust  3 1.000           1.000       1.000          0.949 0.718   0.599
get_stats(res_list, k = 4)
#>             k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> SD:NMF      4 0.895           0.924       0.946         0.1444 0.902   0.767
#> CV:NMF      4 0.824           0.838       0.921         0.1346 0.918   0.806
#> MAD:NMF     4 0.730           0.639       0.859         0.1833 0.956   0.896
#> ATC:NMF     4 0.778           0.887       0.904         0.1348 1.000   1.000
#> SD:skmeans  4 0.844           0.774       0.890         0.2200 0.902   0.767
#> CV:skmeans  4 0.731           0.435       0.766         0.2443 0.977   0.946
#> MAD:skmeans 4 0.860           0.905       0.933         0.2909 0.824   0.583
#> ATC:skmeans 4 0.936           0.966       0.978         0.2613 0.817   0.558
#> SD:mclust   4 1.000           0.966       0.989         0.0961 0.918   0.806
#> CV:mclust   4 0.936           0.905       0.932         0.1039 0.918   0.806
#> MAD:mclust  4 0.701           0.698       0.838         0.1957 0.956   0.896
#> ATC:mclust  4 0.833           0.883       0.925         0.1723 0.936   0.849
#> SD:kmeans   4 0.770           0.863       0.892         0.2027 0.936   0.849
#> CV:kmeans   4 0.727           0.868       0.874         0.1875 1.000   1.000
#> MAD:kmeans  4 0.708           0.356       0.785         0.2186 0.977   0.946
#> ATC:kmeans  4 0.731           0.669       0.729         0.2216 0.836   0.611
#> SD:pam      4 0.820           0.847       0.885         0.2357 0.824   0.583
#> CV:pam      4 0.860           0.900       0.943         0.1691 0.936   0.849
#> MAD:pam     4 0.956           0.939       0.975         0.2997 0.824   0.583
#> ATC:pam     4 0.824           0.880       0.915         0.2560 0.852   0.648
#> SD:hclust   4 0.934           0.992       0.983         0.0893 0.936   0.849
#> CV:hclust   4 0.845           0.874       0.932         0.1416 0.936   0.849
#> MAD:hclust  4 0.759           0.850       0.921         0.1370 0.956   0.896
#> ATC:hclust  4 0.785           0.914       0.949         0.0796 0.991   0.980
get_stats(res_list, k = 5)
#>             k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> SD:NMF      5 0.822           0.876       0.929         0.0596 0.977   0.930
#> CV:NMF      5 0.859           0.868       0.928         0.0808 0.977   0.934
#> MAD:NMF     5 0.736           0.765       0.858         0.1179 0.825   0.547
#> ATC:NMF     5 0.689           0.701       0.848         0.0747 0.902   0.767
#> SD:skmeans  5 0.909           0.819       0.929         0.1236 0.887   0.650
#> CV:skmeans  5 0.947           0.922       0.956         0.1099 0.780   0.457
#> MAD:skmeans 5 0.969           0.939       0.968         0.0766 0.938   0.752
#> ATC:skmeans 5 0.827           0.804       0.884         0.0752 0.928   0.716
#> SD:mclust   5 0.909           0.882       0.944         0.0903 0.941   0.828
#> CV:mclust   5 0.685           0.590       0.738         0.1488 0.941   0.828
#> MAD:mclust  5 0.652           0.532       0.743         0.0859 0.802   0.509
#> ATC:mclust  5 0.796           0.781       0.877         0.0820 0.920   0.779
#> SD:kmeans   5 0.684           0.774       0.824         0.1183 1.000   1.000
#> CV:kmeans   5 0.695           0.561       0.697         0.1158 0.817   0.566
#> MAD:kmeans  5 0.681           0.760       0.768         0.0887 0.776   0.450
#> ATC:kmeans  5 0.680           0.746       0.828         0.1072 0.836   0.535
#> SD:pam      5 0.822           0.794       0.883         0.0873 0.949   0.801
#> CV:pam      5 0.781           0.623       0.783         0.1004 0.865   0.641
#> MAD:pam     5 0.924           0.921       0.962         0.0371 0.973   0.888
#> ATC:pam     5 0.803           0.865       0.919         0.0456 0.973   0.899
#> SD:hclust   5 1.000           0.980       1.000         0.0324 0.991   0.976
#> CV:hclust   5 0.812           0.839       0.924         0.0623 0.961   0.890
#> MAD:hclust  5 0.773           0.779       0.886         0.1181 0.905   0.749
#> ATC:hclust  5 0.834           0.848       0.920         0.1092 0.918   0.802
get_stats(res_list, k = 6)
#>             k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> SD:NMF      6 0.757           0.799       0.873         0.0577 0.977   0.927
#> CV:NMF      6 0.786           0.814       0.881         0.0500 0.956   0.867
#> MAD:NMF     6 0.782           0.713       0.831         0.0352 1.000   1.000
#> ATC:NMF     6 0.682           0.673       0.813         0.0459 0.956   0.867
#> SD:skmeans  6 0.865           0.762       0.835         0.0392 0.964   0.830
#> CV:skmeans  6 0.871           0.876       0.910         0.0317 0.969   0.846
#> MAD:skmeans 6 0.869           0.772       0.839         0.0298 0.967   0.829
#> ATC:skmeans 6 0.846           0.752       0.861         0.0306 0.947   0.734
#> SD:mclust   6 0.780           0.811       0.904         0.0641 0.971   0.899
#> CV:mclust   6 0.695           0.561       0.740         0.0503 0.797   0.413
#> MAD:mclust  6 0.776           0.662       0.865         0.0650 0.823   0.418
#> ATC:mclust  6 0.774           0.829       0.886         0.0786 0.892   0.637
#> SD:kmeans   6 0.689           0.724       0.776         0.0840 0.881   0.667
#> CV:kmeans   6 0.713           0.781       0.801         0.0781 0.869   0.536
#> MAD:kmeans  6 0.689           0.811       0.801         0.0623 0.961   0.817
#> ATC:kmeans  6 0.697           0.774       0.807         0.0495 0.925   0.734
#> SD:pam      6 0.879           0.852       0.933         0.0315 0.973   0.873
#> CV:pam      6 0.902           0.890       0.950         0.0756 0.907   0.664
#> MAD:pam     6 0.877           0.771       0.927         0.0244 0.990   0.953
#> ATC:pam     6 0.819           0.849       0.930         0.0080 0.997   0.987
#> SD:hclust   6 0.802           0.834       0.881         0.1456 0.873   0.636
#> CV:hclust   6 0.811           0.844       0.919         0.0375 0.991   0.973
#> MAD:hclust  6 0.782           0.774       0.903         0.0133 0.991   0.970
#> ATC:hclust  6 0.790           0.782       0.905         0.1160 0.871   0.619

Following heatmap plots the partition for each combination of methods and the lightness correspond to the silhouette scores for samples in each method. On top the consensus subgroup is inferred from all methods by taking the mean silhouette scores as weight.

collect_stats(res_list, k = 2)

plot of chunk tab-collect-stats-from-consensus-partition-list-1

collect_stats(res_list, k = 3)

plot of chunk tab-collect-stats-from-consensus-partition-list-2

collect_stats(res_list, k = 4)

plot of chunk tab-collect-stats-from-consensus-partition-list-3

collect_stats(res_list, k = 5)

plot of chunk tab-collect-stats-from-consensus-partition-list-4

collect_stats(res_list, k = 6)

plot of chunk tab-collect-stats-from-consensus-partition-list-5

Partition from all methods

Collect partitions from all methods:

collect_classes(res_list, k = 2)

plot of chunk tab-collect-classes-from-consensus-partition-list-1

collect_classes(res_list, k = 3)

plot of chunk tab-collect-classes-from-consensus-partition-list-2

collect_classes(res_list, k = 4)

plot of chunk tab-collect-classes-from-consensus-partition-list-3

collect_classes(res_list, k = 5)

plot of chunk tab-collect-classes-from-consensus-partition-list-4

collect_classes(res_list, k = 6)

plot of chunk tab-collect-classes-from-consensus-partition-list-5

Top rows overlap

Overlap of top rows from different top-row methods:

top_rows_overlap(res_list, top_n = 1000, method = "euler")

plot of chunk tab-top-rows-overlap-by-euler-1

top_rows_overlap(res_list, top_n = 2000, method = "euler")

plot of chunk tab-top-rows-overlap-by-euler-2

top_rows_overlap(res_list, top_n = 3000, method = "euler")

plot of chunk tab-top-rows-overlap-by-euler-3

top_rows_overlap(res_list, top_n = 4000, method = "euler")

plot of chunk tab-top-rows-overlap-by-euler-4

top_rows_overlap(res_list, top_n = 5000, method = "euler")

plot of chunk tab-top-rows-overlap-by-euler-5

Also visualize the correspondance of rankings between different top-row methods:

top_rows_overlap(res_list, top_n = 1000, method = "correspondance")

plot of chunk tab-top-rows-overlap-by-correspondance-1

top_rows_overlap(res_list, top_n = 2000, method = "correspondance")

plot of chunk tab-top-rows-overlap-by-correspondance-2

top_rows_overlap(res_list, top_n = 3000, method = "correspondance")

plot of chunk tab-top-rows-overlap-by-correspondance-3

top_rows_overlap(res_list, top_n = 4000, method = "correspondance")

plot of chunk tab-top-rows-overlap-by-correspondance-4

top_rows_overlap(res_list, top_n = 5000, method = "correspondance")

plot of chunk tab-top-rows-overlap-by-correspondance-5

Heatmaps of the top rows:

top_rows_heatmap(res_list, top_n = 1000)

plot of chunk tab-top-rows-heatmap-1

top_rows_heatmap(res_list, top_n = 2000)

plot of chunk tab-top-rows-heatmap-2

top_rows_heatmap(res_list, top_n = 3000)

plot of chunk tab-top-rows-heatmap-3

top_rows_heatmap(res_list, top_n = 4000)

plot of chunk tab-top-rows-heatmap-4

top_rows_heatmap(res_list, top_n = 5000)

plot of chunk tab-top-rows-heatmap-5

Test to known annotations

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res_list, k = 2)
#>              n agent(p) k
#> SD:NMF      51    0.648 2
#> CV:NMF      51    0.648 2
#> MAD:NMF     51    0.648 2
#> ATC:NMF     51    0.648 2
#> SD:skmeans  51    0.493 2
#> CV:skmeans  51    0.493 2
#> MAD:skmeans 51    0.493 2
#> ATC:skmeans 51    0.648 2
#> SD:mclust   51    0.493 2
#> CV:mclust   51    0.493 2
#> MAD:mclust  51    0.493 2
#> ATC:mclust  51    0.648 2
#> SD:kmeans   51    0.648 2
#> CV:kmeans   51    0.648 2
#> MAD:kmeans  42    0.557 2
#> ATC:kmeans  51    0.648 2
#> SD:pam      51    0.648 2
#> CV:pam      51    0.648 2
#> MAD:pam     51    0.648 2
#> ATC:pam     51    0.648 2
#> SD:hclust   51    0.648 2
#> CV:hclust   51    0.648 2
#> MAD:hclust  51    0.648 2
#> ATC:hclust  51    0.648 2
test_to_known_factors(res_list, k = 3)
#>              n agent(p) k
#> SD:NMF      51    0.642 3
#> CV:NMF      51    0.642 3
#> MAD:NMF     51    0.642 3
#> ATC:NMF     51    0.642 3
#> SD:skmeans  51    0.642 3
#> CV:skmeans  51    0.642 3
#> MAD:skmeans 51    0.642 3
#> ATC:skmeans 50    0.627 3
#> SD:mclust   48    0.627 3
#> CV:mclust   51    0.642 3
#> MAD:mclust  51    0.642 3
#> ATC:mclust  51    0.642 3
#> SD:kmeans   51    0.642 3
#> CV:kmeans   51    0.642 3
#> MAD:kmeans  51    0.642 3
#> ATC:kmeans  51    0.642 3
#> SD:pam      51    0.642 3
#> CV:pam      51    0.642 3
#> MAD:pam     51    0.642 3
#> ATC:pam     51    0.642 3
#> SD:hclust   51    0.642 3
#> CV:hclust   51    0.642 3
#> MAD:hclust  51    0.642 3
#> ATC:hclust  51    0.642 3
test_to_known_factors(res_list, k = 4)
#>              n agent(p) k
#> SD:NMF      50    0.502 4
#> CV:NMF      49    0.494 4
#> MAD:NMF     33    0.406 4
#> ATC:NMF     51    0.642 4
#> SD:skmeans  45    0.474 4
#> CV:skmeans  21    0.529 4
#> MAD:skmeans 51    0.544 4
#> ATC:skmeans 51    0.567 4
#> SD:mclust   50    0.497 4
#> CV:mclust   49    0.495 4
#> MAD:mclust  40    0.754 4
#> ATC:mclust  51    0.502 4
#> SD:kmeans   50    0.497 4
#> CV:kmeans   51    0.642 4
#> MAD:kmeans  21    0.529 4
#> ATC:kmeans  41    0.528 4
#> SD:pam      47    0.515 4
#> CV:pam      51    0.502 4
#> MAD:pam     49    0.551 4
#> ATC:pam     51    0.623 4
#> SD:hclust   51    0.502 4
#> CV:hclust   49    0.494 4
#> MAD:hclust  50    0.833 4
#> ATC:hclust  50    0.583 4
test_to_known_factors(res_list, k = 5)
#>              n agent(p) k
#> SD:NMF      49    0.497 5
#> CV:NMF      49    0.497 5
#> MAD:NMF     44    0.403 5
#> ATC:NMF     44    0.474 5
#> SD:skmeans  46    0.476 5
#> CV:skmeans  51    0.502 5
#> MAD:skmeans 50    0.538 5
#> ATC:skmeans 47    0.440 5
#> SD:mclust   49    0.396 5
#> CV:mclust   34    0.352 5
#> MAD:mclust  25    0.428 5
#> ATC:mclust  45    0.395 5
#> SD:kmeans   50    0.497 5
#> CV:kmeans   39    0.425 5
#> MAD:kmeans  48    0.520 5
#> ATC:kmeans  46    0.600 5
#> SD:pam      47    0.452 5
#> CV:pam      37    0.491 5
#> MAD:pam     49    0.520 5
#> ATC:pam     51    0.626 5
#> SD:hclust   50    0.476 5
#> CV:hclust   50    0.711 5
#> MAD:hclust  49    0.632 5
#> ATC:hclust  48    0.747 5
test_to_known_factors(res_list, k = 6)
#>              n agent(p) k
#> SD:NMF      47    0.487 6
#> CV:NMF      45    0.478 6
#> MAD:NMF     44    0.403 6
#> ATC:NMF     42    0.479 6
#> SD:skmeans  45    0.394 6
#> CV:skmeans  48    0.422 6
#> MAD:skmeans 46    0.403 6
#> ATC:skmeans 43    0.400 6
#> SD:mclust   46    0.394 6
#> CV:mclust   32    0.497 6
#> MAD:mclust  40    0.576 6
#> ATC:mclust  48    0.384 6
#> SD:kmeans   43    0.446 6
#> CV:kmeans   49    0.394 6
#> MAD:kmeans  50    0.494 6
#> ATC:kmeans  48    0.495 6
#> SD:pam      46    0.424 6
#> CV:pam      48    0.445 6
#> MAD:pam     46    0.523 6
#> ATC:pam     50    0.522 6
#> SD:hclust   48    0.472 6
#> CV:hclust   49    0.631 6
#> MAD:hclust  49    0.632 6
#> ATC:hclust  44    0.601 6

Results for each method


SD:hclust*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "hclust"]
# you can also extract it by
# res = res_list["SD:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 4.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.934           0.992       0.983         0.0893 0.936   0.849
#> 5 5 1.000           0.980       1.000         0.0324 0.991   0.976
#> 6 6 0.802           0.834       0.881         0.1456 0.873   0.636

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 4
#> attr(,"optional")
#> [1] 2 3

There is also optional best \(k\) = 2 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782697     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782698     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782699     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782702     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782703     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782705     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782706     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782707     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782708     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782709     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782710     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782711     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782712     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782713     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782716     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782717     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782718     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782719     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782720     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782721     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782722     4  0.3764      1.000 0.216  0 0.000 0.784
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     4  0.3764      1.000 0.216  0 0.000 0.784
#> GSM782726     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782727     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     4  0.3764      1.000 0.216  0 0.000 0.784
#> GSM782730     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782731     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782732     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782733     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782734     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     1  0.0188      0.995 0.996  0 0.000 0.004
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782739     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782742     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782743     3  0.0000      0.983 0.000  0 1.000 0.000
#> GSM782744     3  0.3764      0.784 0.000  0 0.784 0.216
#> GSM782745     1  0.0000      1.000 1.000  0 0.000 0.000
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2 p3    p4 p5
#> GSM782696     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782697     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782698     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782699     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782701     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782702     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782705     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782706     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782707     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782709     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782710     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782711     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782712     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782715     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782717     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782718     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782719     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782721     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782722     4  0.0000      1.000 0.000  0  0 1.000  0
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782725     4  0.0000      1.000 0.000  0  0 1.000  0
#> GSM782726     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782729     4  0.0000      1.000 0.000  0  0 1.000  0
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782731     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782732     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782734     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782736     1  0.0162      0.996 0.996  0  0 0.004  0
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782738     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782739     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782741     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782744     5  0.0000      0.000 0.000  0  0 0.000  1
#> GSM782745     1  0.0000      1.000 1.000  0  0 0.000  0
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000  0

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2 p3    p4    p5    p6
#> GSM782696     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782697     1  0.0146      0.803 0.996  0  0 0.000 0.000 0.004
#> GSM782698     1  0.0146      0.803 0.996  0  0 0.000 0.000 0.004
#> GSM782699     1  0.0146      0.803 0.996  0  0 0.000 0.000 0.004
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782701     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782702     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782705     1  0.0260      0.801 0.992  0  0 0.000 0.008 0.000
#> GSM782706     1  0.2527      0.512 0.832  0  0 0.000 0.000 0.168
#> GSM782707     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782709     1  0.3797     -0.570 0.580  0  0 0.000 0.000 0.420
#> GSM782710     6  0.3843      0.829 0.452  0  0 0.000 0.000 0.548
#> GSM782711     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782712     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782715     1  0.4793      0.436 0.628  0  0 0.000 0.288 0.084
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782717     6  0.3867      0.917 0.488  0  0 0.000 0.000 0.512
#> GSM782718     1  0.2491      0.666 0.836  0  0 0.000 0.164 0.000
#> GSM782719     1  0.0000      0.804 1.000  0  0 0.000 0.000 0.000
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782721     1  0.2527      0.512 0.832  0  0 0.000 0.000 0.168
#> GSM782722     4  0.0000      1.000 0.000  0  0 1.000 0.000 0.000
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782725     4  0.0000      1.000 0.000  0  0 1.000 0.000 0.000
#> GSM782726     6  0.3695      0.829 0.376  0  0 0.000 0.000 0.624
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782729     4  0.0000      1.000 0.000  0  0 1.000 0.000 0.000
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782731     6  0.3868      0.913 0.492  0  0 0.000 0.000 0.508
#> GSM782732     6  0.3868      0.913 0.492  0  0 0.000 0.000 0.508
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782734     6  0.3866      0.916 0.484  0  0 0.000 0.000 0.516
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782736     1  0.3733      0.520 0.700  0  0 0.004 0.288 0.008
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782738     1  0.2491      0.666 0.836  0  0 0.000 0.164 0.000
#> GSM782739     6  0.3867      0.917 0.488  0  0 0.000 0.000 0.512
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000
#> GSM782741     6  0.3867      0.917 0.488  0  0 0.000 0.000 0.512
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000 0.000 0.000
#> GSM782744     5  0.3351      0.000 0.000  0  0 0.000 0.712 0.288
#> GSM782745     6  0.3695      0.829 0.376  0  0 0.000 0.000 0.624
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-hclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-SD-hclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-SD-hclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-SD-hclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-SD-hclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-hclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-SD-hclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-SD-hclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-SD-hclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-SD-hclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-hclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-SD-hclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-SD-hclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-SD-hclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-SD-hclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-hclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-SD-hclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-SD-hclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-SD-hclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-SD-hclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-hclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-SD-hclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-SD-hclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-SD-hclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-SD-hclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>            n agent(p) k
#> SD:hclust 51    0.648 2
#> SD:hclust 51    0.642 3
#> SD:hclust 51    0.502 4
#> SD:hclust 50    0.476 5
#> SD:hclust 48    0.472 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:kmeans

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "kmeans"]
# you can also extract it by
# res = res_list["SD:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.506           0.758       0.824          0.327 0.704   0.704
#> 3 3 0.681           0.990       0.947          0.630 0.718   0.599
#> 4 4 0.770           0.863       0.892          0.203 0.936   0.849
#> 5 5 0.684           0.774       0.824          0.118 1.000   1.000
#> 6 6 0.689           0.724       0.776          0.084 0.881   0.667

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.985      0.781 0.572 0.428
#> GSM782697     1   0.985      0.781 0.572 0.428
#> GSM782698     1   0.985      0.781 0.572 0.428
#> GSM782699     1   0.985      0.781 0.572 0.428
#> GSM782700     2   0.000      1.000 0.000 1.000
#> GSM782701     1   0.985      0.781 0.572 0.428
#> GSM782702     1   0.985      0.781 0.572 0.428
#> GSM782703     1   0.000      0.519 1.000 0.000
#> GSM782704     1   0.000      0.519 1.000 0.000
#> GSM782705     1   0.985      0.781 0.572 0.428
#> GSM782706     1   0.985      0.781 0.572 0.428
#> GSM782707     1   0.985      0.781 0.572 0.428
#> GSM782708     1   0.000      0.519 1.000 0.000
#> GSM782709     1   0.985      0.781 0.572 0.428
#> GSM782710     1   0.985      0.781 0.572 0.428
#> GSM782711     1   0.985      0.781 0.572 0.428
#> GSM782712     1   0.985      0.781 0.572 0.428
#> GSM782713     1   0.000      0.519 1.000 0.000
#> GSM782714     2   0.000      1.000 0.000 1.000
#> GSM782715     1   0.985      0.781 0.572 0.428
#> GSM782716     1   0.000      0.519 1.000 0.000
#> GSM782717     1   0.985      0.781 0.572 0.428
#> GSM782718     1   0.985      0.781 0.572 0.428
#> GSM782719     1   0.985      0.781 0.572 0.428
#> GSM782720     1   0.000      0.519 1.000 0.000
#> GSM782721     1   0.985      0.781 0.572 0.428
#> GSM782722     1   0.985      0.781 0.572 0.428
#> GSM782723     2   0.000      1.000 0.000 1.000
#> GSM782724     2   0.000      1.000 0.000 1.000
#> GSM782725     1   0.985      0.781 0.572 0.428
#> GSM782726     1   0.985      0.781 0.572 0.428
#> GSM782727     1   0.000      0.519 1.000 0.000
#> GSM782728     2   0.000      1.000 0.000 1.000
#> GSM782729     1   0.985      0.781 0.572 0.428
#> GSM782730     1   0.000      0.519 1.000 0.000
#> GSM782731     1   0.985      0.781 0.572 0.428
#> GSM782732     1   0.985      0.781 0.572 0.428
#> GSM782733     1   0.000      0.519 1.000 0.000
#> GSM782734     1   0.985      0.781 0.572 0.428
#> GSM782735     2   0.000      1.000 0.000 1.000
#> GSM782736     1   0.985      0.781 0.572 0.428
#> GSM782737     2   0.000      1.000 0.000 1.000
#> GSM782738     1   0.985      0.781 0.572 0.428
#> GSM782739     1   0.985      0.781 0.572 0.428
#> GSM782740     2   0.000      1.000 0.000 1.000
#> GSM782741     1   0.985      0.781 0.572 0.428
#> GSM782742     1   0.000      0.519 1.000 0.000
#> GSM782743     1   0.000      0.519 1.000 0.000
#> GSM782744     1   0.000      0.519 1.000 0.000
#> GSM782745     1   0.985      0.781 0.572 0.428
#> GSM782746     2   0.000      1.000 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782697     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782698     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782699     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782700     2  0.2400      0.980 0.064 0.932 0.004
#> GSM782701     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782702     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782703     3  0.4609      0.981 0.128 0.028 0.844
#> GSM782704     3  0.5174      0.981 0.128 0.048 0.824
#> GSM782705     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782706     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782707     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782708     3  0.5174      0.981 0.128 0.048 0.824
#> GSM782709     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782710     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782711     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782712     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782713     3  0.3482      0.981 0.128 0.000 0.872
#> GSM782714     2  0.3310      0.979 0.064 0.908 0.028
#> GSM782715     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782716     3  0.5174      0.981 0.128 0.048 0.824
#> GSM782717     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782718     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782719     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782720     3  0.3482      0.981 0.128 0.000 0.872
#> GSM782721     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782722     1  0.0424      0.992 0.992 0.000 0.008
#> GSM782723     2  0.3310      0.979 0.064 0.908 0.028
#> GSM782724     2  0.4565      0.960 0.064 0.860 0.076
#> GSM782725     1  0.0424      0.992 0.992 0.000 0.008
#> GSM782726     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782727     3  0.3482      0.981 0.128 0.000 0.872
#> GSM782728     2  0.2165      0.980 0.064 0.936 0.000
#> GSM782729     1  0.0424      0.992 0.992 0.000 0.008
#> GSM782730     3  0.3482      0.981 0.128 0.000 0.872
#> GSM782731     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782732     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782733     3  0.5174      0.981 0.128 0.048 0.824
#> GSM782734     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782735     2  0.3780      0.968 0.064 0.892 0.044
#> GSM782736     1  0.0424      0.992 0.992 0.000 0.008
#> GSM782737     2  0.3310      0.979 0.064 0.908 0.028
#> GSM782738     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782739     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782740     2  0.2165      0.980 0.064 0.936 0.000
#> GSM782741     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782742     3  0.3482      0.981 0.128 0.000 0.872
#> GSM782743     3  0.5174      0.981 0.128 0.048 0.824
#> GSM782744     3  0.4848      0.976 0.128 0.036 0.836
#> GSM782745     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782746     2  0.3780      0.968 0.064 0.892 0.044

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1    p2    p3    p4
#> GSM782696     1  0.1557      0.826 0.944 0.000 0.000 0.056
#> GSM782697     1  0.0000      0.834 1.000 0.000 0.000 0.000
#> GSM782698     1  0.2704      0.780 0.876 0.000 0.000 0.124
#> GSM782699     1  0.0000      0.834 1.000 0.000 0.000 0.000
#> GSM782700     2  0.0895      0.972 0.020 0.976 0.004 0.000
#> GSM782701     1  0.2530      0.787 0.888 0.000 0.000 0.112
#> GSM782702     1  0.0000      0.834 1.000 0.000 0.000 0.000
#> GSM782703     3  0.2466      0.935 0.028 0.000 0.916 0.056
#> GSM782704     3  0.0921      0.933 0.028 0.000 0.972 0.000
#> GSM782705     1  0.1716      0.839 0.936 0.000 0.000 0.064
#> GSM782706     1  0.2921      0.787 0.860 0.000 0.000 0.140
#> GSM782707     1  0.2530      0.787 0.888 0.000 0.000 0.112
#> GSM782708     3  0.0921      0.933 0.028 0.000 0.972 0.000
#> GSM782709     1  0.0000      0.834 1.000 0.000 0.000 0.000
#> GSM782710     1  0.0000      0.834 1.000 0.000 0.000 0.000
#> GSM782711     1  0.0469      0.835 0.988 0.000 0.000 0.012
#> GSM782712     1  0.0469      0.835 0.988 0.000 0.000 0.012
#> GSM782713     3  0.3962      0.933 0.028 0.000 0.820 0.152
#> GSM782714     2  0.1520      0.971 0.020 0.956 0.000 0.024
#> GSM782715     1  0.4277      0.580 0.720 0.000 0.000 0.280
#> GSM782716     3  0.0921      0.933 0.028 0.000 0.972 0.000
#> GSM782717     1  0.1867      0.836 0.928 0.000 0.000 0.072
#> GSM782718     1  0.4164      0.623 0.736 0.000 0.000 0.264
#> GSM782719     1  0.2530      0.787 0.888 0.000 0.000 0.112
#> GSM782720     3  0.3962      0.933 0.028 0.000 0.820 0.152
#> GSM782721     1  0.2921      0.787 0.860 0.000 0.000 0.140
#> GSM782722     4  0.4697      0.991 0.356 0.000 0.000 0.644
#> GSM782723     2  0.1520      0.971 0.020 0.956 0.000 0.024
#> GSM782724     2  0.2973      0.942 0.020 0.884 0.000 0.096
#> GSM782725     4  0.4713      0.996 0.360 0.000 0.000 0.640
#> GSM782726     1  0.1867      0.836 0.928 0.000 0.000 0.072
#> GSM782727     3  0.3962      0.933 0.028 0.000 0.820 0.152
#> GSM782728     2  0.0707      0.972 0.020 0.980 0.000 0.000
#> GSM782729     4  0.4713      0.996 0.360 0.000 0.000 0.640
#> GSM782730     3  0.3962      0.933 0.028 0.000 0.820 0.152
#> GSM782731     1  0.2081      0.829 0.916 0.000 0.000 0.084
#> GSM782732     1  0.2081      0.829 0.916 0.000 0.000 0.084
#> GSM782733     3  0.0921      0.933 0.028 0.000 0.972 0.000
#> GSM782734     1  0.1867      0.836 0.928 0.000 0.000 0.072
#> GSM782735     2  0.2977      0.947 0.020 0.904 0.024 0.052
#> GSM782736     1  0.4454      0.478 0.692 0.000 0.000 0.308
#> GSM782737     2  0.1520      0.971 0.020 0.956 0.000 0.024
#> GSM782738     1  0.4164      0.623 0.736 0.000 0.000 0.264
#> GSM782739     1  0.1867      0.836 0.928 0.000 0.000 0.072
#> GSM782740     2  0.0707      0.972 0.020 0.980 0.000 0.000
#> GSM782741     1  0.1867      0.836 0.928 0.000 0.000 0.072
#> GSM782742     3  0.3962      0.933 0.028 0.000 0.820 0.152
#> GSM782743     3  0.0921      0.933 0.028 0.000 0.972 0.000
#> GSM782744     3  0.4640      0.906 0.028 0.020 0.800 0.152
#> GSM782745     1  0.1867      0.836 0.928 0.000 0.000 0.072
#> GSM782746     2  0.2977      0.947 0.020 0.904 0.024 0.052

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1    p2    p3    p4 p5
#> GSM782696     1  0.4210      0.707 0.588 0.000 0.000 0.000 NA
#> GSM782697     1  0.4084      0.718 0.668 0.000 0.000 0.004 NA
#> GSM782698     1  0.4557      0.673 0.516 0.000 0.000 0.008 NA
#> GSM782699     1  0.4196      0.718 0.640 0.000 0.000 0.004 NA
#> GSM782700     2  0.0162      0.937 0.000 0.996 0.000 0.004 NA
#> GSM782701     1  0.4637      0.678 0.536 0.000 0.000 0.012 NA
#> GSM782702     1  0.3932      0.720 0.672 0.000 0.000 0.000 NA
#> GSM782703     3  0.0510      0.879 0.000 0.000 0.984 0.016 NA
#> GSM782704     3  0.2520      0.874 0.000 0.000 0.896 0.048 NA
#> GSM782705     1  0.4029      0.725 0.680 0.000 0.000 0.004 NA
#> GSM782706     1  0.4576      0.666 0.608 0.000 0.000 0.016 NA
#> GSM782707     1  0.4637      0.678 0.536 0.000 0.000 0.012 NA
#> GSM782708     3  0.2520      0.874 0.000 0.000 0.896 0.048 NA
#> GSM782709     1  0.2813      0.704 0.832 0.000 0.000 0.000 NA
#> GSM782710     1  0.2966      0.697 0.816 0.000 0.000 0.000 NA
#> GSM782711     1  0.4114      0.716 0.624 0.000 0.000 0.000 NA
#> GSM782712     1  0.4470      0.714 0.616 0.000 0.000 0.012 NA
#> GSM782713     3  0.3201      0.876 0.000 0.000 0.852 0.096 NA
#> GSM782714     2  0.1701      0.933 0.000 0.936 0.000 0.016 NA
#> GSM782715     1  0.5772      0.503 0.584 0.000 0.000 0.120 NA
#> GSM782716     3  0.2520      0.874 0.000 0.000 0.896 0.048 NA
#> GSM782717     1  0.0162      0.666 0.996 0.000 0.000 0.000 NA
#> GSM782718     1  0.5525      0.558 0.612 0.000 0.000 0.100 NA
#> GSM782719     1  0.4637      0.678 0.536 0.000 0.000 0.012 NA
#> GSM782720     3  0.3201      0.876 0.000 0.000 0.852 0.096 NA
#> GSM782721     1  0.4576      0.666 0.608 0.000 0.000 0.016 NA
#> GSM782722     4  0.4832      1.000 0.200 0.000 0.000 0.712 NA
#> GSM782723     2  0.1701      0.933 0.000 0.936 0.000 0.016 NA
#> GSM782724     2  0.3648      0.876 0.000 0.824 0.000 0.084 NA
#> GSM782725     4  0.4832      1.000 0.200 0.000 0.000 0.712 NA
#> GSM782726     1  0.0290      0.660 0.992 0.000 0.000 0.000 NA
#> GSM782727     3  0.3201      0.876 0.000 0.000 0.852 0.096 NA
#> GSM782728     2  0.0162      0.937 0.000 0.996 0.000 0.000 NA
#> GSM782729     4  0.4832      1.000 0.200 0.000 0.000 0.712 NA
#> GSM782730     3  0.3201      0.876 0.000 0.000 0.852 0.096 NA
#> GSM782731     1  0.0671      0.655 0.980 0.000 0.000 0.004 NA
#> GSM782732     1  0.0671      0.655 0.980 0.000 0.000 0.004 NA
#> GSM782733     3  0.2520      0.874 0.000 0.000 0.896 0.048 NA
#> GSM782734     1  0.0290      0.660 0.992 0.000 0.000 0.000 NA
#> GSM782735     2  0.2824      0.887 0.000 0.872 0.000 0.032 NA
#> GSM782736     1  0.5964      0.398 0.588 0.000 0.000 0.180 NA
#> GSM782737     2  0.1701      0.933 0.000 0.936 0.000 0.016 NA
#> GSM782738     1  0.5487      0.556 0.620 0.000 0.000 0.100 NA
#> GSM782739     1  0.0000      0.664 1.000 0.000 0.000 0.000 NA
#> GSM782740     2  0.0162      0.937 0.000 0.996 0.000 0.000 NA
#> GSM782741     1  0.0000      0.664 1.000 0.000 0.000 0.000 NA
#> GSM782742     3  0.3201      0.876 0.000 0.000 0.852 0.096 NA
#> GSM782743     3  0.2520      0.874 0.000 0.000 0.896 0.048 NA
#> GSM782744     3  0.5004      0.807 0.000 0.000 0.672 0.072 NA
#> GSM782745     1  0.0290      0.660 0.992 0.000 0.000 0.000 NA
#> GSM782746     2  0.2824      0.887 0.000 0.872 0.000 0.032 NA

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4 p5    p6
#> GSM782696     1  0.0603      0.658 0.980 0.000 0.000 0.000 NA 0.016
#> GSM782697     1  0.2350      0.616 0.880 0.000 0.000 0.000 NA 0.100
#> GSM782698     1  0.1552      0.653 0.940 0.000 0.000 0.004 NA 0.020
#> GSM782699     1  0.2250      0.622 0.888 0.000 0.000 0.000 NA 0.092
#> GSM782700     2  0.0291      0.911 0.000 0.992 0.000 0.004 NA 0.000
#> GSM782701     1  0.2100      0.653 0.884 0.000 0.000 0.000 NA 0.004
#> GSM782702     1  0.2454      0.584 0.840 0.000 0.000 0.000 NA 0.160
#> GSM782703     3  0.2572      0.840 0.000 0.000 0.852 0.000 NA 0.012
#> GSM782704     3  0.3499      0.832 0.000 0.000 0.680 0.000 NA 0.000
#> GSM782705     1  0.3752      0.561 0.776 0.000 0.000 0.004 NA 0.168
#> GSM782706     1  0.5299      0.489 0.612 0.000 0.000 0.004 NA 0.156
#> GSM782707     1  0.1957      0.654 0.888 0.000 0.000 0.000 NA 0.000
#> GSM782708     3  0.3499      0.832 0.000 0.000 0.680 0.000 NA 0.000
#> GSM782709     1  0.4226     -0.287 0.504 0.000 0.000 0.004 NA 0.484
#> GSM782710     1  0.3999     -0.293 0.500 0.000 0.000 0.000 NA 0.496
#> GSM782711     1  0.1391      0.649 0.944 0.000 0.000 0.000 NA 0.040
#> GSM782712     1  0.2867      0.650 0.848 0.000 0.000 0.000 NA 0.040
#> GSM782713     3  0.0260      0.835 0.000 0.000 0.992 0.000 NA 0.008
#> GSM782714     2  0.1921      0.905 0.000 0.920 0.000 0.012 NA 0.012
#> GSM782715     1  0.6941      0.310 0.464 0.000 0.000 0.092 NA 0.212
#> GSM782716     3  0.3619      0.832 0.000 0.000 0.680 0.000 NA 0.004
#> GSM782717     6  0.2996      0.964 0.228 0.000 0.000 0.000 NA 0.772
#> GSM782718     1  0.6486      0.384 0.540 0.000 0.000 0.076 NA 0.188
#> GSM782719     1  0.1910      0.654 0.892 0.000 0.000 0.000 NA 0.000
#> GSM782720     3  0.0000      0.835 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782721     1  0.5299      0.489 0.612 0.000 0.000 0.004 NA 0.156
#> GSM782722     4  0.2934      0.993 0.112 0.000 0.000 0.844 NA 0.044
#> GSM782723     2  0.2015      0.905 0.000 0.916 0.000 0.012 NA 0.016
#> GSM782724     2  0.4178      0.812 0.000 0.748 0.000 0.016 NA 0.052
#> GSM782725     4  0.2954      0.996 0.108 0.000 0.000 0.844 NA 0.048
#> GSM782726     6  0.2969      0.963 0.224 0.000 0.000 0.000 NA 0.776
#> GSM782727     3  0.0146      0.835 0.000 0.000 0.996 0.000 NA 0.004
#> GSM782728     2  0.0260      0.910 0.000 0.992 0.000 0.000 NA 0.000
#> GSM782729     4  0.2954      0.996 0.108 0.000 0.000 0.844 NA 0.048
#> GSM782730     3  0.0146      0.835 0.000 0.000 0.996 0.000 NA 0.004
#> GSM782731     6  0.4064      0.897 0.236 0.000 0.000 0.004 NA 0.720
#> GSM782732     6  0.4064      0.897 0.236 0.000 0.000 0.004 NA 0.720
#> GSM782733     3  0.3619      0.832 0.000 0.000 0.680 0.000 NA 0.004
#> GSM782734     6  0.2969      0.963 0.224 0.000 0.000 0.000 NA 0.776
#> GSM782735     2  0.3659      0.840 0.000 0.824 0.000 0.064 NA 0.044
#> GSM782736     1  0.7430      0.132 0.380 0.000 0.000 0.164 NA 0.268
#> GSM782737     2  0.1921      0.905 0.000 0.920 0.000 0.012 NA 0.012
#> GSM782738     1  0.6770      0.308 0.488 0.000 0.000 0.080 NA 0.232
#> GSM782739     6  0.2996      0.964 0.228 0.000 0.000 0.000 NA 0.772
#> GSM782740     2  0.0260      0.910 0.000 0.992 0.000 0.000 NA 0.000
#> GSM782741     6  0.2996      0.964 0.228 0.000 0.000 0.000 NA 0.772
#> GSM782742     3  0.0000      0.835 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782743     3  0.3619      0.832 0.000 0.000 0.680 0.000 NA 0.004
#> GSM782744     3  0.4958      0.762 0.000 0.000 0.708 0.068 NA 0.056
#> GSM782745     6  0.2969      0.963 0.224 0.000 0.000 0.000 NA 0.776
#> GSM782746     2  0.3659      0.840 0.000 0.824 0.000 0.064 NA 0.044

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-kmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-SD-kmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-SD-kmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-SD-kmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-SD-kmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-kmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-SD-kmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-SD-kmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-SD-kmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-SD-kmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-kmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-SD-kmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-SD-kmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-SD-kmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-SD-kmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-kmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-SD-kmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-SD-kmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-SD-kmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-SD-kmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-kmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-SD-kmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-SD-kmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-SD-kmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-SD-kmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>            n agent(p) k
#> SD:kmeans 51    0.648 2
#> SD:kmeans 51    0.642 3
#> SD:kmeans 50    0.497 4
#> SD:kmeans 50    0.497 5
#> SD:kmeans 43    0.446 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:skmeans*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "skmeans"]
# you can also extract it by
# res = res_list["SD:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.633           0.897       0.915         0.4236 0.506   0.506
#> 3 3 1.000           1.000       1.000         0.3674 0.915   0.833
#> 4 4 0.844           0.774       0.890         0.2200 0.902   0.767
#> 5 5 0.909           0.819       0.929         0.1236 0.887   0.650
#> 6 6 0.865           0.762       0.835         0.0392 0.964   0.830

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 3

There is also optional best \(k\) = 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette   p1   p2
#> GSM782696     1   0.000      1.000 1.00 0.00
#> GSM782697     1   0.000      1.000 1.00 0.00
#> GSM782698     1   0.000      1.000 1.00 0.00
#> GSM782699     1   0.000      1.000 1.00 0.00
#> GSM782700     2   0.000      0.756 0.00 1.00
#> GSM782701     1   0.000      1.000 1.00 0.00
#> GSM782702     1   0.000      1.000 1.00 0.00
#> GSM782703     2   0.943      0.747 0.36 0.64
#> GSM782704     2   0.943      0.747 0.36 0.64
#> GSM782705     1   0.000      1.000 1.00 0.00
#> GSM782706     1   0.000      1.000 1.00 0.00
#> GSM782707     1   0.000      1.000 1.00 0.00
#> GSM782708     2   0.943      0.747 0.36 0.64
#> GSM782709     1   0.000      1.000 1.00 0.00
#> GSM782710     1   0.000      1.000 1.00 0.00
#> GSM782711     1   0.000      1.000 1.00 0.00
#> GSM782712     1   0.000      1.000 1.00 0.00
#> GSM782713     2   0.943      0.747 0.36 0.64
#> GSM782714     2   0.000      0.756 0.00 1.00
#> GSM782715     1   0.000      1.000 1.00 0.00
#> GSM782716     2   0.943      0.747 0.36 0.64
#> GSM782717     1   0.000      1.000 1.00 0.00
#> GSM782718     1   0.000      1.000 1.00 0.00
#> GSM782719     1   0.000      1.000 1.00 0.00
#> GSM782720     2   0.943      0.747 0.36 0.64
#> GSM782721     1   0.000      1.000 1.00 0.00
#> GSM782722     1   0.000      1.000 1.00 0.00
#> GSM782723     2   0.000      0.756 0.00 1.00
#> GSM782724     2   0.000      0.756 0.00 1.00
#> GSM782725     1   0.000      1.000 1.00 0.00
#> GSM782726     1   0.000      1.000 1.00 0.00
#> GSM782727     2   0.943      0.747 0.36 0.64
#> GSM782728     2   0.000      0.756 0.00 1.00
#> GSM782729     1   0.000      1.000 1.00 0.00
#> GSM782730     2   0.943      0.747 0.36 0.64
#> GSM782731     1   0.000      1.000 1.00 0.00
#> GSM782732     1   0.000      1.000 1.00 0.00
#> GSM782733     2   0.943      0.747 0.36 0.64
#> GSM782734     1   0.000      1.000 1.00 0.00
#> GSM782735     2   0.000      0.756 0.00 1.00
#> GSM782736     1   0.000      1.000 1.00 0.00
#> GSM782737     2   0.000      0.756 0.00 1.00
#> GSM782738     1   0.000      1.000 1.00 0.00
#> GSM782739     1   0.000      1.000 1.00 0.00
#> GSM782740     2   0.000      0.756 0.00 1.00
#> GSM782741     1   0.000      1.000 1.00 0.00
#> GSM782742     2   0.943      0.747 0.36 0.64
#> GSM782743     2   0.943      0.747 0.36 0.64
#> GSM782744     2   0.943      0.747 0.36 0.64
#> GSM782745     1   0.000      1.000 1.00 0.00
#> GSM782746     2   0.000      0.756 0.00 1.00

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1  0.0336      0.726 0.992  0  0 0.008
#> GSM782697     1  0.1302      0.720 0.956  0  0 0.044
#> GSM782698     1  0.2216      0.666 0.908  0  0 0.092
#> GSM782699     1  0.0000      0.727 1.000  0  0 0.000
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782701     1  0.0336      0.726 0.992  0  0 0.008
#> GSM782702     1  0.1389      0.718 0.952  0  0 0.048
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782705     1  0.4877      0.401 0.592  0  0 0.408
#> GSM782706     1  0.0469      0.726 0.988  0  0 0.012
#> GSM782707     1  0.0336      0.726 0.992  0  0 0.008
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782709     1  0.2011      0.708 0.920  0  0 0.080
#> GSM782710     1  0.2011      0.708 0.920  0  0 0.080
#> GSM782711     1  0.0000      0.727 1.000  0  0 0.000
#> GSM782712     1  0.0188      0.726 0.996  0  0 0.004
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782715     4  0.5000     -0.289 0.496  0  0 0.504
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782717     1  0.4817      0.564 0.612  0  0 0.388
#> GSM782718     1  0.4925      0.361 0.572  0  0 0.428
#> GSM782719     1  0.0336      0.726 0.992  0  0 0.008
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782721     1  0.0469      0.726 0.988  0  0 0.012
#> GSM782722     4  0.1940      0.836 0.076  0  0 0.924
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782725     4  0.1940      0.836 0.076  0  0 0.924
#> GSM782726     1  0.4817      0.564 0.612  0  0 0.388
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782729     4  0.1940      0.836 0.076  0  0 0.924
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782731     1  0.4994      0.419 0.520  0  0 0.480
#> GSM782732     1  0.4994      0.419 0.520  0  0 0.480
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782734     1  0.4817      0.564 0.612  0  0 0.388
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782736     4  0.1940      0.836 0.076  0  0 0.924
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782738     1  0.4925      0.361 0.572  0  0 0.428
#> GSM782739     1  0.4830      0.559 0.608  0  0 0.392
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782741     1  0.4817      0.564 0.612  0  0 0.388
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782745     1  0.4817      0.564 0.612  0  0 0.388
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2 p3    p4    p5
#> GSM782696     1  0.0162     0.8067 0.996  0  0 0.000 0.004
#> GSM782697     1  0.0000     0.8058 1.000  0  0 0.000 0.000
#> GSM782698     1  0.0000     0.8058 1.000  0  0 0.000 0.000
#> GSM782699     1  0.0000     0.8058 1.000  0  0 0.000 0.000
#> GSM782700     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782701     1  0.0290     0.8061 0.992  0  0 0.000 0.008
#> GSM782702     1  0.0794     0.7975 0.972  0  0 0.000 0.028
#> GSM782703     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782704     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782705     1  0.4496     0.5312 0.728  0  0 0.216 0.056
#> GSM782706     1  0.3838     0.5910 0.716  0  0 0.004 0.280
#> GSM782707     1  0.0162     0.8067 0.996  0  0 0.000 0.004
#> GSM782708     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782709     1  0.4307     0.0758 0.500  0  0 0.000 0.500
#> GSM782710     5  0.4219     0.2169 0.416  0  0 0.000 0.584
#> GSM782711     1  0.0000     0.8058 1.000  0  0 0.000 0.000
#> GSM782712     1  0.0290     0.8060 0.992  0  0 0.000 0.008
#> GSM782713     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782715     4  0.6563     0.0326 0.356  0  0 0.436 0.208
#> GSM782716     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782717     5  0.0451     0.9044 0.004  0  0 0.008 0.988
#> GSM782718     1  0.6145     0.2220 0.532  0  0 0.312 0.156
#> GSM782719     1  0.0162     0.8067 0.996  0  0 0.000 0.004
#> GSM782720     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782721     1  0.3906     0.5765 0.704  0  0 0.004 0.292
#> GSM782722     4  0.0000     0.8342 0.000  0  0 1.000 0.000
#> GSM782723     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782725     4  0.0000     0.8342 0.000  0  0 1.000 0.000
#> GSM782726     5  0.0000     0.9073 0.000  0  0 0.000 1.000
#> GSM782727     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782729     4  0.0000     0.8342 0.000  0  0 1.000 0.000
#> GSM782730     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782731     5  0.1478     0.8670 0.000  0  0 0.064 0.936
#> GSM782732     5  0.1704     0.8616 0.004  0  0 0.068 0.928
#> GSM782733     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782734     5  0.0000     0.9073 0.000  0  0 0.000 1.000
#> GSM782735     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782736     4  0.1408     0.8083 0.008  0  0 0.948 0.044
#> GSM782737     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782738     1  0.6652    -0.0239 0.420  0  0 0.348 0.232
#> GSM782739     5  0.0000     0.9073 0.000  0  0 0.000 1.000
#> GSM782740     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782741     5  0.0162     0.9063 0.004  0  0 0.000 0.996
#> GSM782742     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782743     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782744     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782745     5  0.0000     0.9073 0.000  0  0 0.000 1.000
#> GSM782746     2  0.0000     1.0000 0.000  1  0 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1  0.1444   0.679052 0.928  0 0.000 0.000 0.072 0.000
#> GSM782697     1  0.3838   0.536810 0.552  0 0.000 0.000 0.448 0.000
#> GSM782698     1  0.3833   0.536679 0.556  0 0.000 0.000 0.444 0.000
#> GSM782699     1  0.3838   0.536810 0.552  0 0.000 0.000 0.448 0.000
#> GSM782700     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     1  0.0713   0.671091 0.972  0 0.000 0.000 0.028 0.000
#> GSM782702     1  0.2190   0.670095 0.900  0 0.000 0.000 0.060 0.040
#> GSM782703     3  0.0146   0.998077 0.000  0 0.996 0.000 0.004 0.000
#> GSM782704     3  0.0146   0.998077 0.000  0 0.996 0.000 0.004 0.000
#> GSM782705     5  0.6218   0.511471 0.332  0 0.000 0.076 0.508 0.084
#> GSM782706     1  0.4328   0.436348 0.716  0 0.000 0.000 0.192 0.092
#> GSM782707     1  0.0260   0.678474 0.992  0 0.000 0.000 0.008 0.000
#> GSM782708     3  0.0146   0.998077 0.000  0 0.996 0.000 0.004 0.000
#> GSM782709     1  0.5932   0.164048 0.396  0 0.000 0.000 0.212 0.392
#> GSM782710     6  0.5157   0.055179 0.404  0 0.000 0.000 0.088 0.508
#> GSM782711     1  0.3198   0.623507 0.740  0 0.000 0.000 0.260 0.000
#> GSM782712     1  0.0508   0.677154 0.984  0 0.000 0.000 0.012 0.004
#> GSM782713     3  0.0000   0.998077 0.000  0 1.000 0.000 0.000 0.000
#> GSM782714     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     5  0.6841   0.748444 0.240  0 0.000 0.200 0.476 0.084
#> GSM782716     3  0.0146   0.998077 0.000  0 0.996 0.000 0.004 0.000
#> GSM782717     6  0.3253   0.693623 0.020  0 0.000 0.000 0.192 0.788
#> GSM782718     5  0.6573   0.771722 0.240  0 0.000 0.148 0.524 0.088
#> GSM782719     1  0.0790   0.683032 0.968  0 0.000 0.000 0.032 0.000
#> GSM782720     3  0.0000   0.998077 0.000  0 1.000 0.000 0.000 0.000
#> GSM782721     1  0.4418   0.429022 0.708  0 0.000 0.000 0.192 0.100
#> GSM782722     4  0.0146   0.804795 0.000  0 0.000 0.996 0.004 0.000
#> GSM782723     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     4  0.0000   0.805807 0.000  0 0.000 1.000 0.000 0.000
#> GSM782726     6  0.0458   0.710849 0.000  0 0.000 0.000 0.016 0.984
#> GSM782727     3  0.0000   0.998077 0.000  0 1.000 0.000 0.000 0.000
#> GSM782728     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     4  0.0000   0.805807 0.000  0 0.000 1.000 0.000 0.000
#> GSM782730     3  0.0000   0.998077 0.000  0 1.000 0.000 0.000 0.000
#> GSM782731     6  0.4722   0.516941 0.008  0 0.000 0.056 0.296 0.640
#> GSM782732     6  0.4901   0.492449 0.012  0 0.000 0.060 0.304 0.624
#> GSM782733     3  0.0146   0.998077 0.000  0 0.996 0.000 0.004 0.000
#> GSM782734     6  0.0146   0.715128 0.000  0 0.000 0.000 0.004 0.996
#> GSM782735     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     4  0.4791  -0.000624 0.004  0 0.000 0.564 0.384 0.048
#> GSM782737     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     5  0.6855   0.770632 0.264  0 0.000 0.172 0.472 0.092
#> GSM782739     6  0.2669   0.716749 0.008  0 0.000 0.000 0.156 0.836
#> GSM782740     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     6  0.3190   0.708183 0.044  0 0.000 0.000 0.136 0.820
#> GSM782742     3  0.0000   0.998077 0.000  0 1.000 0.000 0.000 0.000
#> GSM782743     3  0.0146   0.998077 0.000  0 0.996 0.000 0.004 0.000
#> GSM782744     3  0.0000   0.998077 0.000  0 1.000 0.000 0.000 0.000
#> GSM782745     6  0.0458   0.710849 0.000  0 0.000 0.000 0.016 0.984
#> GSM782746     2  0.0000   1.000000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-skmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-SD-skmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-SD-skmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-SD-skmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-SD-skmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-skmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-SD-skmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-SD-skmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-SD-skmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-SD-skmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-skmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-SD-skmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-SD-skmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-SD-skmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-SD-skmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-skmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-SD-skmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-SD-skmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-SD-skmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-SD-skmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-skmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-SD-skmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-SD-skmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-SD-skmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-SD-skmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> SD:skmeans 51    0.493 2
#> SD:skmeans 51    0.642 3
#> SD:skmeans 45    0.474 4
#> SD:skmeans 46    0.476 5
#> SD:skmeans 45    0.394 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:pam**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "pam"]
# you can also extract it by
# res = res_list["SD:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.820           0.847       0.885         0.2357 0.824   0.583
#> 5 5 0.822           0.794       0.883         0.0873 0.949   0.801
#> 6 6 0.879           0.852       0.933         0.0315 0.973   0.873

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782697     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782698     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782699     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782701     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782702     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782705     4  0.2216      0.651 0.092  0  0 0.908
#> GSM782706     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782707     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782709     1  0.4697      0.944 0.644  0  0 0.356
#> GSM782710     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782711     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782712     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782715     4  0.4250      0.287 0.276  0  0 0.724
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782717     4  0.0000      0.737 0.000  0  0 1.000
#> GSM782718     4  0.0000      0.737 0.000  0  0 1.000
#> GSM782719     1  0.4585      0.980 0.668  0  0 0.332
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782721     1  0.4972      0.738 0.544  0  0 0.456
#> GSM782722     4  0.4585      0.538 0.332  0  0 0.668
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782725     4  0.4585      0.538 0.332  0  0 0.668
#> GSM782726     4  0.4008      0.387 0.244  0  0 0.756
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782729     4  0.4585      0.538 0.332  0  0 0.668
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782731     4  0.0000      0.737 0.000  0  0 1.000
#> GSM782732     4  0.0000      0.737 0.000  0  0 1.000
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782734     4  0.3610      0.498 0.200  0  0 0.800
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782736     4  0.0469      0.732 0.012  0  0 0.988
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782738     4  0.0000      0.737 0.000  0  0 1.000
#> GSM782739     4  0.0000      0.737 0.000  0  0 1.000
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782741     4  0.4866     -0.356 0.404  0  0 0.596
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782745     4  0.3444      0.528 0.184  0  0 0.816
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782697     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782698     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782699     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782702     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782703     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782704     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782705     5  0.3895      0.363 0.320  0 0.000 0.000 0.680
#> GSM782706     1  0.3210      0.675 0.788  0 0.000 0.000 0.212
#> GSM782707     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782708     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782709     1  0.3395      0.643 0.764  0 0.000 0.000 0.236
#> GSM782710     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782711     1  0.0290      0.887 0.992  0 0.000 0.000 0.008
#> GSM782712     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782713     3  0.0000      0.762 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     1  0.4126      0.170 0.620  0 0.000 0.000 0.380
#> GSM782716     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782717     5  0.0609      0.691 0.020  0 0.000 0.000 0.980
#> GSM782718     5  0.2280      0.612 0.120  0 0.000 0.000 0.880
#> GSM782719     1  0.0000      0.892 1.000  0 0.000 0.000 0.000
#> GSM782720     3  0.0000      0.762 0.000  0 1.000 0.000 0.000
#> GSM782721     1  0.3966      0.449 0.664  0 0.000 0.000 0.336
#> GSM782722     4  0.4101      1.000 0.000  0 0.000 0.628 0.372
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.4101      1.000 0.000  0 0.000 0.628 0.372
#> GSM782726     5  0.3876      0.550 0.316  0 0.000 0.000 0.684
#> GSM782727     3  0.0000      0.762 0.000  0 1.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.4101      1.000 0.000  0 0.000 0.628 0.372
#> GSM782730     3  0.0000      0.762 0.000  0 1.000 0.000 0.000
#> GSM782731     5  0.0609      0.691 0.020  0 0.000 0.000 0.980
#> GSM782732     5  0.0609      0.691 0.020  0 0.000 0.000 0.980
#> GSM782733     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782734     5  0.3586      0.597 0.264  0 0.000 0.000 0.736
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     5  0.0609      0.691 0.020  0 0.000 0.000 0.980
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     5  0.1197      0.680 0.048  0 0.000 0.000 0.952
#> GSM782739     5  0.0609      0.691 0.020  0 0.000 0.000 0.980
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     5  0.4278      0.192 0.452  0 0.000 0.000 0.548
#> GSM782742     3  0.0000      0.762 0.000  0 1.000 0.000 0.000
#> GSM782743     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782744     3  0.4101      0.838 0.000  0 0.628 0.372 0.000
#> GSM782745     5  0.3452      0.612 0.244  0 0.000 0.000 0.756
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3 p4    p5    p6
#> GSM782696     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782697     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782698     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782699     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782701     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782702     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782703     3  0.1327      0.986 0.000  0 0.936  0 0.064 0.000
#> GSM782704     3  0.1327      0.986 0.000  0 0.936  0 0.064 0.000
#> GSM782705     6  0.3309      0.539 0.280  0 0.000  0 0.000 0.720
#> GSM782706     1  0.2883      0.681 0.788  0 0.000  0 0.000 0.212
#> GSM782707     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782708     3  0.1327      0.986 0.000  0 0.936  0 0.064 0.000
#> GSM782709     1  0.3050      0.648 0.764  0 0.000  0 0.000 0.236
#> GSM782710     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782711     1  0.0260      0.902 0.992  0 0.000  0 0.000 0.008
#> GSM782712     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782713     5  0.0000      1.000 0.000  0 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782715     1  0.2854      0.659 0.792  0 0.000  0 0.000 0.208
#> GSM782716     3  0.1387      0.983 0.000  0 0.932  0 0.068 0.000
#> GSM782717     6  0.0000      0.740 0.000  0 0.000  0 0.000 1.000
#> GSM782718     6  0.1814      0.692 0.100  0 0.000  0 0.000 0.900
#> GSM782719     1  0.0000      0.907 1.000  0 0.000  0 0.000 0.000
#> GSM782720     5  0.0000      1.000 0.000  0 0.000  0 1.000 0.000
#> GSM782721     1  0.3531      0.460 0.672  0 0.000  0 0.000 0.328
#> GSM782722     4  0.0000      1.000 0.000  0 0.000  1 0.000 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782725     4  0.0000      1.000 0.000  0 0.000  1 0.000 0.000
#> GSM782726     6  0.3810      0.304 0.428  0 0.000  0 0.000 0.572
#> GSM782727     5  0.0000      1.000 0.000  0 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782729     4  0.0000      1.000 0.000  0 0.000  1 0.000 0.000
#> GSM782730     5  0.0000      1.000 0.000  0 0.000  0 1.000 0.000
#> GSM782731     6  0.0000      0.740 0.000  0 0.000  0 0.000 1.000
#> GSM782732     6  0.0000      0.740 0.000  0 0.000  0 0.000 1.000
#> GSM782733     3  0.1327      0.986 0.000  0 0.936  0 0.064 0.000
#> GSM782734     6  0.3765      0.370 0.404  0 0.000  0 0.000 0.596
#> GSM782735     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782736     6  0.0000      0.740 0.000  0 0.000  0 0.000 1.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782738     6  0.0713      0.733 0.028  0 0.000  0 0.000 0.972
#> GSM782739     6  0.0000      0.740 0.000  0 0.000  0 0.000 1.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782741     6  0.3737      0.413 0.392  0 0.000  0 0.000 0.608
#> GSM782742     5  0.0000      1.000 0.000  0 0.000  0 1.000 0.000
#> GSM782743     3  0.1327      0.986 0.000  0 0.936  0 0.064 0.000
#> GSM782744     3  0.0713      0.914 0.000  0 0.972  0 0.028 0.000
#> GSM782745     6  0.3672      0.449 0.368  0 0.000  0 0.000 0.632
#> GSM782746     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-pam-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-SD-pam-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-SD-pam-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-SD-pam-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-SD-pam-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-pam-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-SD-pam-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-SD-pam-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-SD-pam-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-SD-pam-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-pam-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-SD-pam-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-SD-pam-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-SD-pam-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-SD-pam-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-pam-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-SD-pam-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-SD-pam-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-SD-pam-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-SD-pam-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-pam-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-SD-pam-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-SD-pam-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-SD-pam-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-SD-pam-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>         n agent(p) k
#> SD:pam 51    0.648 2
#> SD:pam 51    0.642 3
#> SD:pam 47    0.515 4
#> SD:pam 47    0.452 5
#> SD:pam 46    0.424 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:mclust*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "mclust"]
# you can also extract it by
# res = res_list["SD:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.639           0.932       0.945         0.4637 0.506   0.506
#> 3 3 0.969           0.941       0.973         0.2855 0.915   0.833
#> 4 4 1.000           0.966       0.989         0.0961 0.918   0.806
#> 5 5 0.909           0.882       0.944         0.0903 0.941   0.828
#> 6 6 0.780           0.811       0.904         0.0641 0.971   0.899

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 3 4

There is also optional best \(k\) = 3 4 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.000      0.985 1.000 0.000
#> GSM782697     1   0.000      0.985 1.000 0.000
#> GSM782698     1   0.000      0.985 1.000 0.000
#> GSM782699     1   0.000      0.985 1.000 0.000
#> GSM782700     2   0.000      0.870 0.000 1.000
#> GSM782701     1   0.000      0.985 1.000 0.000
#> GSM782702     1   0.000      0.985 1.000 0.000
#> GSM782703     2   0.714      0.887 0.196 0.804
#> GSM782704     2   0.714      0.887 0.196 0.804
#> GSM782705     1   0.000      0.985 1.000 0.000
#> GSM782706     1   0.000      0.985 1.000 0.000
#> GSM782707     1   0.000      0.985 1.000 0.000
#> GSM782708     2   0.714      0.887 0.196 0.804
#> GSM782709     1   0.000      0.985 1.000 0.000
#> GSM782710     1   0.000      0.985 1.000 0.000
#> GSM782711     1   0.000      0.985 1.000 0.000
#> GSM782712     1   0.000      0.985 1.000 0.000
#> GSM782713     2   0.714      0.887 0.196 0.804
#> GSM782714     2   0.000      0.870 0.000 1.000
#> GSM782715     1   0.000      0.985 1.000 0.000
#> GSM782716     2   0.714      0.887 0.196 0.804
#> GSM782717     1   0.000      0.985 1.000 0.000
#> GSM782718     1   0.000      0.985 1.000 0.000
#> GSM782719     1   0.000      0.985 1.000 0.000
#> GSM782720     2   0.714      0.887 0.196 0.804
#> GSM782721     1   0.000      0.985 1.000 0.000
#> GSM782722     1   0.584      0.838 0.860 0.140
#> GSM782723     2   0.000      0.870 0.000 1.000
#> GSM782724     2   0.000      0.870 0.000 1.000
#> GSM782725     1   0.584      0.838 0.860 0.140
#> GSM782726     1   0.000      0.985 1.000 0.000
#> GSM782727     2   0.714      0.887 0.196 0.804
#> GSM782728     2   0.000      0.870 0.000 1.000
#> GSM782729     1   0.443      0.889 0.908 0.092
#> GSM782730     2   0.714      0.887 0.196 0.804
#> GSM782731     1   0.000      0.985 1.000 0.000
#> GSM782732     1   0.000      0.985 1.000 0.000
#> GSM782733     2   0.714      0.887 0.196 0.804
#> GSM782734     1   0.000      0.985 1.000 0.000
#> GSM782735     2   0.000      0.870 0.000 1.000
#> GSM782736     1   0.000      0.985 1.000 0.000
#> GSM782737     2   0.000      0.870 0.000 1.000
#> GSM782738     1   0.000      0.985 1.000 0.000
#> GSM782739     1   0.000      0.985 1.000 0.000
#> GSM782740     2   0.000      0.870 0.000 1.000
#> GSM782741     1   0.000      0.985 1.000 0.000
#> GSM782742     2   0.714      0.887 0.196 0.804
#> GSM782743     2   0.738      0.875 0.208 0.792
#> GSM782744     2   0.844      0.794 0.272 0.728
#> GSM782745     1   0.000      0.985 1.000 0.000
#> GSM782746     2   0.000      0.870 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1   0.000      0.953 1.000 0.000 0.000
#> GSM782697     1   0.000      0.953 1.000 0.000 0.000
#> GSM782698     1   0.000      0.953 1.000 0.000 0.000
#> GSM782699     1   0.000      0.953 1.000 0.000 0.000
#> GSM782700     2   0.000      1.000 0.000 1.000 0.000
#> GSM782701     1   0.000      0.953 1.000 0.000 0.000
#> GSM782702     1   0.000      0.953 1.000 0.000 0.000
#> GSM782703     3   0.000      1.000 0.000 0.000 1.000
#> GSM782704     3   0.000      1.000 0.000 0.000 1.000
#> GSM782705     1   0.000      0.953 1.000 0.000 0.000
#> GSM782706     1   0.000      0.953 1.000 0.000 0.000
#> GSM782707     1   0.000      0.953 1.000 0.000 0.000
#> GSM782708     3   0.000      1.000 0.000 0.000 1.000
#> GSM782709     1   0.000      0.953 1.000 0.000 0.000
#> GSM782710     1   0.000      0.953 1.000 0.000 0.000
#> GSM782711     1   0.000      0.953 1.000 0.000 0.000
#> GSM782712     1   0.000      0.953 1.000 0.000 0.000
#> GSM782713     3   0.000      1.000 0.000 0.000 1.000
#> GSM782714     2   0.000      1.000 0.000 1.000 0.000
#> GSM782715     1   0.000      0.953 1.000 0.000 0.000
#> GSM782716     3   0.000      1.000 0.000 0.000 1.000
#> GSM782717     1   0.000      0.953 1.000 0.000 0.000
#> GSM782718     1   0.000      0.953 1.000 0.000 0.000
#> GSM782719     1   0.000      0.953 1.000 0.000 0.000
#> GSM782720     3   0.000      1.000 0.000 0.000 1.000
#> GSM782721     1   0.000      0.953 1.000 0.000 0.000
#> GSM782722     1   0.832      0.478 0.600 0.116 0.284
#> GSM782723     2   0.000      1.000 0.000 1.000 0.000
#> GSM782724     2   0.000      1.000 0.000 1.000 0.000
#> GSM782725     1   0.832      0.478 0.600 0.116 0.284
#> GSM782726     1   0.000      0.953 1.000 0.000 0.000
#> GSM782727     3   0.000      1.000 0.000 0.000 1.000
#> GSM782728     2   0.000      1.000 0.000 1.000 0.000
#> GSM782729     1   0.832      0.478 0.600 0.116 0.284
#> GSM782730     3   0.000      1.000 0.000 0.000 1.000
#> GSM782731     1   0.000      0.953 1.000 0.000 0.000
#> GSM782732     1   0.000      0.953 1.000 0.000 0.000
#> GSM782733     3   0.000      1.000 0.000 0.000 1.000
#> GSM782734     1   0.000      0.953 1.000 0.000 0.000
#> GSM782735     2   0.000      1.000 0.000 1.000 0.000
#> GSM782736     1   0.545      0.782 0.816 0.116 0.068
#> GSM782737     2   0.000      1.000 0.000 1.000 0.000
#> GSM782738     1   0.000      0.953 1.000 0.000 0.000
#> GSM782739     1   0.000      0.953 1.000 0.000 0.000
#> GSM782740     2   0.000      1.000 0.000 1.000 0.000
#> GSM782741     1   0.000      0.953 1.000 0.000 0.000
#> GSM782742     3   0.000      1.000 0.000 0.000 1.000
#> GSM782743     3   0.000      1.000 0.000 0.000 1.000
#> GSM782744     3   0.000      1.000 0.000 0.000 1.000
#> GSM782745     1   0.000      0.953 1.000 0.000 0.000
#> GSM782746     2   0.000      1.000 0.000 1.000 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782697     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782698     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782699     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782701     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782702     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782705     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782706     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782707     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782709     1  0.0336      0.989 0.992  0  0 0.008
#> GSM782710     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782711     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782712     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782715     1  0.1557      0.932 0.944  0  0 0.056
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782717     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782718     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782719     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782721     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782722     4  0.0188      0.760 0.004  0  0 0.996
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782725     4  0.0188      0.760 0.004  0  0 0.996
#> GSM782726     1  0.0188      0.993 0.996  0  0 0.004
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782729     4  0.0188      0.760 0.004  0  0 0.996
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782731     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782732     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782734     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782736     4  0.4981      0.131 0.464  0  0 0.536
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782738     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782739     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782741     1  0.0000      0.997 1.000  0  0 0.000
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782745     1  0.0188      0.993 0.996  0  0 0.004
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.0290     0.9174 0.992  0 0.000 0.008 0.000
#> GSM782697     1  0.0000     0.9169 1.000  0 0.000 0.000 0.000
#> GSM782698     1  0.1732     0.8709 0.920  0 0.000 0.080 0.000
#> GSM782699     1  0.0000     0.9169 1.000  0 0.000 0.000 0.000
#> GSM782700     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.1043     0.9131 0.960  0 0.000 0.040 0.000
#> GSM782702     1  0.0000     0.9169 1.000  0 0.000 0.000 0.000
#> GSM782703     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782704     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782705     1  0.0963     0.9064 0.964  0 0.000 0.036 0.000
#> GSM782706     1  0.2516     0.8275 0.860  0 0.000 0.140 0.000
#> GSM782707     1  0.0794     0.9123 0.972  0 0.000 0.028 0.000
#> GSM782708     3  0.0290     0.9934 0.000  0 0.992 0.000 0.008
#> GSM782709     1  0.0880     0.9125 0.968  0 0.000 0.032 0.000
#> GSM782710     1  0.0000     0.9169 1.000  0 0.000 0.000 0.000
#> GSM782711     1  0.0000     0.9169 1.000  0 0.000 0.000 0.000
#> GSM782712     1  0.0000     0.9169 1.000  0 0.000 0.000 0.000
#> GSM782713     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782715     4  0.3689     0.6450 0.256  0 0.000 0.740 0.004
#> GSM782716     3  0.0162     0.9949 0.000  0 0.996 0.000 0.004
#> GSM782717     1  0.0794     0.9141 0.972  0 0.000 0.028 0.000
#> GSM782718     4  0.4273     0.5081 0.448  0 0.000 0.552 0.000
#> GSM782719     1  0.0963     0.9132 0.964  0 0.000 0.036 0.000
#> GSM782720     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782721     1  0.2179     0.8600 0.888  0 0.000 0.112 0.000
#> GSM782722     5  0.0671     0.9706 0.004  0 0.000 0.016 0.980
#> GSM782723     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782725     5  0.0798     0.9724 0.008  0 0.000 0.016 0.976
#> GSM782726     1  0.1952     0.8724 0.912  0 0.000 0.084 0.004
#> GSM782727     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782729     5  0.1942     0.9493 0.012  0 0.000 0.068 0.920
#> GSM782730     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782731     1  0.4304    -0.3853 0.516  0 0.000 0.484 0.000
#> GSM782732     1  0.2929     0.7535 0.820  0 0.000 0.180 0.000
#> GSM782733     3  0.0162     0.9949 0.000  0 0.996 0.000 0.004
#> GSM782734     1  0.1197     0.9042 0.952  0 0.000 0.048 0.000
#> GSM782735     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.2624     0.0356 0.012  0 0.000 0.872 0.116
#> GSM782737     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782738     4  0.4060     0.6506 0.360  0 0.000 0.640 0.000
#> GSM782739     1  0.0162     0.9175 0.996  0 0.000 0.004 0.000
#> GSM782740     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.0162     0.9176 0.996  0 0.000 0.004 0.000
#> GSM782742     3  0.0000     0.9961 0.000  0 1.000 0.000 0.000
#> GSM782743     3  0.0609     0.9859 0.000  0 0.980 0.000 0.020
#> GSM782744     3  0.0510     0.9873 0.000  0 0.984 0.000 0.016
#> GSM782745     1  0.1952     0.8724 0.912  0 0.000 0.084 0.004
#> GSM782746     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1  0.1387      0.858 0.932  0 0.000 0.000 0.000 0.068
#> GSM782697     1  0.0000      0.865 1.000  0 0.000 0.000 0.000 0.000
#> GSM782698     1  0.2793      0.784 0.800  0 0.000 0.000 0.000 0.200
#> GSM782699     1  0.0146      0.864 0.996  0 0.000 0.000 0.000 0.004
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     1  0.2784      0.847 0.848  0 0.000 0.000 0.028 0.124
#> GSM782702     1  0.0000      0.865 1.000  0 0.000 0.000 0.000 0.000
#> GSM782703     3  0.0000      0.904 0.000  0 1.000 0.000 0.000 0.000
#> GSM782704     3  0.1327      0.851 0.000  0 0.936 0.000 0.064 0.000
#> GSM782705     1  0.2378      0.814 0.848  0 0.000 0.000 0.000 0.152
#> GSM782706     1  0.4355      0.452 0.556  0 0.000 0.000 0.024 0.420
#> GSM782707     1  0.1957      0.846 0.888  0 0.000 0.000 0.000 0.112
#> GSM782708     3  0.1387      0.846 0.000  0 0.932 0.000 0.068 0.000
#> GSM782709     1  0.2328      0.852 0.892  0 0.000 0.000 0.052 0.056
#> GSM782710     1  0.0260      0.866 0.992  0 0.000 0.000 0.008 0.000
#> GSM782711     1  0.0146      0.866 0.996  0 0.000 0.000 0.000 0.004
#> GSM782712     1  0.0000      0.865 1.000  0 0.000 0.000 0.000 0.000
#> GSM782713     3  0.0000      0.904 0.000  0 1.000 0.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     6  0.3033      0.782 0.076  0 0.000 0.012 0.056 0.856
#> GSM782716     3  0.0363      0.900 0.000  0 0.988 0.000 0.012 0.000
#> GSM782717     1  0.1765      0.860 0.924  0 0.000 0.000 0.024 0.052
#> GSM782718     6  0.1610      0.807 0.084  0 0.000 0.000 0.000 0.916
#> GSM782719     1  0.1910      0.852 0.892  0 0.000 0.000 0.000 0.108
#> GSM782720     3  0.0000      0.904 0.000  0 1.000 0.000 0.000 0.000
#> GSM782721     1  0.3993      0.677 0.676  0 0.000 0.000 0.024 0.300
#> GSM782722     4  0.0508      0.947 0.000  0 0.000 0.984 0.004 0.012
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     4  0.0405      0.949 0.004  0 0.000 0.988 0.000 0.008
#> GSM782726     1  0.3518      0.818 0.816  0 0.000 0.012 0.116 0.056
#> GSM782727     3  0.0000      0.904 0.000  0 1.000 0.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     4  0.2437      0.905 0.004  0 0.000 0.888 0.072 0.036
#> GSM782730     3  0.0000      0.904 0.000  0 1.000 0.000 0.000 0.000
#> GSM782731     6  0.2854      0.683 0.208  0 0.000 0.000 0.000 0.792
#> GSM782732     1  0.4246      0.491 0.580  0 0.000 0.000 0.020 0.400
#> GSM782733     3  0.0363      0.900 0.000  0 0.988 0.000 0.012 0.000
#> GSM782734     1  0.2660      0.842 0.868  0 0.000 0.000 0.048 0.084
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     6  0.4669      0.383 0.004  0 0.000 0.108 0.196 0.692
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     6  0.1610      0.807 0.084  0 0.000 0.000 0.000 0.916
#> GSM782739     1  0.1152      0.868 0.952  0 0.000 0.000 0.004 0.044
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     1  0.0937      0.867 0.960  0 0.000 0.000 0.000 0.040
#> GSM782742     3  0.0000      0.904 0.000  0 1.000 0.000 0.000 0.000
#> GSM782743     3  0.3866     -0.556 0.000  0 0.516 0.000 0.484 0.000
#> GSM782744     5  0.3499      0.000 0.000  0 0.320 0.000 0.680 0.000
#> GSM782745     1  0.3849      0.801 0.792  0 0.000 0.012 0.116 0.080
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-mclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-SD-mclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-SD-mclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-SD-mclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-SD-mclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-mclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-SD-mclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-SD-mclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-SD-mclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-SD-mclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-mclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-SD-mclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-SD-mclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-SD-mclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-SD-mclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-mclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-SD-mclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-SD-mclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-SD-mclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-SD-mclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-mclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-SD-mclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-SD-mclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-SD-mclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-SD-mclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>            n agent(p) k
#> SD:mclust 51    0.493 2
#> SD:mclust 48    0.627 3
#> SD:mclust 50    0.497 4
#> SD:mclust 49    0.396 5
#> SD:mclust 46    0.394 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


SD:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["SD", "NMF"]
# you can also extract it by
# res = res_list["SD:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'SD' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk SD-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk SD-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.895           0.924       0.946         0.1444 0.902   0.767
#> 5 5 0.822           0.876       0.929         0.0596 0.977   0.930
#> 6 6 0.757           0.799       0.873         0.0577 0.977   0.927

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.1211      0.920 0.960  0 0.000 0.040
#> GSM782697     1  0.1302      0.911 0.956  0 0.000 0.044
#> GSM782698     1  0.0921      0.930 0.972  0 0.000 0.028
#> GSM782699     1  0.1211      0.914 0.960  0 0.000 0.040
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.0188      0.931 0.996  0 0.000 0.004
#> GSM782702     1  0.0707      0.928 0.980  0 0.000 0.020
#> GSM782703     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782705     1  0.0592      0.927 0.984  0 0.000 0.016
#> GSM782706     1  0.0592      0.927 0.984  0 0.000 0.016
#> GSM782707     1  0.0336      0.932 0.992  0 0.000 0.008
#> GSM782708     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782709     1  0.1022      0.922 0.968  0 0.000 0.032
#> GSM782710     1  0.0592      0.931 0.984  0 0.000 0.016
#> GSM782711     1  0.0707      0.931 0.980  0 0.000 0.020
#> GSM782712     1  0.0592      0.930 0.984  0 0.000 0.016
#> GSM782713     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     4  0.4907      0.755 0.420  0 0.000 0.580
#> GSM782716     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782717     1  0.0188      0.931 0.996  0 0.000 0.004
#> GSM782718     1  0.3942      0.525 0.764  0 0.000 0.236
#> GSM782719     1  0.1302      0.918 0.956  0 0.000 0.044
#> GSM782720     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782721     1  0.0469      0.931 0.988  0 0.000 0.012
#> GSM782722     4  0.4040      0.873 0.248  0 0.000 0.752
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     4  0.4250      0.899 0.276  0 0.000 0.724
#> GSM782726     1  0.0336      0.932 0.992  0 0.000 0.008
#> GSM782727     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     4  0.4356      0.902 0.292  0 0.000 0.708
#> GSM782730     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782731     1  0.3123      0.720 0.844  0 0.000 0.156
#> GSM782732     1  0.1792      0.870 0.932  0 0.000 0.068
#> GSM782733     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782734     1  0.0336      0.931 0.992  0 0.000 0.008
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     4  0.4679      0.867 0.352  0 0.000 0.648
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.4431      0.280 0.696  0 0.000 0.304
#> GSM782739     1  0.0000      0.932 1.000  0 0.000 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.0000      0.932 1.000  0 0.000 0.000
#> GSM782742     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782743     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782744     3  0.0817      0.977 0.000  0 0.976 0.024
#> GSM782745     1  0.0707      0.926 0.980  0 0.000 0.020
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2   p3    p4    p5
#> GSM782696     1  0.1544      0.895 0.932  0 0.00 0.000 0.068
#> GSM782697     1  0.2179      0.864 0.888  0 0.00 0.000 0.112
#> GSM782698     1  0.2674      0.847 0.856  0 0.00 0.004 0.140
#> GSM782699     1  0.1732      0.880 0.920  0 0.00 0.000 0.080
#> GSM782700     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782701     1  0.0880      0.903 0.968  0 0.00 0.000 0.032
#> GSM782702     1  0.0798      0.903 0.976  0 0.00 0.008 0.016
#> GSM782703     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782704     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782705     1  0.1914      0.891 0.924  0 0.00 0.016 0.060
#> GSM782706     1  0.2669      0.859 0.876  0 0.00 0.020 0.104
#> GSM782707     1  0.1205      0.902 0.956  0 0.00 0.004 0.040
#> GSM782708     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782709     1  0.1082      0.904 0.964  0 0.00 0.008 0.028
#> GSM782710     1  0.1195      0.903 0.960  0 0.00 0.012 0.028
#> GSM782711     1  0.0880      0.902 0.968  0 0.00 0.000 0.032
#> GSM782712     1  0.0963      0.902 0.964  0 0.00 0.000 0.036
#> GSM782713     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782715     4  0.4927      0.663 0.296  0 0.00 0.652 0.052
#> GSM782716     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782717     1  0.0693      0.902 0.980  0 0.00 0.008 0.012
#> GSM782718     1  0.5042     -0.276 0.508  0 0.00 0.460 0.032
#> GSM782719     1  0.1965      0.880 0.904  0 0.00 0.000 0.096
#> GSM782720     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782721     1  0.2915      0.846 0.860  0 0.00 0.024 0.116
#> GSM782722     4  0.1484      0.744 0.048  0 0.00 0.944 0.008
#> GSM782723     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782725     4  0.2110      0.772 0.072  0 0.00 0.912 0.016
#> GSM782726     1  0.1741      0.891 0.936  0 0.00 0.024 0.040
#> GSM782727     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782729     4  0.2361      0.784 0.096  0 0.00 0.892 0.012
#> GSM782730     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782731     1  0.3779      0.745 0.804  0 0.00 0.144 0.052
#> GSM782732     1  0.2409      0.862 0.900  0 0.00 0.068 0.032
#> GSM782733     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782734     1  0.1310      0.896 0.956  0 0.00 0.020 0.024
#> GSM782735     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782736     4  0.3639      0.780 0.184  0 0.00 0.792 0.024
#> GSM782737     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782738     4  0.5049      0.207 0.484  0 0.00 0.484 0.032
#> GSM782739     1  0.0807      0.900 0.976  0 0.00 0.012 0.012
#> GSM782740     2  0.0000      1.000 0.000  1 0.00 0.000 0.000
#> GSM782741     1  0.0693      0.902 0.980  0 0.00 0.008 0.012
#> GSM782742     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782743     3  0.0000      0.989 0.000  0 1.00 0.000 0.000
#> GSM782744     3  0.3037      0.869 0.000  0 0.86 0.040 0.100
#> GSM782745     1  0.2769      0.851 0.876  0 0.00 0.032 0.092
#> GSM782746     2  0.0000      1.000 0.000  1 0.00 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4 p5    p6
#> GSM782696     1  0.2554      0.797 0.876 0.000 0.000 0.000 NA 0.076
#> GSM782697     1  0.2738      0.751 0.820 0.000 0.000 0.000 NA 0.004
#> GSM782698     1  0.4719      0.613 0.680 0.000 0.000 0.044 NA 0.028
#> GSM782699     1  0.2513      0.774 0.852 0.000 0.000 0.000 NA 0.008
#> GSM782700     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782701     1  0.2883      0.771 0.844 0.000 0.000 0.012 NA 0.132
#> GSM782702     1  0.0717      0.810 0.976 0.000 0.000 0.000 NA 0.016
#> GSM782703     3  0.0291      0.972 0.000 0.000 0.992 0.000 NA 0.004
#> GSM782704     3  0.0000      0.973 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782705     1  0.4053      0.695 0.744 0.000 0.000 0.048 NA 0.008
#> GSM782706     1  0.5218      0.319 0.528 0.000 0.000 0.084 NA 0.384
#> GSM782707     1  0.2983      0.784 0.856 0.000 0.000 0.012 NA 0.092
#> GSM782708     3  0.0000      0.973 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782709     1  0.2009      0.806 0.908 0.000 0.000 0.000 NA 0.068
#> GSM782710     1  0.1866      0.803 0.908 0.000 0.000 0.000 NA 0.008
#> GSM782711     1  0.1168      0.809 0.956 0.000 0.000 0.000 NA 0.016
#> GSM782712     1  0.2537      0.790 0.880 0.000 0.000 0.008 NA 0.088
#> GSM782713     3  0.0291      0.972 0.000 0.000 0.992 0.000 NA 0.004
#> GSM782714     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782715     4  0.5960      0.527 0.284 0.000 0.000 0.544 NA 0.144
#> GSM782716     3  0.0000      0.973 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782717     1  0.1410      0.806 0.944 0.000 0.000 0.004 NA 0.008
#> GSM782718     4  0.6043      0.216 0.428 0.000 0.000 0.440 NA 0.072
#> GSM782719     1  0.4531      0.669 0.716 0.000 0.000 0.004 NA 0.140
#> GSM782720     3  0.0291      0.972 0.000 0.000 0.992 0.000 NA 0.004
#> GSM782721     1  0.4952      0.329 0.524 0.000 0.000 0.068 NA 0.408
#> GSM782722     4  0.1462      0.669 0.008 0.000 0.000 0.936 NA 0.056
#> GSM782723     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782724     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782725     4  0.0976      0.668 0.008 0.000 0.000 0.968 NA 0.008
#> GSM782726     1  0.2916      0.790 0.860 0.000 0.000 0.024 NA 0.096
#> GSM782727     3  0.0508      0.970 0.000 0.000 0.984 0.000 NA 0.012
#> GSM782728     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782729     4  0.2360      0.677 0.044 0.000 0.000 0.900 NA 0.012
#> GSM782730     3  0.0146      0.973 0.000 0.000 0.996 0.000 NA 0.004
#> GSM782731     1  0.4870      0.646 0.720 0.000 0.000 0.144 NA 0.092
#> GSM782732     1  0.4290      0.725 0.776 0.000 0.000 0.100 NA 0.048
#> GSM782733     3  0.0000      0.973 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782734     1  0.2784      0.788 0.848 0.000 0.000 0.028 NA 0.124
#> GSM782735     2  0.0146      0.997 0.000 0.996 0.000 0.000 NA 0.004
#> GSM782736     4  0.4019      0.688 0.112 0.000 0.000 0.792 NA 0.056
#> GSM782737     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782738     4  0.5924      0.247 0.412 0.000 0.000 0.420 NA 0.160
#> GSM782739     1  0.2039      0.804 0.916 0.000 0.000 0.012 NA 0.020
#> GSM782740     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782741     1  0.1477      0.807 0.940 0.000 0.000 0.008 NA 0.048
#> GSM782742     3  0.0603      0.968 0.000 0.000 0.980 0.000 NA 0.016
#> GSM782743     3  0.0000      0.973 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782744     3  0.4641      0.704 0.000 0.000 0.712 0.048 NA 0.204
#> GSM782745     1  0.3194      0.771 0.828 0.000 0.000 0.032 NA 0.132
#> GSM782746     2  0.0146      0.997 0.000 0.996 0.000 0.000 NA 0.004

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-SD-NMF-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-SD-NMF-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-SD-NMF-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-SD-NMF-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-SD-NMF-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-SD-NMF-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-SD-NMF-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-SD-NMF-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-SD-NMF-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-SD-NMF-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-SD-NMF-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-SD-NMF-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-SD-NMF-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-SD-NMF-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-SD-NMF-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-SD-NMF-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-SD-NMF-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-SD-NMF-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-SD-NMF-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-SD-NMF-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk SD-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-SD-NMF-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-SD-NMF-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-SD-NMF-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-SD-NMF-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-SD-NMF-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk SD-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>         n agent(p) k
#> SD:NMF 51    0.648 2
#> SD:NMF 51    0.642 3
#> SD:NMF 50    0.502 4
#> SD:NMF 49    0.497 5
#> SD:NMF 47    0.487 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:hclust**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "hclust"]
# you can also extract it by
# res = res_list["CV:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.845           0.874       0.932         0.1416 0.936   0.849
#> 5 5 0.812           0.839       0.924         0.0623 0.961   0.890
#> 6 6 0.811           0.844       0.919         0.0375 0.991   0.973

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782697     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782698     1  0.3649      0.580 0.796  0  0 0.204
#> GSM782699     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782701     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782702     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782705     1  0.0707      0.838 0.980  0  0 0.020
#> GSM782706     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782707     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782709     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782710     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782711     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782712     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782715     1  0.3649      0.580 0.796  0  0 0.204
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782717     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782718     1  0.3649      0.580 0.796  0  0 0.204
#> GSM782719     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782721     1  0.0000      0.852 1.000  0  0 0.000
#> GSM782722     4  0.4643      1.000 0.344  0  0 0.656
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782725     4  0.4643      1.000 0.344  0  0 0.656
#> GSM782726     1  0.4643      0.450 0.656  0  0 0.344
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782729     4  0.4643      1.000 0.344  0  0 0.656
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782731     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782732     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782734     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782736     1  0.3649      0.580 0.796  0  0 0.204
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782738     1  0.3649      0.580 0.796  0  0 0.204
#> GSM782739     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782741     1  0.2281      0.813 0.904  0  0 0.096
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782745     1  0.4643      0.450 0.656  0  0 0.344
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782697     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782698     1  0.3266      0.617 0.796  0 0.000 0.200 0.004
#> GSM782699     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782702     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782703     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782704     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782705     1  0.0609      0.803 0.980  0 0.000 0.020 0.000
#> GSM782706     1  0.0703      0.806 0.976  0 0.000 0.000 0.024
#> GSM782707     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782708     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782709     1  0.0510      0.809 0.984  0 0.000 0.000 0.016
#> GSM782710     1  0.3932      0.138 0.672  0 0.000 0.000 0.328
#> GSM782711     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782712     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782713     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     1  0.3521      0.572 0.764  0 0.000 0.232 0.004
#> GSM782716     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782717     1  0.2813      0.661 0.832  0 0.000 0.000 0.168
#> GSM782718     1  0.3333      0.608 0.788  0 0.000 0.208 0.004
#> GSM782719     1  0.0000      0.815 1.000  0 0.000 0.000 0.000
#> GSM782720     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782721     1  0.0703      0.806 0.976  0 0.000 0.000 0.024
#> GSM782722     4  0.1197      1.000 0.048  0 0.000 0.952 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.1197      1.000 0.048  0 0.000 0.952 0.000
#> GSM782726     5  0.4088      1.000 0.368  0 0.000 0.000 0.632
#> GSM782727     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.1197      1.000 0.048  0 0.000 0.952 0.000
#> GSM782730     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782731     1  0.2813      0.661 0.832  0 0.000 0.000 0.168
#> GSM782732     1  0.2813      0.661 0.832  0 0.000 0.000 0.168
#> GSM782733     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782734     1  0.2813      0.661 0.832  0 0.000 0.000 0.168
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     1  0.3333      0.608 0.788  0 0.000 0.208 0.004
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     1  0.3333      0.608 0.788  0 0.000 0.208 0.004
#> GSM782739     1  0.2813      0.661 0.832  0 0.000 0.000 0.168
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.2813      0.661 0.832  0 0.000 0.000 0.168
#> GSM782742     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782743     3  0.0000      0.966 0.000  0 1.000 0.000 0.000
#> GSM782744     3  0.5131      0.501 0.000  0 0.588 0.048 0.364
#> GSM782745     5  0.4088      1.000 0.368  0 0.000 0.000 0.632
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2 p3    p4 p5    p6
#> GSM782696     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782697     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782698     1  0.3422     0.6811 0.792  0  0 0.040  0 0.168
#> GSM782699     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782700     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782701     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782702     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782703     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782704     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782705     1  0.0547     0.8140 0.980  0  0 0.000  0 0.020
#> GSM782706     1  0.1863     0.7844 0.896  0  0 0.000  0 0.104
#> GSM782707     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782708     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782709     1  0.1714     0.7922 0.908  0  0 0.000  0 0.092
#> GSM782710     1  0.3847     0.0436 0.544  0  0 0.000  0 0.456
#> GSM782711     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782712     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782713     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782715     1  0.4046     0.6332 0.748  0  0 0.084  0 0.168
#> GSM782716     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782717     1  0.2969     0.6834 0.776  0  0 0.000  0 0.224
#> GSM782718     1  0.3612     0.6745 0.780  0  0 0.052  0 0.168
#> GSM782719     1  0.0000     0.8217 1.000  0  0 0.000  0 0.000
#> GSM782720     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782721     1  0.1863     0.7844 0.896  0  0 0.000  0 0.104
#> GSM782722     4  0.0000     1.0000 0.000  0  0 1.000  0 0.000
#> GSM782723     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782725     4  0.0000     1.0000 0.000  0  0 1.000  0 0.000
#> GSM782726     6  0.2527     1.0000 0.168  0  0 0.000  0 0.832
#> GSM782727     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782729     4  0.0000     1.0000 0.000  0  0 1.000  0 0.000
#> GSM782730     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782731     1  0.2969     0.6834 0.776  0  0 0.000  0 0.224
#> GSM782732     1  0.2969     0.6834 0.776  0  0 0.000  0 0.224
#> GSM782733     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782734     1  0.2969     0.6834 0.776  0  0 0.000  0 0.224
#> GSM782735     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782736     1  0.3612     0.6694 0.780  0  0 0.052  0 0.168
#> GSM782737     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782738     1  0.3612     0.6745 0.780  0  0 0.052  0 0.168
#> GSM782739     1  0.2969     0.6834 0.776  0  0 0.000  0 0.224
#> GSM782740     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782741     1  0.2969     0.6834 0.776  0  0 0.000  0 0.224
#> GSM782742     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782743     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782744     5  0.0000     0.0000 0.000  0  0 0.000  1 0.000
#> GSM782745     6  0.2527     1.0000 0.168  0  0 0.000  0 0.832
#> GSM782746     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-hclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-CV-hclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-CV-hclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-CV-hclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-CV-hclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-hclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-CV-hclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-CV-hclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-CV-hclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-CV-hclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-hclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-CV-hclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-CV-hclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-CV-hclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-CV-hclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-hclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-CV-hclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-CV-hclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-CV-hclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-CV-hclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-hclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-CV-hclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-CV-hclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-CV-hclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-CV-hclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>            n agent(p) k
#> CV:hclust 51    0.648 2
#> CV:hclust 51    0.642 3
#> CV:hclust 49    0.494 4
#> CV:hclust 50    0.711 5
#> CV:hclust 49    0.631 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:kmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "kmeans"]
# you can also extract it by
# res = res_list["CV:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.506           0.815       0.854         0.3229 0.704   0.704
#> 3 3 1.000           0.991       0.964         0.7049 0.718   0.599
#> 4 4 0.727           0.868       0.874         0.1875 1.000   1.000
#> 5 5 0.695           0.561       0.697         0.1158 0.817   0.566
#> 6 6 0.713           0.781       0.801         0.0781 0.869   0.536

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.000      0.839 1.000 0.000
#> GSM782697     1   0.000      0.839 1.000 0.000
#> GSM782698     1   0.000      0.839 1.000 0.000
#> GSM782699     1   0.000      0.839 1.000 0.000
#> GSM782700     2   0.936      1.000 0.352 0.648
#> GSM782701     1   0.000      0.839 1.000 0.000
#> GSM782702     1   0.000      0.839 1.000 0.000
#> GSM782703     1   0.939      0.617 0.644 0.356
#> GSM782704     1   0.939      0.617 0.644 0.356
#> GSM782705     1   0.000      0.839 1.000 0.000
#> GSM782706     1   0.000      0.839 1.000 0.000
#> GSM782707     1   0.000      0.839 1.000 0.000
#> GSM782708     1   0.939      0.617 0.644 0.356
#> GSM782709     1   0.000      0.839 1.000 0.000
#> GSM782710     1   0.000      0.839 1.000 0.000
#> GSM782711     1   0.000      0.839 1.000 0.000
#> GSM782712     1   0.000      0.839 1.000 0.000
#> GSM782713     1   0.939      0.617 0.644 0.356
#> GSM782714     2   0.936      1.000 0.352 0.648
#> GSM782715     1   0.000      0.839 1.000 0.000
#> GSM782716     1   0.939      0.617 0.644 0.356
#> GSM782717     1   0.000      0.839 1.000 0.000
#> GSM782718     1   0.000      0.839 1.000 0.000
#> GSM782719     1   0.000      0.839 1.000 0.000
#> GSM782720     1   0.939      0.617 0.644 0.356
#> GSM782721     1   0.000      0.839 1.000 0.000
#> GSM782722     1   0.000      0.839 1.000 0.000
#> GSM782723     2   0.936      1.000 0.352 0.648
#> GSM782724     2   0.936      1.000 0.352 0.648
#> GSM782725     1   0.000      0.839 1.000 0.000
#> GSM782726     1   0.000      0.839 1.000 0.000
#> GSM782727     1   0.939      0.617 0.644 0.356
#> GSM782728     2   0.936      1.000 0.352 0.648
#> GSM782729     1   0.000      0.839 1.000 0.000
#> GSM782730     1   0.939      0.617 0.644 0.356
#> GSM782731     1   0.000      0.839 1.000 0.000
#> GSM782732     1   0.000      0.839 1.000 0.000
#> GSM782733     1   0.939      0.617 0.644 0.356
#> GSM782734     1   0.000      0.839 1.000 0.000
#> GSM782735     2   0.936      1.000 0.352 0.648
#> GSM782736     1   0.000      0.839 1.000 0.000
#> GSM782737     2   0.936      1.000 0.352 0.648
#> GSM782738     1   0.000      0.839 1.000 0.000
#> GSM782739     1   0.000      0.839 1.000 0.000
#> GSM782740     2   0.936      1.000 0.352 0.648
#> GSM782741     1   0.000      0.839 1.000 0.000
#> GSM782742     1   0.939      0.617 0.644 0.356
#> GSM782743     1   0.939      0.617 0.644 0.356
#> GSM782744     1   0.939      0.617 0.644 0.356
#> GSM782745     1   0.000      0.839 1.000 0.000
#> GSM782746     2   0.936      1.000 0.352 0.648

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1   0.000      1.000 1.000 0.000 0.000
#> GSM782697     1   0.000      1.000 1.000 0.000 0.000
#> GSM782698     1   0.000      1.000 1.000 0.000 0.000
#> GSM782699     1   0.000      1.000 1.000 0.000 0.000
#> GSM782700     2   0.216      0.991 0.064 0.936 0.000
#> GSM782701     1   0.000      1.000 1.000 0.000 0.000
#> GSM782702     1   0.000      1.000 1.000 0.000 0.000
#> GSM782703     3   0.378      0.974 0.064 0.044 0.892
#> GSM782704     3   0.429      0.972 0.064 0.064 0.872
#> GSM782705     1   0.000      1.000 1.000 0.000 0.000
#> GSM782706     1   0.000      1.000 1.000 0.000 0.000
#> GSM782707     1   0.000      1.000 1.000 0.000 0.000
#> GSM782708     3   0.429      0.972 0.064 0.064 0.872
#> GSM782709     1   0.000      1.000 1.000 0.000 0.000
#> GSM782710     1   0.000      1.000 1.000 0.000 0.000
#> GSM782711     1   0.000      1.000 1.000 0.000 0.000
#> GSM782712     1   0.000      1.000 1.000 0.000 0.000
#> GSM782713     3   0.216      0.975 0.064 0.000 0.936
#> GSM782714     2   0.216      0.991 0.064 0.936 0.000
#> GSM782715     1   0.000      1.000 1.000 0.000 0.000
#> GSM782716     3   0.429      0.972 0.064 0.064 0.872
#> GSM782717     1   0.000      1.000 1.000 0.000 0.000
#> GSM782718     1   0.000      1.000 1.000 0.000 0.000
#> GSM782719     1   0.000      1.000 1.000 0.000 0.000
#> GSM782720     3   0.216      0.975 0.064 0.000 0.936
#> GSM782721     1   0.000      1.000 1.000 0.000 0.000
#> GSM782722     1   0.000      1.000 1.000 0.000 0.000
#> GSM782723     2   0.216      0.991 0.064 0.936 0.000
#> GSM782724     2   0.305      0.983 0.064 0.916 0.020
#> GSM782725     1   0.000      1.000 1.000 0.000 0.000
#> GSM782726     1   0.000      1.000 1.000 0.000 0.000
#> GSM782727     3   0.216      0.975 0.064 0.000 0.936
#> GSM782728     2   0.216      0.991 0.064 0.936 0.000
#> GSM782729     1   0.000      1.000 1.000 0.000 0.000
#> GSM782730     3   0.216      0.975 0.064 0.000 0.936
#> GSM782731     1   0.000      1.000 1.000 0.000 0.000
#> GSM782732     1   0.000      1.000 1.000 0.000 0.000
#> GSM782733     3   0.429      0.972 0.064 0.064 0.872
#> GSM782734     1   0.000      1.000 1.000 0.000 0.000
#> GSM782735     2   0.378      0.974 0.064 0.892 0.044
#> GSM782736     1   0.000      1.000 1.000 0.000 0.000
#> GSM782737     2   0.216      0.991 0.064 0.936 0.000
#> GSM782738     1   0.000      1.000 1.000 0.000 0.000
#> GSM782739     1   0.000      1.000 1.000 0.000 0.000
#> GSM782740     2   0.216      0.991 0.064 0.936 0.000
#> GSM782741     1   0.000      1.000 1.000 0.000 0.000
#> GSM782742     3   0.216      0.975 0.064 0.000 0.936
#> GSM782743     3   0.429      0.972 0.064 0.064 0.872
#> GSM782744     3   0.216      0.975 0.064 0.000 0.936
#> GSM782745     1   0.000      1.000 1.000 0.000 0.000
#> GSM782746     2   0.378      0.974 0.064 0.892 0.044

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1    p2    p3 p4
#> GSM782696     1  0.3311      0.861 0.828 0.000 0.000 NA
#> GSM782697     1  0.1716      0.864 0.936 0.000 0.000 NA
#> GSM782698     1  0.3907      0.842 0.768 0.000 0.000 NA
#> GSM782699     1  0.2011      0.866 0.920 0.000 0.000 NA
#> GSM782700     2  0.0188      0.969 0.000 0.996 0.000 NA
#> GSM782701     1  0.3123      0.863 0.844 0.000 0.000 NA
#> GSM782702     1  0.1716      0.864 0.936 0.000 0.000 NA
#> GSM782703     3  0.3695      0.912 0.016 0.000 0.828 NA
#> GSM782704     3  0.4214      0.908 0.016 0.000 0.780 NA
#> GSM782705     1  0.2589      0.863 0.884 0.000 0.000 NA
#> GSM782706     1  0.3311      0.861 0.828 0.000 0.000 NA
#> GSM782707     1  0.3311      0.861 0.828 0.000 0.000 NA
#> GSM782708     3  0.4214      0.908 0.016 0.000 0.780 NA
#> GSM782709     1  0.1867      0.864 0.928 0.000 0.000 NA
#> GSM782710     1  0.1474      0.860 0.948 0.000 0.000 NA
#> GSM782711     1  0.1792      0.864 0.932 0.000 0.000 NA
#> GSM782712     1  0.1792      0.864 0.932 0.000 0.000 NA
#> GSM782713     3  0.0592      0.913 0.016 0.000 0.984 NA
#> GSM782714     2  0.0336      0.969 0.000 0.992 0.000 NA
#> GSM782715     1  0.3688      0.826 0.792 0.000 0.000 NA
#> GSM782716     3  0.4214      0.908 0.016 0.000 0.780 NA
#> GSM782717     1  0.1557      0.860 0.944 0.000 0.000 NA
#> GSM782718     1  0.3649      0.828 0.796 0.000 0.000 NA
#> GSM782719     1  0.3311      0.861 0.828 0.000 0.000 NA
#> GSM782720     3  0.0592      0.913 0.016 0.000 0.984 NA
#> GSM782721     1  0.3311      0.861 0.828 0.000 0.000 NA
#> GSM782722     1  0.4992      0.588 0.524 0.000 0.000 NA
#> GSM782723     2  0.0336      0.969 0.000 0.992 0.000 NA
#> GSM782724     2  0.2060      0.947 0.000 0.932 0.016 NA
#> GSM782725     1  0.4999      0.583 0.508 0.000 0.000 NA
#> GSM782726     1  0.1557      0.860 0.944 0.000 0.000 NA
#> GSM782727     3  0.0592      0.913 0.016 0.000 0.984 NA
#> GSM782728     2  0.0000      0.969 0.000 1.000 0.000 NA
#> GSM782729     1  0.4999      0.583 0.508 0.000 0.000 NA
#> GSM782730     3  0.0592      0.913 0.016 0.000 0.984 NA
#> GSM782731     1  0.1716      0.859 0.936 0.000 0.000 NA
#> GSM782732     1  0.1716      0.859 0.936 0.000 0.000 NA
#> GSM782733     3  0.4214      0.908 0.016 0.000 0.780 NA
#> GSM782734     1  0.1557      0.860 0.944 0.000 0.000 NA
#> GSM782735     2  0.2814      0.917 0.000 0.868 0.000 NA
#> GSM782736     1  0.4643      0.728 0.656 0.000 0.000 NA
#> GSM782737     2  0.0336      0.969 0.000 0.992 0.000 NA
#> GSM782738     1  0.3688      0.827 0.792 0.000 0.000 NA
#> GSM782739     1  0.1557      0.860 0.944 0.000 0.000 NA
#> GSM782740     2  0.0000      0.969 0.000 1.000 0.000 NA
#> GSM782741     1  0.1557      0.860 0.944 0.000 0.000 NA
#> GSM782742     3  0.0592      0.913 0.016 0.000 0.984 NA
#> GSM782743     3  0.4214      0.908 0.016 0.000 0.780 NA
#> GSM782744     3  0.1510      0.903 0.016 0.000 0.956 NA
#> GSM782745     1  0.1557      0.860 0.944 0.000 0.000 NA
#> GSM782746     2  0.2814      0.917 0.000 0.868 0.000 NA

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1    p2    p3    p4    p5
#> GSM782696     5  0.4227     0.8950 0.420 0.000 0.000 0.000 0.580
#> GSM782697     1  0.4552    -0.6551 0.524 0.000 0.000 0.008 0.468
#> GSM782698     5  0.4862     0.7959 0.364 0.000 0.000 0.032 0.604
#> GSM782699     5  0.4562     0.7035 0.492 0.000 0.000 0.008 0.500
#> GSM782700     2  0.0451     0.9540 0.000 0.988 0.004 0.000 0.008
#> GSM782701     5  0.4604     0.8933 0.428 0.000 0.000 0.012 0.560
#> GSM782702     1  0.4443    -0.6571 0.524 0.000 0.000 0.004 0.472
#> GSM782703     3  0.2349     0.8677 0.004 0.000 0.900 0.012 0.084
#> GSM782704     3  0.0162     0.8601 0.004 0.000 0.996 0.000 0.000
#> GSM782705     1  0.4882    -0.4789 0.532 0.000 0.000 0.024 0.444
#> GSM782706     5  0.4713     0.8584 0.440 0.000 0.000 0.016 0.544
#> GSM782707     5  0.4367     0.8961 0.416 0.000 0.000 0.004 0.580
#> GSM782708     3  0.0162     0.8601 0.004 0.000 0.996 0.000 0.000
#> GSM782709     1  0.4590    -0.5662 0.568 0.000 0.000 0.012 0.420
#> GSM782710     1  0.1410     0.4616 0.940 0.000 0.000 0.000 0.060
#> GSM782711     1  0.4560    -0.7011 0.508 0.000 0.000 0.008 0.484
#> GSM782712     1  0.4560    -0.7057 0.508 0.000 0.000 0.008 0.484
#> GSM782713     3  0.4910     0.8649 0.004 0.000 0.712 0.080 0.204
#> GSM782714     2  0.0000     0.9571 0.000 1.000 0.000 0.000 0.000
#> GSM782715     1  0.6426    -0.0447 0.468 0.000 0.000 0.184 0.348
#> GSM782716     3  0.0162     0.8601 0.004 0.000 0.996 0.000 0.000
#> GSM782717     1  0.0000     0.5076 1.000 0.000 0.000 0.000 0.000
#> GSM782718     1  0.6402    -0.0638 0.472 0.000 0.000 0.180 0.348
#> GSM782719     5  0.4590     0.8976 0.420 0.000 0.000 0.012 0.568
#> GSM782720     3  0.4910     0.8649 0.004 0.000 0.712 0.080 0.204
#> GSM782721     5  0.4713     0.8584 0.440 0.000 0.000 0.016 0.544
#> GSM782722     4  0.5400     0.9770 0.272 0.000 0.000 0.632 0.096
#> GSM782723     2  0.0000     0.9571 0.000 1.000 0.000 0.000 0.000
#> GSM782724     2  0.2597     0.9029 0.000 0.884 0.000 0.092 0.024
#> GSM782725     4  0.5296     0.9885 0.280 0.000 0.000 0.636 0.084
#> GSM782726     1  0.0000     0.5076 1.000 0.000 0.000 0.000 0.000
#> GSM782727     3  0.4910     0.8649 0.004 0.000 0.712 0.080 0.204
#> GSM782728     2  0.0000     0.9571 0.000 1.000 0.000 0.000 0.000
#> GSM782729     4  0.5296     0.9885 0.280 0.000 0.000 0.636 0.084
#> GSM782730     3  0.4910     0.8649 0.004 0.000 0.712 0.080 0.204
#> GSM782731     1  0.0992     0.4996 0.968 0.000 0.000 0.024 0.008
#> GSM782732     1  0.0865     0.5010 0.972 0.000 0.000 0.024 0.004
#> GSM782733     3  0.0162     0.8601 0.004 0.000 0.996 0.000 0.000
#> GSM782734     1  0.0000     0.5076 1.000 0.000 0.000 0.000 0.000
#> GSM782735     2  0.3390     0.8870 0.000 0.840 0.000 0.060 0.100
#> GSM782736     1  0.6630    -0.4690 0.404 0.000 0.000 0.376 0.220
#> GSM782737     2  0.0000     0.9571 0.000 1.000 0.000 0.000 0.000
#> GSM782738     1  0.6386    -0.0412 0.480 0.000 0.000 0.180 0.340
#> GSM782739     1  0.0162     0.5065 0.996 0.000 0.000 0.004 0.000
#> GSM782740     2  0.0000     0.9571 0.000 1.000 0.000 0.000 0.000
#> GSM782741     1  0.0000     0.5076 1.000 0.000 0.000 0.000 0.000
#> GSM782742     3  0.4910     0.8649 0.004 0.000 0.712 0.080 0.204
#> GSM782743     3  0.0162     0.8601 0.004 0.000 0.996 0.000 0.000
#> GSM782744     3  0.5689     0.8080 0.004 0.000 0.644 0.192 0.160
#> GSM782745     1  0.0000     0.5076 1.000 0.000 0.000 0.000 0.000
#> GSM782746     2  0.3390     0.8870 0.000 0.840 0.000 0.060 0.100

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4    p5    p6
#> GSM782696     1  0.0291      0.754 0.992 0.000 0.000 0.004 0.004 0.000
#> GSM782697     1  0.2647      0.741 0.876 0.000 0.000 0.016 0.020 0.088
#> GSM782698     1  0.1657      0.703 0.928 0.000 0.000 0.016 0.056 0.000
#> GSM782699     1  0.2196      0.760 0.908 0.000 0.000 0.016 0.020 0.056
#> GSM782700     2  0.0653      0.925 0.000 0.980 0.000 0.004 0.004 0.012
#> GSM782701     1  0.1528      0.756 0.944 0.000 0.000 0.028 0.016 0.012
#> GSM782702     1  0.2006      0.744 0.892 0.000 0.000 0.000 0.004 0.104
#> GSM782703     3  0.3270      0.803 0.000 0.000 0.844 0.088 0.040 0.028
#> GSM782704     3  0.0547      0.787 0.000 0.000 0.980 0.000 0.000 0.020
#> GSM782705     1  0.4259      0.325 0.752 0.000 0.000 0.016 0.160 0.072
#> GSM782706     1  0.3880      0.626 0.804 0.000 0.000 0.032 0.088 0.076
#> GSM782707     1  0.0777      0.754 0.972 0.000 0.000 0.024 0.004 0.000
#> GSM782708     3  0.0000      0.788 0.000 0.000 1.000 0.000 0.000 0.000
#> GSM782709     1  0.3168      0.669 0.804 0.000 0.000 0.000 0.024 0.172
#> GSM782710     6  0.3309      0.832 0.280 0.000 0.000 0.000 0.000 0.720
#> GSM782711     1  0.2182      0.758 0.904 0.000 0.000 0.008 0.020 0.068
#> GSM782712     1  0.2422      0.762 0.892 0.000 0.000 0.024 0.012 0.072
#> GSM782713     3  0.5635      0.801 0.000 0.000 0.612 0.192 0.172 0.024
#> GSM782714     2  0.0146      0.930 0.000 0.996 0.000 0.000 0.004 0.000
#> GSM782715     5  0.5681      0.827 0.432 0.000 0.000 0.016 0.452 0.100
#> GSM782716     3  0.0146      0.788 0.000 0.000 0.996 0.000 0.000 0.004
#> GSM782717     6  0.3136      0.945 0.188 0.000 0.000 0.000 0.016 0.796
#> GSM782718     1  0.5075     -0.843 0.464 0.000 0.000 0.000 0.460 0.076
#> GSM782719     1  0.1168      0.753 0.956 0.000 0.000 0.028 0.016 0.000
#> GSM782720     3  0.5473      0.802 0.000 0.000 0.612 0.204 0.172 0.012
#> GSM782721     1  0.3880      0.626 0.804 0.000 0.000 0.032 0.088 0.076
#> GSM782722     4  0.5683      0.988 0.116 0.000 0.000 0.604 0.244 0.036
#> GSM782723     2  0.0260      0.929 0.000 0.992 0.000 0.000 0.008 0.000
#> GSM782724     2  0.3895      0.816 0.000 0.800 0.000 0.032 0.108 0.060
#> GSM782725     4  0.5708      0.994 0.112 0.000 0.000 0.604 0.244 0.040
#> GSM782726     6  0.2838      0.941 0.188 0.000 0.000 0.000 0.004 0.808
#> GSM782727     3  0.5473      0.802 0.000 0.000 0.612 0.204 0.172 0.012
#> GSM782728     2  0.0000      0.930 0.000 1.000 0.000 0.000 0.000 0.000
#> GSM782729     4  0.5708      0.994 0.112 0.000 0.000 0.604 0.244 0.040
#> GSM782730     3  0.5473      0.802 0.000 0.000 0.612 0.204 0.172 0.012
#> GSM782731     6  0.4314      0.881 0.184 0.000 0.000 0.000 0.096 0.720
#> GSM782732     6  0.4314      0.881 0.184 0.000 0.000 0.000 0.096 0.720
#> GSM782733     3  0.0000      0.788 0.000 0.000 1.000 0.000 0.000 0.000
#> GSM782734     6  0.2697      0.942 0.188 0.000 0.000 0.000 0.000 0.812
#> GSM782735     2  0.4093      0.824 0.000 0.784 0.000 0.080 0.108 0.028
#> GSM782736     5  0.6812      0.550 0.300 0.000 0.000 0.160 0.456 0.084
#> GSM782737     2  0.0260      0.929 0.000 0.992 0.000 0.000 0.008 0.000
#> GSM782738     5  0.5423      0.816 0.440 0.000 0.000 0.004 0.456 0.100
#> GSM782739     6  0.3136      0.945 0.188 0.000 0.000 0.000 0.016 0.796
#> GSM782740     2  0.0000      0.930 0.000 1.000 0.000 0.000 0.000 0.000
#> GSM782741     6  0.3136      0.945 0.188 0.000 0.000 0.000 0.016 0.796
#> GSM782742     3  0.5473      0.802 0.000 0.000 0.612 0.204 0.172 0.012
#> GSM782743     3  0.0146      0.788 0.000 0.000 0.996 0.000 0.000 0.004
#> GSM782744     3  0.6338      0.731 0.000 0.000 0.540 0.156 0.244 0.060
#> GSM782745     6  0.2838      0.941 0.188 0.000 0.000 0.000 0.004 0.808
#> GSM782746     2  0.4093      0.824 0.000 0.784 0.000 0.080 0.108 0.028

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-kmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-CV-kmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-CV-kmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-CV-kmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-CV-kmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-kmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-CV-kmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-CV-kmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-CV-kmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-CV-kmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-kmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-CV-kmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-CV-kmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-CV-kmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-CV-kmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-kmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-CV-kmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-CV-kmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-CV-kmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-CV-kmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-kmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-CV-kmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-CV-kmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-CV-kmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-CV-kmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>            n agent(p) k
#> CV:kmeans 51    0.648 2
#> CV:kmeans 51    0.642 3
#> CV:kmeans 51    0.642 4
#> CV:kmeans 39    0.425 5
#> CV:kmeans 49    0.394 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:skmeans*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "skmeans"]
# you can also extract it by
# res = res_list["CV:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.633           0.897       0.915         0.4236 0.506   0.506
#> 3 3 1.000           1.000       1.000         0.3674 0.915   0.833
#> 4 4 0.731           0.435       0.766         0.2443 0.977   0.946
#> 5 5 0.947           0.922       0.956         0.1099 0.780   0.457
#> 6 6 0.871           0.876       0.910         0.0317 0.969   0.846

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 3

There is also optional best \(k\) = 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette   p1   p2
#> GSM782696     1   0.000      1.000 1.00 0.00
#> GSM782697     1   0.000      1.000 1.00 0.00
#> GSM782698     1   0.000      1.000 1.00 0.00
#> GSM782699     1   0.000      1.000 1.00 0.00
#> GSM782700     2   0.000      0.756 0.00 1.00
#> GSM782701     1   0.000      1.000 1.00 0.00
#> GSM782702     1   0.000      1.000 1.00 0.00
#> GSM782703     2   0.943      0.747 0.36 0.64
#> GSM782704     2   0.943      0.747 0.36 0.64
#> GSM782705     1   0.000      1.000 1.00 0.00
#> GSM782706     1   0.000      1.000 1.00 0.00
#> GSM782707     1   0.000      1.000 1.00 0.00
#> GSM782708     2   0.943      0.747 0.36 0.64
#> GSM782709     1   0.000      1.000 1.00 0.00
#> GSM782710     1   0.000      1.000 1.00 0.00
#> GSM782711     1   0.000      1.000 1.00 0.00
#> GSM782712     1   0.000      1.000 1.00 0.00
#> GSM782713     2   0.943      0.747 0.36 0.64
#> GSM782714     2   0.000      0.756 0.00 1.00
#> GSM782715     1   0.000      1.000 1.00 0.00
#> GSM782716     2   0.943      0.747 0.36 0.64
#> GSM782717     1   0.000      1.000 1.00 0.00
#> GSM782718     1   0.000      1.000 1.00 0.00
#> GSM782719     1   0.000      1.000 1.00 0.00
#> GSM782720     2   0.943      0.747 0.36 0.64
#> GSM782721     1   0.000      1.000 1.00 0.00
#> GSM782722     1   0.000      1.000 1.00 0.00
#> GSM782723     2   0.000      0.756 0.00 1.00
#> GSM782724     2   0.000      0.756 0.00 1.00
#> GSM782725     1   0.000      1.000 1.00 0.00
#> GSM782726     1   0.000      1.000 1.00 0.00
#> GSM782727     2   0.943      0.747 0.36 0.64
#> GSM782728     2   0.000      0.756 0.00 1.00
#> GSM782729     1   0.000      1.000 1.00 0.00
#> GSM782730     2   0.943      0.747 0.36 0.64
#> GSM782731     1   0.000      1.000 1.00 0.00
#> GSM782732     1   0.000      1.000 1.00 0.00
#> GSM782733     2   0.943      0.747 0.36 0.64
#> GSM782734     1   0.000      1.000 1.00 0.00
#> GSM782735     2   0.000      0.756 0.00 1.00
#> GSM782736     1   0.000      1.000 1.00 0.00
#> GSM782737     2   0.000      0.756 0.00 1.00
#> GSM782738     1   0.000      1.000 1.00 0.00
#> GSM782739     1   0.000      1.000 1.00 0.00
#> GSM782740     2   0.000      0.756 0.00 1.00
#> GSM782741     1   0.000      1.000 1.00 0.00
#> GSM782742     2   0.943      0.747 0.36 0.64
#> GSM782743     2   0.943      0.747 0.36 0.64
#> GSM782744     2   0.943      0.747 0.36 0.64
#> GSM782745     1   0.000      1.000 1.00 0.00
#> GSM782746     2   0.000      0.756 0.00 1.00

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1   0.445      0.395 0.692  0  0 0.308
#> GSM782697     1   0.496      0.250 0.552  0  0 0.448
#> GSM782698     1   0.422      0.389 0.728  0  0 0.272
#> GSM782699     1   0.456      0.393 0.672  0  0 0.328
#> GSM782700     2   0.000      1.000 0.000  1  0 0.000
#> GSM782701     1   0.460      0.388 0.664  0  0 0.336
#> GSM782702     1   0.496      0.250 0.552  0  0 0.448
#> GSM782703     3   0.000      1.000 0.000  0  1 0.000
#> GSM782704     3   0.000      1.000 0.000  0  1 0.000
#> GSM782705     1   0.000      0.253 1.000  0  0 0.000
#> GSM782706     1   0.456      0.393 0.672  0  0 0.328
#> GSM782707     1   0.454      0.394 0.676  0  0 0.324
#> GSM782708     3   0.000      1.000 0.000  0  1 0.000
#> GSM782709     1   0.499      0.207 0.532  0  0 0.468
#> GSM782710     4   0.489      0.000 0.412  0  0 0.588
#> GSM782711     1   0.476      0.357 0.628  0  0 0.372
#> GSM782712     1   0.483      0.335 0.608  0  0 0.392
#> GSM782713     3   0.000      1.000 0.000  0  1 0.000
#> GSM782714     2   0.000      1.000 0.000  1  0 0.000
#> GSM782715     1   0.000      0.253 1.000  0  0 0.000
#> GSM782716     3   0.000      1.000 0.000  0  1 0.000
#> GSM782717     1   0.499     -0.675 0.532  0  0 0.468
#> GSM782718     1   0.000      0.253 1.000  0  0 0.000
#> GSM782719     1   0.454      0.394 0.676  0  0 0.324
#> GSM782720     3   0.000      1.000 0.000  0  1 0.000
#> GSM782721     1   0.456      0.393 0.672  0  0 0.328
#> GSM782722     1   0.416      0.215 0.736  0  0 0.264
#> GSM782723     2   0.000      1.000 0.000  1  0 0.000
#> GSM782724     2   0.000      1.000 0.000  1  0 0.000
#> GSM782725     1   0.422      0.208 0.728  0  0 0.272
#> GSM782726     1   0.499     -0.675 0.532  0  0 0.468
#> GSM782727     3   0.000      1.000 0.000  0  1 0.000
#> GSM782728     2   0.000      1.000 0.000  1  0 0.000
#> GSM782729     1   0.422      0.208 0.728  0  0 0.272
#> GSM782730     3   0.000      1.000 0.000  0  1 0.000
#> GSM782731     1   0.488     -0.587 0.592  0  0 0.408
#> GSM782732     1   0.488     -0.587 0.592  0  0 0.408
#> GSM782733     3   0.000      1.000 0.000  0  1 0.000
#> GSM782734     1   0.499     -0.675 0.532  0  0 0.468
#> GSM782735     2   0.000      1.000 0.000  1  0 0.000
#> GSM782736     1   0.416      0.215 0.736  0  0 0.264
#> GSM782737     2   0.000      1.000 0.000  1  0 0.000
#> GSM782738     1   0.000      0.253 1.000  0  0 0.000
#> GSM782739     1   0.499     -0.675 0.532  0  0 0.468
#> GSM782740     2   0.000      1.000 0.000  1  0 0.000
#> GSM782741     1   0.499     -0.675 0.532  0  0 0.468
#> GSM782742     3   0.000      1.000 0.000  0  1 0.000
#> GSM782743     3   0.000      1.000 0.000  0  1 0.000
#> GSM782744     3   0.000      1.000 0.000  0  1 0.000
#> GSM782745     1   0.499     -0.675 0.532  0  0 0.468
#> GSM782746     2   0.000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2 p3    p4    p5
#> GSM782696     1  0.0000      0.968 1.000  0  0 0.000 0.000
#> GSM782697     1  0.0000      0.968 1.000  0  0 0.000 0.000
#> GSM782698     1  0.0000      0.968 1.000  0  0 0.000 0.000
#> GSM782699     1  0.0000      0.968 1.000  0  0 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782701     1  0.0671      0.962 0.980  0  0 0.004 0.016
#> GSM782702     1  0.0771      0.960 0.976  0  0 0.004 0.020
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782705     4  0.4547      0.572 0.400  0  0 0.588 0.012
#> GSM782706     1  0.1638      0.926 0.932  0  0 0.004 0.064
#> GSM782707     1  0.0162      0.967 0.996  0  0 0.004 0.000
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782709     1  0.2329      0.854 0.876  0  0 0.000 0.124
#> GSM782710     5  0.1768      0.865 0.072  0  0 0.004 0.924
#> GSM782711     1  0.0000      0.968 1.000  0  0 0.000 0.000
#> GSM782712     1  0.0324      0.967 0.992  0  0 0.004 0.004
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782715     4  0.4777      0.728 0.268  0  0 0.680 0.052
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782717     5  0.0000      0.925 0.000  0  0 0.000 1.000
#> GSM782718     4  0.4546      0.712 0.304  0  0 0.668 0.028
#> GSM782719     1  0.0000      0.968 1.000  0  0 0.000 0.000
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782721     1  0.1638      0.926 0.932  0  0 0.004 0.064
#> GSM782722     4  0.0162      0.762 0.000  0  0 0.996 0.004
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782725     4  0.0162      0.762 0.000  0  0 0.996 0.004
#> GSM782726     5  0.0000      0.925 0.000  0  0 0.000 1.000
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782729     4  0.0162      0.762 0.000  0  0 0.996 0.004
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782731     5  0.3210      0.742 0.000  0  0 0.212 0.788
#> GSM782732     5  0.3274      0.731 0.000  0  0 0.220 0.780
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782734     5  0.0000      0.925 0.000  0  0 0.000 1.000
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782736     4  0.0162      0.762 0.000  0  0 0.996 0.004
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782738     4  0.4914      0.730 0.260  0  0 0.676 0.064
#> GSM782739     5  0.0290      0.923 0.000  0  0 0.008 0.992
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782741     5  0.0162      0.924 0.004  0  0 0.000 0.996
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782745     5  0.0000      0.925 0.000  0  0 0.000 1.000
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1  0.1471      0.880 0.932  0 0.000 0.004 0.064 0.000
#> GSM782697     1  0.3078      0.845 0.836  0 0.000 0.056 0.108 0.000
#> GSM782698     1  0.3316      0.837 0.812  0 0.000 0.052 0.136 0.000
#> GSM782699     1  0.3377      0.834 0.808  0 0.000 0.056 0.136 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     1  0.1700      0.880 0.936  0 0.000 0.024 0.028 0.012
#> GSM782702     1  0.1767      0.882 0.932  0 0.000 0.012 0.020 0.036
#> GSM782703     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782704     3  0.0405      0.993 0.000  0 0.988 0.008 0.004 0.000
#> GSM782705     5  0.3323      0.605 0.204  0 0.000 0.008 0.780 0.008
#> GSM782706     1  0.3776      0.795 0.792  0 0.000 0.036 0.148 0.024
#> GSM782707     1  0.0891      0.884 0.968  0 0.000 0.008 0.024 0.000
#> GSM782708     3  0.0405      0.993 0.000  0 0.988 0.008 0.004 0.000
#> GSM782709     1  0.4225      0.808 0.780  0 0.000 0.056 0.056 0.108
#> GSM782710     6  0.2933      0.779 0.092  0 0.000 0.032 0.016 0.860
#> GSM782711     1  0.2420      0.868 0.884  0 0.000 0.040 0.076 0.000
#> GSM782712     1  0.1906      0.881 0.924  0 0.000 0.036 0.032 0.008
#> GSM782713     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     5  0.3107      0.676 0.080  0 0.000 0.072 0.844 0.004
#> GSM782716     3  0.0405      0.993 0.000  0 0.988 0.008 0.004 0.000
#> GSM782717     6  0.2420      0.838 0.004  0 0.000 0.004 0.128 0.864
#> GSM782718     5  0.2964      0.688 0.108  0 0.000 0.040 0.848 0.004
#> GSM782719     1  0.0622      0.885 0.980  0 0.000 0.008 0.012 0.000
#> GSM782720     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782721     1  0.3776      0.795 0.792  0 0.000 0.036 0.148 0.024
#> GSM782722     4  0.2378      0.984 0.000  0 0.000 0.848 0.152 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     4  0.2260      0.992 0.000  0 0.000 0.860 0.140 0.000
#> GSM782726     6  0.0790      0.866 0.000  0 0.000 0.032 0.000 0.968
#> GSM782727     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     4  0.2260      0.992 0.000  0 0.000 0.860 0.140 0.000
#> GSM782730     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782731     5  0.3717      0.381 0.000  0 0.000 0.000 0.616 0.384
#> GSM782732     5  0.3695      0.399 0.000  0 0.000 0.000 0.624 0.376
#> GSM782733     3  0.0405      0.993 0.000  0 0.988 0.008 0.004 0.000
#> GSM782734     6  0.0777      0.873 0.004  0 0.000 0.000 0.024 0.972
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     5  0.3508      0.423 0.004  0 0.000 0.292 0.704 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     5  0.3065      0.690 0.088  0 0.000 0.048 0.852 0.012
#> GSM782739     6  0.3104      0.743 0.004  0 0.000 0.004 0.204 0.788
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     6  0.2325      0.855 0.008  0 0.000 0.008 0.100 0.884
#> GSM782742     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782743     3  0.0405      0.993 0.000  0 0.988 0.008 0.004 0.000
#> GSM782744     3  0.0000      0.995 0.000  0 1.000 0.000 0.000 0.000
#> GSM782745     6  0.0790      0.866 0.000  0 0.000 0.032 0.000 0.968
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-skmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-CV-skmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-CV-skmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-CV-skmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-CV-skmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-skmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-CV-skmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-CV-skmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-CV-skmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-CV-skmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-skmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-CV-skmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-CV-skmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-CV-skmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-CV-skmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-skmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-CV-skmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-CV-skmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-CV-skmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-CV-skmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-skmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-CV-skmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-CV-skmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-CV-skmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-CV-skmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> CV:skmeans 51    0.493 2
#> CV:skmeans 51    0.642 3
#> CV:skmeans 21    0.529 4
#> CV:skmeans 51    0.502 5
#> CV:skmeans 48    0.422 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:pam*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "pam"]
# you can also extract it by
# res = res_list["CV:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 6.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.860           0.900       0.943         0.1691 0.936   0.849
#> 5 5 0.781           0.623       0.783         0.1004 0.865   0.641
#> 6 6 0.902           0.890       0.950         0.0756 0.907   0.664

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 6
#> attr(,"optional")
#> [1] 2 3

There is also optional best \(k\) = 2 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1   0.000      0.876 1.000  0  0 0.000
#> GSM782697     1   0.000      0.876 1.000  0  0 0.000
#> GSM782698     1   0.000      0.876 1.000  0  0 0.000
#> GSM782699     1   0.000      0.876 1.000  0  0 0.000
#> GSM782700     2   0.000      1.000 0.000  1  0 0.000
#> GSM782701     1   0.000      0.876 1.000  0  0 0.000
#> GSM782702     1   0.000      0.876 1.000  0  0 0.000
#> GSM782703     3   0.000      1.000 0.000  0  1 0.000
#> GSM782704     3   0.000      1.000 0.000  0  1 0.000
#> GSM782705     1   0.448      0.691 0.688  0  0 0.312
#> GSM782706     1   0.000      0.876 1.000  0  0 0.000
#> GSM782707     1   0.000      0.876 1.000  0  0 0.000
#> GSM782708     3   0.000      1.000 0.000  0  1 0.000
#> GSM782709     1   0.000      0.876 1.000  0  0 0.000
#> GSM782710     1   0.000      0.876 1.000  0  0 0.000
#> GSM782711     1   0.000      0.876 1.000  0  0 0.000
#> GSM782712     1   0.000      0.876 1.000  0  0 0.000
#> GSM782713     3   0.000      1.000 0.000  0  1 0.000
#> GSM782714     2   0.000      1.000 0.000  1  0 0.000
#> GSM782715     1   0.000      0.876 1.000  0  0 0.000
#> GSM782716     3   0.000      1.000 0.000  0  1 0.000
#> GSM782717     1   0.448      0.691 0.688  0  0 0.312
#> GSM782718     1   0.448      0.691 0.688  0  0 0.312
#> GSM782719     1   0.000      0.876 1.000  0  0 0.000
#> GSM782720     3   0.000      1.000 0.000  0  1 0.000
#> GSM782721     1   0.000      0.876 1.000  0  0 0.000
#> GSM782722     4   0.000      1.000 0.000  0  0 1.000
#> GSM782723     2   0.000      1.000 0.000  1  0 0.000
#> GSM782724     2   0.000      1.000 0.000  1  0 0.000
#> GSM782725     4   0.000      1.000 0.000  0  0 1.000
#> GSM782726     1   0.164      0.860 0.940  0  0 0.060
#> GSM782727     3   0.000      1.000 0.000  0  1 0.000
#> GSM782728     2   0.000      1.000 0.000  1  0 0.000
#> GSM782729     4   0.000      1.000 0.000  0  0 1.000
#> GSM782730     3   0.000      1.000 0.000  0  1 0.000
#> GSM782731     1   0.448      0.691 0.688  0  0 0.312
#> GSM782732     1   0.448      0.691 0.688  0  0 0.312
#> GSM782733     3   0.000      1.000 0.000  0  1 0.000
#> GSM782734     1   0.139      0.864 0.952  0  0 0.048
#> GSM782735     2   0.000      1.000 0.000  1  0 0.000
#> GSM782736     1   0.492      0.501 0.576  0  0 0.424
#> GSM782737     2   0.000      1.000 0.000  1  0 0.000
#> GSM782738     1   0.448      0.691 0.688  0  0 0.312
#> GSM782739     1   0.448      0.691 0.688  0  0 0.312
#> GSM782740     2   0.000      1.000 0.000  1  0 0.000
#> GSM782741     1   0.194      0.853 0.924  0  0 0.076
#> GSM782742     3   0.000      1.000 0.000  0  1 0.000
#> GSM782743     3   0.000      1.000 0.000  0  1 0.000
#> GSM782744     3   0.000      1.000 0.000  0  1 0.000
#> GSM782745     1   0.276      0.826 0.872  0  0 0.128
#> GSM782746     2   0.000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2  p3    p4    p5
#> GSM782696     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782697     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782698     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782699     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782700     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782701     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782702     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782703     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782704     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782705     1  0.6445    0.15834 0.496  0 0.0 0.288 0.216
#> GSM782706     1  0.2561    0.72642 0.856  0 0.0 0.000 0.144
#> GSM782707     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782708     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782709     1  0.0794    0.78977 0.972  0 0.0 0.000 0.028
#> GSM782710     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782711     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782712     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782713     5  0.4182    0.00701 0.000  0 0.4 0.000 0.600
#> GSM782714     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782715     1  0.1197    0.78089 0.952  0 0.0 0.000 0.048
#> GSM782716     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782717     5  0.6769   -0.12414 0.316  0 0.0 0.288 0.396
#> GSM782718     1  0.6605    0.10290 0.460  0 0.0 0.288 0.252
#> GSM782719     1  0.0000    0.79905 1.000  0 0.0 0.000 0.000
#> GSM782720     5  0.4182    0.00701 0.000  0 0.4 0.000 0.600
#> GSM782721     1  0.2852    0.71459 0.828  0 0.0 0.000 0.172
#> GSM782722     4  0.0000    0.71674 0.000  0 0.0 1.000 0.000
#> GSM782723     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782724     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782725     4  0.0000    0.71674 0.000  0 0.0 1.000 0.000
#> GSM782726     1  0.4987    0.54827 0.616  0 0.0 0.044 0.340
#> GSM782727     5  0.4182    0.00701 0.000  0 0.4 0.000 0.600
#> GSM782728     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782729     4  0.0000    0.71674 0.000  0 0.0 1.000 0.000
#> GSM782730     5  0.4182    0.00701 0.000  0 0.4 0.000 0.600
#> GSM782731     5  0.6763   -0.12431 0.312  0 0.0 0.288 0.400
#> GSM782732     5  0.6763   -0.12431 0.312  0 0.0 0.288 0.400
#> GSM782733     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782734     1  0.4731    0.57528 0.640  0 0.0 0.032 0.328
#> GSM782735     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782736     4  0.6819   -0.07978 0.320  0 0.0 0.356 0.324
#> GSM782737     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782738     1  0.6647    0.08671 0.448  0 0.0 0.288 0.264
#> GSM782739     5  0.6779   -0.12708 0.324  0 0.0 0.288 0.388
#> GSM782740     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000
#> GSM782741     1  0.5036    0.55243 0.628  0 0.0 0.052 0.320
#> GSM782742     5  0.4182    0.00701 0.000  0 0.4 0.000 0.600
#> GSM782743     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782744     3  0.0000    1.00000 0.000  0 1.0 0.000 0.000
#> GSM782745     1  0.5901    0.36751 0.496  0 0.0 0.104 0.400
#> GSM782746     2  0.0000    1.00000 0.000  1 0.0 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2 p3    p4 p5    p6
#> GSM782696     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782697     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782698     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782699     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782700     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782701     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782702     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782703     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782704     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782705     6  0.2697      0.786 0.188 0.000  0 0.000  0 0.812
#> GSM782706     1  0.2340      0.788 0.852 0.000  0 0.000  0 0.148
#> GSM782707     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782708     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782709     1  0.0713      0.877 0.972 0.000  0 0.000  0 0.028
#> GSM782710     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782711     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782712     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782713     5  0.0000      1.000 0.000 0.000  0 0.000  1 0.000
#> GSM782714     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782715     1  0.1075      0.861 0.952 0.000  0 0.000  0 0.048
#> GSM782716     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782717     6  0.0146      0.854 0.004 0.000  0 0.000  0 0.996
#> GSM782718     6  0.2378      0.816 0.152 0.000  0 0.000  0 0.848
#> GSM782719     1  0.0000      0.890 1.000 0.000  0 0.000  0 0.000
#> GSM782720     5  0.0000      1.000 0.000 0.000  0 0.000  1 0.000
#> GSM782721     1  0.2597      0.768 0.824 0.000  0 0.000  0 0.176
#> GSM782722     4  0.0363      1.000 0.000 0.000  0 0.988  0 0.012
#> GSM782723     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782724     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782725     4  0.0363      1.000 0.000 0.000  0 0.988  0 0.012
#> GSM782726     1  0.3857      0.269 0.532 0.000  0 0.000  0 0.468
#> GSM782727     5  0.0000      1.000 0.000 0.000  0 0.000  1 0.000
#> GSM782728     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782729     4  0.0363      1.000 0.000 0.000  0 0.988  0 0.012
#> GSM782730     5  0.0000      1.000 0.000 0.000  0 0.000  1 0.000
#> GSM782731     6  0.0000      0.853 0.000 0.000  0 0.000  0 1.000
#> GSM782732     6  0.0000      0.853 0.000 0.000  0 0.000  0 1.000
#> GSM782733     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782734     1  0.3765      0.440 0.596 0.000  0 0.000  0 0.404
#> GSM782735     2  0.0363      0.991 0.000 0.988  0 0.012  0 0.000
#> GSM782736     6  0.1644      0.853 0.076 0.000  0 0.004  0 0.920
#> GSM782737     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782738     6  0.2260      0.826 0.140 0.000  0 0.000  0 0.860
#> GSM782739     6  0.0363      0.855 0.012 0.000  0 0.000  0 0.988
#> GSM782740     2  0.0000      0.997 0.000 1.000  0 0.000  0 0.000
#> GSM782741     1  0.3847      0.277 0.544 0.000  0 0.000  0 0.456
#> GSM782742     5  0.0000      1.000 0.000 0.000  0 0.000  1 0.000
#> GSM782743     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782744     3  0.0000      1.000 0.000 0.000  1 0.000  0 0.000
#> GSM782745     6  0.2854      0.659 0.208 0.000  0 0.000  0 0.792
#> GSM782746     2  0.0363      0.991 0.000 0.988  0 0.012  0 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-pam-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-CV-pam-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-CV-pam-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-CV-pam-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-CV-pam-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-pam-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-CV-pam-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-CV-pam-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-CV-pam-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-CV-pam-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-pam-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-CV-pam-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-CV-pam-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-CV-pam-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-CV-pam-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-pam-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-CV-pam-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-CV-pam-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-CV-pam-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-CV-pam-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-pam-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-CV-pam-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-CV-pam-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-CV-pam-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-CV-pam-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>         n agent(p) k
#> CV:pam 51    0.648 2
#> CV:pam 51    0.642 3
#> CV:pam 51    0.502 4
#> CV:pam 37    0.491 5
#> CV:pam 48    0.445 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:mclust*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "mclust"]
# you can also extract it by
# res = res_list["CV:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 4.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.984       0.986         0.4847 0.506   0.506
#> 3 3 0.977           0.967       0.984         0.2154 0.915   0.833
#> 4 4 0.936           0.905       0.932         0.1039 0.918   0.806
#> 5 5 0.685           0.590       0.738         0.1488 0.941   0.828
#> 6 6 0.695           0.561       0.740         0.0503 0.797   0.413

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 4
#> attr(,"optional")
#> [1] 2 3

There is also optional best \(k\) = 2 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1  0.0000      0.997 1.000 0.000
#> GSM782697     1  0.0000      0.997 1.000 0.000
#> GSM782698     1  0.0000      0.997 1.000 0.000
#> GSM782699     1  0.0000      0.997 1.000 0.000
#> GSM782700     2  0.0000      0.967 0.000 1.000
#> GSM782701     1  0.0000      0.997 1.000 0.000
#> GSM782702     1  0.0000      0.997 1.000 0.000
#> GSM782703     2  0.2948      0.974 0.052 0.948
#> GSM782704     2  0.2948      0.974 0.052 0.948
#> GSM782705     1  0.0000      0.997 1.000 0.000
#> GSM782706     1  0.0000      0.997 1.000 0.000
#> GSM782707     1  0.0000      0.997 1.000 0.000
#> GSM782708     2  0.2948      0.974 0.052 0.948
#> GSM782709     1  0.0000      0.997 1.000 0.000
#> GSM782710     1  0.0000      0.997 1.000 0.000
#> GSM782711     1  0.0000      0.997 1.000 0.000
#> GSM782712     1  0.0000      0.997 1.000 0.000
#> GSM782713     2  0.2948      0.974 0.052 0.948
#> GSM782714     2  0.0000      0.967 0.000 1.000
#> GSM782715     1  0.0000      0.997 1.000 0.000
#> GSM782716     2  0.2948      0.974 0.052 0.948
#> GSM782717     1  0.0000      0.997 1.000 0.000
#> GSM782718     1  0.0000      0.997 1.000 0.000
#> GSM782719     1  0.0000      0.997 1.000 0.000
#> GSM782720     2  0.2948      0.974 0.052 0.948
#> GSM782721     1  0.0000      0.997 1.000 0.000
#> GSM782722     1  0.1843      0.972 0.972 0.028
#> GSM782723     2  0.0000      0.967 0.000 1.000
#> GSM782724     2  0.0000      0.967 0.000 1.000
#> GSM782725     1  0.1843      0.972 0.972 0.028
#> GSM782726     1  0.0000      0.997 1.000 0.000
#> GSM782727     2  0.2948      0.974 0.052 0.948
#> GSM782728     2  0.0000      0.967 0.000 1.000
#> GSM782729     1  0.1633      0.976 0.976 0.024
#> GSM782730     2  0.2948      0.974 0.052 0.948
#> GSM782731     1  0.0000      0.997 1.000 0.000
#> GSM782732     1  0.0000      0.997 1.000 0.000
#> GSM782733     2  0.2948      0.974 0.052 0.948
#> GSM782734     1  0.0000      0.997 1.000 0.000
#> GSM782735     2  0.0000      0.967 0.000 1.000
#> GSM782736     1  0.0672      0.990 0.992 0.008
#> GSM782737     2  0.0000      0.967 0.000 1.000
#> GSM782738     1  0.0000      0.997 1.000 0.000
#> GSM782739     1  0.0000      0.997 1.000 0.000
#> GSM782740     2  0.0000      0.967 0.000 1.000
#> GSM782741     1  0.0000      0.997 1.000 0.000
#> GSM782742     2  0.2948      0.974 0.052 0.948
#> GSM782743     2  0.3114      0.971 0.056 0.944
#> GSM782744     2  0.3733      0.956 0.072 0.928
#> GSM782745     1  0.0000      0.997 1.000 0.000
#> GSM782746     2  0.0000      0.967 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1   0.000      0.971 1.000 0.000 0.000
#> GSM782697     1   0.000      0.971 1.000 0.000 0.000
#> GSM782698     1   0.000      0.971 1.000 0.000 0.000
#> GSM782699     1   0.000      0.971 1.000 0.000 0.000
#> GSM782700     2   0.000      1.000 0.000 1.000 0.000
#> GSM782701     1   0.000      0.971 1.000 0.000 0.000
#> GSM782702     1   0.000      0.971 1.000 0.000 0.000
#> GSM782703     3   0.000      1.000 0.000 0.000 1.000
#> GSM782704     3   0.000      1.000 0.000 0.000 1.000
#> GSM782705     1   0.000      0.971 1.000 0.000 0.000
#> GSM782706     1   0.000      0.971 1.000 0.000 0.000
#> GSM782707     1   0.000      0.971 1.000 0.000 0.000
#> GSM782708     3   0.000      1.000 0.000 0.000 1.000
#> GSM782709     1   0.000      0.971 1.000 0.000 0.000
#> GSM782710     1   0.000      0.971 1.000 0.000 0.000
#> GSM782711     1   0.000      0.971 1.000 0.000 0.000
#> GSM782712     1   0.000      0.971 1.000 0.000 0.000
#> GSM782713     3   0.000      1.000 0.000 0.000 1.000
#> GSM782714     2   0.000      1.000 0.000 1.000 0.000
#> GSM782715     1   0.000      0.971 1.000 0.000 0.000
#> GSM782716     3   0.000      1.000 0.000 0.000 1.000
#> GSM782717     1   0.000      0.971 1.000 0.000 0.000
#> GSM782718     1   0.000      0.971 1.000 0.000 0.000
#> GSM782719     1   0.000      0.971 1.000 0.000 0.000
#> GSM782720     3   0.000      1.000 0.000 0.000 1.000
#> GSM782721     1   0.000      0.971 1.000 0.000 0.000
#> GSM782722     1   0.606      0.733 0.760 0.044 0.196
#> GSM782723     2   0.000      1.000 0.000 1.000 0.000
#> GSM782724     2   0.000      1.000 0.000 1.000 0.000
#> GSM782725     1   0.606      0.733 0.760 0.044 0.196
#> GSM782726     1   0.000      0.971 1.000 0.000 0.000
#> GSM782727     3   0.000      1.000 0.000 0.000 1.000
#> GSM782728     2   0.000      1.000 0.000 1.000 0.000
#> GSM782729     1   0.606      0.733 0.760 0.044 0.196
#> GSM782730     3   0.000      1.000 0.000 0.000 1.000
#> GSM782731     1   0.000      0.971 1.000 0.000 0.000
#> GSM782732     1   0.000      0.971 1.000 0.000 0.000
#> GSM782733     3   0.000      1.000 0.000 0.000 1.000
#> GSM782734     1   0.000      0.971 1.000 0.000 0.000
#> GSM782735     2   0.000      1.000 0.000 1.000 0.000
#> GSM782736     1   0.377      0.877 0.888 0.028 0.084
#> GSM782737     2   0.000      1.000 0.000 1.000 0.000
#> GSM782738     1   0.000      0.971 1.000 0.000 0.000
#> GSM782739     1   0.000      0.971 1.000 0.000 0.000
#> GSM782740     2   0.000      1.000 0.000 1.000 0.000
#> GSM782741     1   0.000      0.971 1.000 0.000 0.000
#> GSM782742     3   0.000      1.000 0.000 0.000 1.000
#> GSM782743     3   0.000      1.000 0.000 0.000 1.000
#> GSM782744     3   0.000      1.000 0.000 0.000 1.000
#> GSM782745     1   0.000      0.971 1.000 0.000 0.000
#> GSM782746     2   0.000      1.000 0.000 1.000 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.0921      0.887 0.972  0 0.000 0.028
#> GSM782697     1  0.0592      0.892 0.984  0 0.000 0.016
#> GSM782698     1  0.1302      0.886 0.956  0 0.000 0.044
#> GSM782699     1  0.0921      0.887 0.972  0 0.000 0.028
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.1118      0.884 0.964  0 0.000 0.036
#> GSM782702     1  0.1118      0.888 0.964  0 0.000 0.036
#> GSM782703     3  0.0188      0.996 0.000  0 0.996 0.004
#> GSM782704     3  0.0469      0.995 0.000  0 0.988 0.012
#> GSM782705     1  0.0921      0.887 0.972  0 0.000 0.028
#> GSM782706     1  0.0921      0.889 0.972  0 0.000 0.028
#> GSM782707     1  0.1118      0.890 0.964  0 0.000 0.036
#> GSM782708     3  0.0469      0.995 0.000  0 0.988 0.012
#> GSM782709     1  0.0592      0.896 0.984  0 0.000 0.016
#> GSM782710     1  0.0707      0.891 0.980  0 0.000 0.020
#> GSM782711     1  0.1022      0.887 0.968  0 0.000 0.032
#> GSM782712     1  0.1211      0.888 0.960  0 0.000 0.040
#> GSM782713     3  0.0000      0.996 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.0921      0.889 0.972  0 0.000 0.028
#> GSM782716     3  0.0469      0.995 0.000  0 0.988 0.012
#> GSM782717     1  0.0817      0.889 0.976  0 0.000 0.024
#> GSM782718     1  0.1302      0.886 0.956  0 0.000 0.044
#> GSM782719     1  0.1302      0.886 0.956  0 0.000 0.044
#> GSM782720     3  0.0000      0.996 0.000  0 1.000 0.000
#> GSM782721     1  0.0921      0.889 0.972  0 0.000 0.028
#> GSM782722     4  0.4948      0.925 0.440  0 0.000 0.560
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     4  0.4972      0.938 0.456  0 0.000 0.544
#> GSM782726     1  0.4877      0.107 0.592  0 0.000 0.408
#> GSM782727     3  0.0000      0.996 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     4  0.4972      0.938 0.456  0 0.000 0.544
#> GSM782730     3  0.0000      0.996 0.000  0 1.000 0.000
#> GSM782731     1  0.0592      0.895 0.984  0 0.000 0.016
#> GSM782732     1  0.0469      0.897 0.988  0 0.000 0.012
#> GSM782733     3  0.0469      0.995 0.000  0 0.988 0.012
#> GSM782734     1  0.0592      0.892 0.984  0 0.000 0.016
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     4  0.5000      0.874 0.500  0 0.000 0.500
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.1211      0.888 0.960  0 0.000 0.040
#> GSM782739     1  0.0817      0.890 0.976  0 0.000 0.024
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.0707      0.891 0.980  0 0.000 0.020
#> GSM782742     3  0.0000      0.996 0.000  0 1.000 0.000
#> GSM782743     3  0.0469      0.995 0.000  0 0.988 0.012
#> GSM782744     3  0.0000      0.996 0.000  0 1.000 0.000
#> GSM782745     1  0.4877      0.107 0.592  0 0.000 0.408
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.5232     0.4358 0.668  0 0.000 0.228 0.104
#> GSM782697     1  0.2230     0.5246 0.884  0 0.000 0.116 0.000
#> GSM782698     1  0.6081     0.1342 0.476  0 0.000 0.400 0.124
#> GSM782699     1  0.4693     0.4745 0.700  0 0.000 0.244 0.056
#> GSM782700     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.5488     0.1433 0.608  0 0.000 0.300 0.092
#> GSM782702     1  0.0510     0.5619 0.984  0 0.000 0.016 0.000
#> GSM782703     3  0.2127     0.9013 0.000  0 0.892 0.000 0.108
#> GSM782704     3  0.3074     0.8888 0.000  0 0.804 0.000 0.196
#> GSM782705     1  0.5541     0.4151 0.636  0 0.000 0.236 0.128
#> GSM782706     1  0.6039     0.0647 0.552  0 0.000 0.300 0.148
#> GSM782707     1  0.5889     0.2307 0.544  0 0.000 0.340 0.116
#> GSM782708     3  0.3366     0.8801 0.000  0 0.768 0.000 0.232
#> GSM782709     1  0.4941     0.2355 0.628  0 0.000 0.328 0.044
#> GSM782710     1  0.1282     0.5669 0.952  0 0.000 0.044 0.004
#> GSM782711     1  0.3460     0.5465 0.828  0 0.000 0.128 0.044
#> GSM782712     1  0.1251     0.5639 0.956  0 0.000 0.036 0.008
#> GSM782713     3  0.0000     0.9051 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782715     5  0.6801     0.9002 0.308  0 0.000 0.316 0.376
#> GSM782716     3  0.3366     0.8801 0.000  0 0.768 0.000 0.232
#> GSM782717     1  0.1117     0.5445 0.964  0 0.000 0.020 0.016
#> GSM782718     4  0.6688    -0.7086 0.240  0 0.000 0.404 0.356
#> GSM782719     1  0.5946     0.1324 0.508  0 0.000 0.380 0.112
#> GSM782720     3  0.0000     0.9051 0.000  0 1.000 0.000 0.000
#> GSM782721     1  0.5765     0.0802 0.580  0 0.000 0.304 0.116
#> GSM782722     4  0.1732     0.5014 0.080  0 0.000 0.920 0.000
#> GSM782723     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.3480     0.5506 0.248  0 0.000 0.752 0.000
#> GSM782726     1  0.4642     0.3635 0.660  0 0.000 0.032 0.308
#> GSM782727     3  0.0000     0.9051 0.000  0 1.000 0.000 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.3395     0.5518 0.236  0 0.000 0.764 0.000
#> GSM782730     3  0.0000     0.9051 0.000  0 1.000 0.000 0.000
#> GSM782731     1  0.6420    -0.6063 0.484  0 0.000 0.192 0.324
#> GSM782732     1  0.4797     0.0245 0.660  0 0.000 0.044 0.296
#> GSM782733     3  0.3366     0.8801 0.000  0 0.768 0.000 0.232
#> GSM782734     1  0.3183     0.4979 0.828  0 0.000 0.156 0.016
#> GSM782735     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.5697     0.2441 0.116  0 0.000 0.596 0.288
#> GSM782737     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782738     5  0.6808     0.8987 0.324  0 0.000 0.308 0.368
#> GSM782739     1  0.1549     0.5549 0.944  0 0.000 0.040 0.016
#> GSM782740     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.0912     0.5589 0.972  0 0.000 0.016 0.012
#> GSM782742     3  0.0000     0.9051 0.000  0 1.000 0.000 0.000
#> GSM782743     3  0.3366     0.8801 0.000  0 0.768 0.000 0.232
#> GSM782744     3  0.0404     0.8999 0.000  0 0.988 0.000 0.012
#> GSM782745     1  0.4786     0.3679 0.652  0 0.000 0.040 0.308
#> GSM782746     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1   0.371    -0.1952 0.620  0 0.000 0.000 0.000 0.380
#> GSM782697     6   0.398     0.5408 0.392  0 0.000 0.008 0.000 0.600
#> GSM782698     1   0.356     0.5000 0.800  0 0.000 0.056 0.004 0.140
#> GSM782699     6   0.385     0.4693 0.456  0 0.000 0.000 0.000 0.544
#> GSM782700     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     1   0.135     0.4586 0.940  0 0.000 0.004 0.000 0.056
#> GSM782702     6   0.390     0.5447 0.404  0 0.000 0.004 0.000 0.592
#> GSM782703     3   0.150     0.7183 0.000  0 0.924 0.000 0.076 0.000
#> GSM782704     3   0.350     0.0584 0.000  0 0.680 0.000 0.320 0.000
#> GSM782705     6   0.561     0.2449 0.380  0 0.000 0.148 0.000 0.472
#> GSM782706     1   0.382     0.5149 0.768  0 0.000 0.176 0.004 0.052
#> GSM782707     1   0.310     0.2351 0.756  0 0.000 0.000 0.000 0.244
#> GSM782708     5   0.382     0.8903 0.000  0 0.432 0.000 0.568 0.000
#> GSM782709     1   0.374    -0.1280 0.672  0 0.000 0.008 0.000 0.320
#> GSM782710     6   0.581     0.2175 0.360  0 0.000 0.188 0.000 0.452
#> GSM782711     6   0.394     0.5183 0.428  0 0.000 0.004 0.000 0.568
#> GSM782712     6   0.372     0.5438 0.384  0 0.000 0.000 0.000 0.616
#> GSM782713     3   0.000     0.7878 0.000  0 1.000 0.000 0.000 0.000
#> GSM782714     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     1   0.468     0.4885 0.628  0 0.000 0.312 0.004 0.056
#> GSM782716     5   0.387     0.8767 0.000  0 0.488 0.000 0.512 0.000
#> GSM782717     6   0.427     0.5357 0.412  0 0.000 0.020 0.000 0.568
#> GSM782718     1   0.456     0.4924 0.628  0 0.000 0.316 0.000 0.056
#> GSM782719     1   0.159     0.5056 0.924  0 0.000 0.004 0.000 0.072
#> GSM782720     3   0.000     0.7878 0.000  0 1.000 0.000 0.000 0.000
#> GSM782721     1   0.115     0.5047 0.960  0 0.000 0.020 0.004 0.016
#> GSM782722     6   0.666    -0.2828 0.388  0 0.000 0.064 0.148 0.400
#> GSM782723     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     6   0.544     0.0797 0.092  0 0.000 0.084 0.148 0.676
#> GSM782726     4   0.514     0.9788 0.316  0 0.000 0.596 0.012 0.076
#> GSM782727     3   0.000     0.7878 0.000  0 1.000 0.000 0.000 0.000
#> GSM782728     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     6   0.545     0.0955 0.088  0 0.000 0.068 0.180 0.664
#> GSM782730     3   0.000     0.7878 0.000  0 1.000 0.000 0.000 0.000
#> GSM782731     6   0.607     0.0432 0.292  0 0.000 0.304 0.000 0.404
#> GSM782732     6   0.598     0.1234 0.272  0 0.000 0.284 0.000 0.444
#> GSM782733     5   0.386     0.8895 0.000  0 0.480 0.000 0.520 0.000
#> GSM782734     6   0.478     0.4530 0.476  0 0.000 0.040 0.004 0.480
#> GSM782735     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     1   0.674     0.2195 0.472  0 0.000 0.160 0.288 0.080
#> GSM782737     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     1   0.555     0.3969 0.528  0 0.000 0.312 0.000 0.160
#> GSM782739     6   0.433     0.5363 0.408  0 0.000 0.024 0.000 0.568
#> GSM782740     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     6   0.435     0.5385 0.384  0 0.000 0.028 0.000 0.588
#> GSM782742     3   0.200     0.6897 0.000  0 0.884 0.000 0.116 0.000
#> GSM782743     5   0.376     0.8518 0.000  0 0.400 0.000 0.600 0.000
#> GSM782744     3   0.343     0.3275 0.000  0 0.696 0.000 0.304 0.000
#> GSM782745     4   0.514     0.9788 0.304  0 0.000 0.604 0.012 0.080
#> GSM782746     2   0.000     1.0000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-mclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-CV-mclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-CV-mclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-CV-mclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-CV-mclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-mclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-CV-mclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-CV-mclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-CV-mclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-CV-mclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-mclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-CV-mclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-CV-mclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-CV-mclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-CV-mclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-mclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-CV-mclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-CV-mclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-CV-mclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-CV-mclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-mclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-CV-mclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-CV-mclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-CV-mclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-CV-mclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>            n agent(p) k
#> CV:mclust 51    0.493 2
#> CV:mclust 51    0.642 3
#> CV:mclust 49    0.495 4
#> CV:mclust 34    0.352 5
#> CV:mclust 32    0.497 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


CV:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["CV", "NMF"]
# you can also extract it by
# res = res_list["CV:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'CV' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk CV-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk CV-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.824           0.838       0.921         0.1346 0.918   0.806
#> 5 5 0.859           0.868       0.928         0.0808 0.977   0.934
#> 6 6 0.786           0.814       0.881         0.0500 0.956   0.867

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.1302      0.829 0.956  0 0.000 0.044
#> GSM782697     1  0.2973      0.705 0.856  0 0.000 0.144
#> GSM782698     1  0.3266      0.675 0.832  0 0.000 0.168
#> GSM782699     1  0.2081      0.788 0.916  0 0.000 0.084
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.0592      0.846 0.984  0 0.000 0.016
#> GSM782702     1  0.0336      0.847 0.992  0 0.000 0.008
#> GSM782703     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782705     1  0.0921      0.836 0.972  0 0.000 0.028
#> GSM782706     1  0.0188      0.847 0.996  0 0.000 0.004
#> GSM782707     1  0.0817      0.843 0.976  0 0.000 0.024
#> GSM782708     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782709     1  0.0817      0.842 0.976  0 0.000 0.024
#> GSM782710     1  0.0469      0.848 0.988  0 0.000 0.012
#> GSM782711     1  0.0817      0.843 0.976  0 0.000 0.024
#> GSM782712     1  0.0707      0.843 0.980  0 0.000 0.020
#> GSM782713     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.4985     -0.791 0.532  0 0.000 0.468
#> GSM782716     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782717     1  0.0336      0.845 0.992  0 0.000 0.008
#> GSM782718     1  0.3486      0.546 0.812  0 0.000 0.188
#> GSM782719     1  0.3172      0.675 0.840  0 0.000 0.160
#> GSM782720     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782721     1  0.0000      0.847 1.000  0 0.000 0.000
#> GSM782722     4  0.4746      0.797 0.368  0 0.000 0.632
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     4  0.4981      0.905 0.464  0 0.000 0.536
#> GSM782726     1  0.1022      0.834 0.968  0 0.000 0.032
#> GSM782727     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     4  0.4985      0.905 0.468  0 0.000 0.532
#> GSM782730     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782731     1  0.3400      0.554 0.820  0 0.000 0.180
#> GSM782732     1  0.2589      0.714 0.884  0 0.000 0.116
#> GSM782733     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782734     1  0.0592      0.842 0.984  0 0.000 0.016
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     4  0.4996      0.878 0.484  0 0.000 0.516
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.4193      0.197 0.732  0 0.000 0.268
#> GSM782739     1  0.0469      0.843 0.988  0 0.000 0.012
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.0336      0.845 0.992  0 0.000 0.008
#> GSM782742     3  0.0188      0.995 0.000  0 0.996 0.004
#> GSM782743     3  0.0000      0.997 0.000  0 1.000 0.000
#> GSM782744     3  0.1022      0.974 0.000  0 0.968 0.032
#> GSM782745     1  0.2149      0.765 0.912  0 0.000 0.088
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1    p2    p3    p4    p5
#> GSM782696     1  0.1792     0.8556 0.916 0.000 0.000 0.000 0.084
#> GSM782697     1  0.2852     0.7954 0.828 0.000 0.000 0.000 0.172
#> GSM782698     1  0.4425     0.5228 0.600 0.000 0.000 0.008 0.392
#> GSM782699     1  0.2230     0.8391 0.884 0.000 0.000 0.000 0.116
#> GSM782700     2  0.0000     0.9988 0.000 1.000 0.000 0.000 0.000
#> GSM782701     1  0.0566     0.8751 0.984 0.000 0.000 0.004 0.012
#> GSM782702     1  0.0609     0.8738 0.980 0.000 0.000 0.000 0.020
#> GSM782703     3  0.0162     0.9935 0.000 0.000 0.996 0.004 0.000
#> GSM782704     3  0.0000     0.9938 0.000 0.000 1.000 0.000 0.000
#> GSM782705     1  0.1485     0.8739 0.948 0.000 0.000 0.032 0.020
#> GSM782706     1  0.1282     0.8721 0.952 0.000 0.000 0.004 0.044
#> GSM782707     1  0.1764     0.8649 0.928 0.000 0.000 0.008 0.064
#> GSM782708     3  0.0000     0.9938 0.000 0.000 1.000 0.000 0.000
#> GSM782709     1  0.0898     0.8730 0.972 0.000 0.000 0.008 0.020
#> GSM782710     1  0.0671     0.8747 0.980 0.000 0.000 0.004 0.016
#> GSM782711     1  0.0794     0.8722 0.972 0.000 0.000 0.000 0.028
#> GSM782712     1  0.0609     0.8731 0.980 0.000 0.000 0.000 0.020
#> GSM782713     3  0.0324     0.9928 0.000 0.000 0.992 0.004 0.004
#> GSM782714     2  0.0000     0.9988 0.000 1.000 0.000 0.000 0.000
#> GSM782715     4  0.4575     0.6934 0.236 0.000 0.000 0.712 0.052
#> GSM782716     3  0.0000     0.9938 0.000 0.000 1.000 0.000 0.000
#> GSM782717     1  0.0807     0.8750 0.976 0.000 0.000 0.012 0.012
#> GSM782718     1  0.5024     0.0865 0.528 0.000 0.000 0.440 0.032
#> GSM782719     1  0.3305     0.7509 0.776 0.000 0.000 0.000 0.224
#> GSM782720     3  0.0324     0.9928 0.000 0.000 0.992 0.004 0.004
#> GSM782721     1  0.1205     0.8687 0.956 0.000 0.000 0.004 0.040
#> GSM782722     4  0.0794     0.8745 0.028 0.000 0.000 0.972 0.000
#> GSM782723     2  0.0000     0.9988 0.000 1.000 0.000 0.000 0.000
#> GSM782724     2  0.0162     0.9976 0.000 0.996 0.000 0.000 0.004
#> GSM782725     4  0.1251     0.8820 0.036 0.000 0.000 0.956 0.008
#> GSM782726     1  0.2144     0.8529 0.912 0.000 0.000 0.020 0.068
#> GSM782727     3  0.0324     0.9928 0.000 0.000 0.992 0.004 0.004
#> GSM782728     2  0.0000     0.9988 0.000 1.000 0.000 0.000 0.000
#> GSM782729     4  0.1502     0.8875 0.056 0.000 0.000 0.940 0.004
#> GSM782730     3  0.0000     0.9938 0.000 0.000 1.000 0.000 0.000
#> GSM782731     1  0.4226     0.7034 0.764 0.000 0.000 0.176 0.060
#> GSM782732     1  0.2754     0.8276 0.880 0.000 0.000 0.080 0.040
#> GSM782733     3  0.0000     0.9938 0.000 0.000 1.000 0.000 0.000
#> GSM782734     1  0.1670     0.8610 0.936 0.000 0.000 0.012 0.052
#> GSM782735     2  0.0162     0.9976 0.000 0.996 0.000 0.000 0.004
#> GSM782736     4  0.3192     0.8625 0.112 0.000 0.000 0.848 0.040
#> GSM782737     2  0.0000     0.9988 0.000 1.000 0.000 0.000 0.000
#> GSM782738     1  0.5176    -0.0616 0.492 0.000 0.000 0.468 0.040
#> GSM782739     1  0.1018     0.8734 0.968 0.000 0.000 0.016 0.016
#> GSM782740     2  0.0000     0.9988 0.000 1.000 0.000 0.000 0.000
#> GSM782741     1  0.0579     0.8737 0.984 0.000 0.000 0.008 0.008
#> GSM782742     3  0.0324     0.9928 0.000 0.000 0.992 0.004 0.004
#> GSM782743     3  0.0000     0.9938 0.000 0.000 1.000 0.000 0.000
#> GSM782744     3  0.1399     0.9609 0.000 0.000 0.952 0.028 0.020
#> GSM782745     1  0.2554     0.8408 0.892 0.000 0.000 0.036 0.072
#> GSM782746     2  0.0162     0.9976 0.000 0.996 0.000 0.000 0.004

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5 p6
#> GSM782696     1  0.2234      0.803 0.872  0 0.000 0.000 0.124 NA
#> GSM782697     1  0.2070      0.811 0.892  0 0.000 0.000 0.100 NA
#> GSM782698     1  0.4732      0.374 0.484  0 0.000 0.016 0.480 NA
#> GSM782699     1  0.2001      0.813 0.900  0 0.000 0.004 0.092 NA
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782701     1  0.3784      0.755 0.792  0 0.000 0.008 0.124 NA
#> GSM782702     1  0.1334      0.819 0.948  0 0.000 0.000 0.032 NA
#> GSM782703     3  0.0146      0.973 0.000  0 0.996 0.000 0.000 NA
#> GSM782704     3  0.0146      0.973 0.000  0 0.996 0.000 0.000 NA
#> GSM782705     1  0.2528      0.802 0.892  0 0.000 0.056 0.028 NA
#> GSM782706     1  0.6302      0.322 0.476  0 0.000 0.044 0.136 NA
#> GSM782707     1  0.4369      0.720 0.740  0 0.000 0.020 0.176 NA
#> GSM782708     3  0.0146      0.973 0.000  0 0.996 0.000 0.000 NA
#> GSM782709     1  0.1970      0.818 0.912  0 0.000 0.000 0.060 NA
#> GSM782710     1  0.1275      0.819 0.956  0 0.000 0.016 0.012 NA
#> GSM782711     1  0.1643      0.816 0.924  0 0.000 0.000 0.068 NA
#> GSM782712     1  0.2365      0.805 0.888  0 0.000 0.000 0.072 NA
#> GSM782713     3  0.0260      0.973 0.000  0 0.992 0.000 0.000 NA
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782715     4  0.5615      0.676 0.140  0 0.000 0.596 0.020 NA
#> GSM782716     3  0.0000      0.973 0.000  0 1.000 0.000 0.000 NA
#> GSM782717     1  0.1391      0.811 0.944  0 0.000 0.040 0.000 NA
#> GSM782718     4  0.5704      0.351 0.380  0 0.000 0.496 0.016 NA
#> GSM782719     1  0.4636      0.429 0.516  0 0.000 0.000 0.444 NA
#> GSM782720     3  0.0363      0.970 0.000  0 0.988 0.000 0.000 NA
#> GSM782721     1  0.5952      0.406 0.520  0 0.000 0.036 0.108 NA
#> GSM782722     4  0.1897      0.736 0.004  0 0.000 0.908 0.004 NA
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782725     4  0.1010      0.735 0.004  0 0.000 0.960 0.000 NA
#> GSM782726     1  0.1794      0.807 0.924  0 0.000 0.040 0.000 NA
#> GSM782727     3  0.0547      0.967 0.000  0 0.980 0.000 0.000 NA
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782729     4  0.1245      0.741 0.016  0 0.000 0.952 0.000 NA
#> GSM782730     3  0.0000      0.973 0.000  0 1.000 0.000 0.000 NA
#> GSM782731     1  0.3602      0.700 0.792  0 0.000 0.136 0.000 NA
#> GSM782732     1  0.2863      0.769 0.860  0 0.000 0.096 0.008 NA
#> GSM782733     3  0.0146      0.973 0.000  0 0.996 0.000 0.000 NA
#> GSM782734     1  0.1845      0.812 0.920  0 0.000 0.028 0.000 NA
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782736     4  0.2213      0.758 0.048  0 0.000 0.904 0.004 NA
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782738     4  0.5961      0.443 0.328  0 0.000 0.480 0.008 NA
#> GSM782739     1  0.1480      0.809 0.940  0 0.000 0.040 0.000 NA
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA
#> GSM782741     1  0.1341      0.817 0.948  0 0.000 0.024 0.000 NA
#> GSM782742     3  0.0713      0.963 0.000  0 0.972 0.000 0.000 NA
#> GSM782743     3  0.0146      0.973 0.000  0 0.996 0.000 0.000 NA
#> GSM782744     3  0.3645      0.734 0.000  0 0.740 0.024 0.000 NA
#> GSM782745     1  0.2308      0.794 0.892  0 0.000 0.040 0.000 NA
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 NA

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-CV-NMF-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-CV-NMF-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-CV-NMF-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-CV-NMF-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-CV-NMF-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-CV-NMF-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-CV-NMF-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-CV-NMF-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-CV-NMF-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-CV-NMF-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-CV-NMF-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-CV-NMF-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-CV-NMF-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-CV-NMF-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-CV-NMF-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-CV-NMF-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-CV-NMF-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-CV-NMF-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-CV-NMF-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-CV-NMF-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk CV-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-CV-NMF-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-CV-NMF-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-CV-NMF-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-CV-NMF-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-CV-NMF-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk CV-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>         n agent(p) k
#> CV:NMF 51    0.648 2
#> CV:NMF 51    0.642 3
#> CV:NMF 49    0.494 4
#> CV:NMF 49    0.497 5
#> CV:NMF 45    0.478 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:hclust**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "hclust"]
# you can also extract it by
# res = res_list["MAD:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           0.968       0.987         0.9772 0.718   0.599
#> 4 4 0.759           0.850       0.921         0.1370 0.956   0.896
#> 5 5 0.773           0.779       0.886         0.1181 0.905   0.749
#> 6 6 0.782           0.774       0.903         0.0133 0.991   0.970

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1 p2    p3
#> GSM782696     1   0.000      0.976 1.000  0 0.000
#> GSM782697     1   0.000      0.976 1.000  0 0.000
#> GSM782698     1   0.000      0.976 1.000  0 0.000
#> GSM782699     1   0.000      0.976 1.000  0 0.000
#> GSM782700     2   0.000      1.000 0.000  1 0.000
#> GSM782701     1   0.000      0.976 1.000  0 0.000
#> GSM782702     1   0.000      0.976 1.000  0 0.000
#> GSM782703     3   0.000      1.000 0.000  0 1.000
#> GSM782704     3   0.000      1.000 0.000  0 1.000
#> GSM782705     1   0.000      0.976 1.000  0 0.000
#> GSM782706     1   0.000      0.976 1.000  0 0.000
#> GSM782707     1   0.000      0.976 1.000  0 0.000
#> GSM782708     3   0.000      1.000 0.000  0 1.000
#> GSM782709     1   0.000      0.976 1.000  0 0.000
#> GSM782710     1   0.000      0.976 1.000  0 0.000
#> GSM782711     1   0.000      0.976 1.000  0 0.000
#> GSM782712     1   0.000      0.976 1.000  0 0.000
#> GSM782713     3   0.000      1.000 0.000  0 1.000
#> GSM782714     2   0.000      1.000 0.000  1 0.000
#> GSM782715     1   0.000      0.976 1.000  0 0.000
#> GSM782716     3   0.000      1.000 0.000  0 1.000
#> GSM782717     1   0.000      0.976 1.000  0 0.000
#> GSM782718     1   0.000      0.976 1.000  0 0.000
#> GSM782719     1   0.000      0.976 1.000  0 0.000
#> GSM782720     3   0.000      1.000 0.000  0 1.000
#> GSM782721     1   0.000      0.976 1.000  0 0.000
#> GSM782722     1   0.000      0.976 1.000  0 0.000
#> GSM782723     2   0.000      1.000 0.000  1 0.000
#> GSM782724     2   0.000      1.000 0.000  1 0.000
#> GSM782725     1   0.000      0.976 1.000  0 0.000
#> GSM782726     1   0.579      0.520 0.668  0 0.332
#> GSM782727     3   0.000      1.000 0.000  0 1.000
#> GSM782728     2   0.000      1.000 0.000  1 0.000
#> GSM782729     1   0.000      0.976 1.000  0 0.000
#> GSM782730     3   0.000      1.000 0.000  0 1.000
#> GSM782731     1   0.000      0.976 1.000  0 0.000
#> GSM782732     1   0.000      0.976 1.000  0 0.000
#> GSM782733     3   0.000      1.000 0.000  0 1.000
#> GSM782734     1   0.000      0.976 1.000  0 0.000
#> GSM782735     2   0.000      1.000 0.000  1 0.000
#> GSM782736     1   0.000      0.976 1.000  0 0.000
#> GSM782737     2   0.000      1.000 0.000  1 0.000
#> GSM782738     1   0.000      0.976 1.000  0 0.000
#> GSM782739     1   0.000      0.976 1.000  0 0.000
#> GSM782740     2   0.000      1.000 0.000  1 0.000
#> GSM782741     1   0.000      0.976 1.000  0 0.000
#> GSM782742     3   0.000      1.000 0.000  0 1.000
#> GSM782743     3   0.000      1.000 0.000  0 1.000
#> GSM782744     3   0.000      1.000 0.000  0 1.000
#> GSM782745     1   0.579      0.520 0.668  0 0.332
#> GSM782746     2   0.000      1.000 0.000  1 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.0469      0.837 0.988  0 0.000 0.012
#> GSM782697     1  0.1637      0.819 0.940  0 0.000 0.060
#> GSM782698     1  0.1022      0.834 0.968  0 0.000 0.032
#> GSM782699     1  0.0707      0.835 0.980  0 0.000 0.020
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.0188      0.838 0.996  0 0.000 0.004
#> GSM782702     1  0.0188      0.838 0.996  0 0.000 0.004
#> GSM782703     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782705     1  0.2081      0.812 0.916  0 0.000 0.084
#> GSM782706     1  0.0817      0.836 0.976  0 0.000 0.024
#> GSM782707     1  0.0188      0.838 0.996  0 0.000 0.004
#> GSM782708     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782709     1  0.2704      0.779 0.876  0 0.000 0.124
#> GSM782710     1  0.4907      0.149 0.580  0 0.000 0.420
#> GSM782711     1  0.1474      0.823 0.948  0 0.000 0.052
#> GSM782712     1  0.0188      0.838 0.996  0 0.000 0.004
#> GSM782713     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.3569      0.725 0.804  0 0.000 0.196
#> GSM782716     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782717     1  0.3837      0.676 0.776  0 0.000 0.224
#> GSM782718     1  0.2281      0.806 0.904  0 0.000 0.096
#> GSM782719     1  0.0188      0.838 0.996  0 0.000 0.004
#> GSM782720     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782721     1  0.0817      0.836 0.976  0 0.000 0.024
#> GSM782722     1  0.3688      0.711 0.792  0 0.000 0.208
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     1  0.3688      0.711 0.792  0 0.000 0.208
#> GSM782726     4  0.3688      1.000 0.208  0 0.000 0.792
#> GSM782727     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     1  0.3688      0.711 0.792  0 0.000 0.208
#> GSM782730     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782731     1  0.3726      0.691 0.788  0 0.000 0.212
#> GSM782732     1  0.3726      0.691 0.788  0 0.000 0.212
#> GSM782733     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782734     1  0.3837      0.676 0.776  0 0.000 0.224
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     1  0.2281      0.806 0.904  0 0.000 0.096
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.2281      0.806 0.904  0 0.000 0.096
#> GSM782739     1  0.3837      0.676 0.776  0 0.000 0.224
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.3837      0.676 0.776  0 0.000 0.224
#> GSM782742     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782743     3  0.0000      0.971 0.000  0 1.000 0.000
#> GSM782744     3  0.4585      0.573 0.000  0 0.668 0.332
#> GSM782745     4  0.3688      1.000 0.208  0 0.000 0.792
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.0404      0.739 0.988  0 0.000 0.012 0.000
#> GSM782697     1  0.1197      0.719 0.952  0 0.000 0.000 0.048
#> GSM782698     1  0.1121      0.736 0.956  0 0.000 0.044 0.000
#> GSM782699     1  0.0290      0.735 0.992  0 0.000 0.000 0.008
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.3039      0.670 0.808  0 0.000 0.192 0.000
#> GSM782702     1  0.1043      0.742 0.960  0 0.000 0.040 0.000
#> GSM782703     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782704     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782705     1  0.2773      0.695 0.836  0 0.000 0.164 0.000
#> GSM782706     1  0.3336      0.649 0.772  0 0.000 0.228 0.000
#> GSM782707     1  0.1270      0.740 0.948  0 0.000 0.052 0.000
#> GSM782708     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782709     1  0.2891      0.645 0.824  0 0.000 0.000 0.176
#> GSM782710     5  0.4273      0.029 0.448  0 0.000 0.000 0.552
#> GSM782711     1  0.1043      0.723 0.960  0 0.000 0.000 0.040
#> GSM782712     1  0.1043      0.742 0.960  0 0.000 0.040 0.000
#> GSM782713     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     4  0.2674      0.862 0.140  0 0.000 0.856 0.004
#> GSM782716     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782717     1  0.3990      0.516 0.688  0 0.000 0.004 0.308
#> GSM782718     1  0.3949      0.539 0.668  0 0.000 0.332 0.000
#> GSM782719     1  0.3039      0.670 0.808  0 0.000 0.192 0.000
#> GSM782720     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782721     1  0.3336      0.649 0.772  0 0.000 0.228 0.000
#> GSM782722     4  0.1410      0.955 0.060  0 0.000 0.940 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.1410      0.955 0.060  0 0.000 0.940 0.000
#> GSM782726     5  0.1121      0.660 0.044  0 0.000 0.000 0.956
#> GSM782727     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.1410      0.955 0.060  0 0.000 0.940 0.000
#> GSM782730     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782731     1  0.4046      0.531 0.696  0 0.000 0.008 0.296
#> GSM782732     1  0.4046      0.531 0.696  0 0.000 0.008 0.296
#> GSM782733     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782734     1  0.3990      0.516 0.688  0 0.000 0.004 0.308
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     1  0.3949      0.539 0.668  0 0.000 0.332 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     1  0.3949      0.539 0.668  0 0.000 0.332 0.000
#> GSM782739     1  0.3990      0.516 0.688  0 0.000 0.004 0.308
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.3990      0.516 0.688  0 0.000 0.004 0.308
#> GSM782742     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782743     3  0.0000      0.964 0.000  0 1.000 0.000 0.000
#> GSM782744     3  0.5341      0.429 0.000  0 0.564 0.060 0.376
#> GSM782745     5  0.1121      0.660 0.044  0 0.000 0.000 0.956
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2 p3    p4 p5    p6
#> GSM782696     1  0.0508     0.7438 0.984  0  0 0.012  0 0.004
#> GSM782697     1  0.1141     0.7319 0.948  0  0 0.000  0 0.052
#> GSM782698     1  0.1196     0.7402 0.952  0  0 0.040  0 0.008
#> GSM782699     1  0.0363     0.7407 0.988  0  0 0.000  0 0.012
#> GSM782700     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782701     1  0.2697     0.6733 0.812  0  0 0.188  0 0.000
#> GSM782702     1  0.0865     0.7457 0.964  0  0 0.036  0 0.000
#> GSM782703     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782704     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782705     1  0.2706     0.6976 0.832  0  0 0.160  0 0.008
#> GSM782706     1  0.2969     0.6575 0.776  0  0 0.224  0 0.000
#> GSM782707     1  0.1075     0.7437 0.952  0  0 0.048  0 0.000
#> GSM782708     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782709     1  0.2631     0.6616 0.820  0  0 0.000  0 0.180
#> GSM782710     6  0.3828    -0.0246 0.440  0  0 0.000  0 0.560
#> GSM782711     1  0.1007     0.7344 0.956  0  0 0.000  0 0.044
#> GSM782712     1  0.0865     0.7457 0.964  0  0 0.036  0 0.000
#> GSM782713     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782715     4  0.2070     0.8077 0.092  0  0 0.896  0 0.012
#> GSM782716     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782717     1  0.3619     0.5340 0.680  0  0 0.004  0 0.316
#> GSM782718     1  0.3774     0.5740 0.664  0  0 0.328  0 0.008
#> GSM782719     1  0.2697     0.6733 0.812  0  0 0.188  0 0.000
#> GSM782720     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782721     1  0.2969     0.6575 0.776  0  0 0.224  0 0.000
#> GSM782722     4  0.0000     0.9349 0.000  0  0 1.000  0 0.000
#> GSM782723     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782725     4  0.0000     0.9349 0.000  0  0 1.000  0 0.000
#> GSM782726     6  0.0260     0.5029 0.008  0  0 0.000  0 0.992
#> GSM782727     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782729     4  0.0000     0.9349 0.000  0  0 1.000  0 0.000
#> GSM782730     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782731     1  0.3672     0.5482 0.688  0  0 0.008  0 0.304
#> GSM782732     1  0.3672     0.5482 0.688  0  0 0.008  0 0.304
#> GSM782733     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782734     1  0.3619     0.5340 0.680  0  0 0.004  0 0.316
#> GSM782735     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782736     1  0.3774     0.5740 0.664  0  0 0.328  0 0.008
#> GSM782737     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782738     1  0.3774     0.5740 0.664  0  0 0.328  0 0.008
#> GSM782739     1  0.3619     0.5340 0.680  0  0 0.004  0 0.316
#> GSM782740     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000
#> GSM782741     1  0.3619     0.5340 0.680  0  0 0.004  0 0.316
#> GSM782742     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782743     3  0.0000     1.0000 0.000  0  1 0.000  0 0.000
#> GSM782744     5  0.0000     0.0000 0.000  0  0 0.000  1 0.000
#> GSM782745     6  0.0260     0.5029 0.008  0  0 0.000  0 0.992
#> GSM782746     2  0.0000     1.0000 0.000  1  0 0.000  0 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-hclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-MAD-hclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-MAD-hclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-MAD-hclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-MAD-hclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-hclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-MAD-hclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-MAD-hclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-MAD-hclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-MAD-hclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-hclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-MAD-hclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-MAD-hclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-MAD-hclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-MAD-hclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-hclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-MAD-hclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-MAD-hclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-MAD-hclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-MAD-hclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-hclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-MAD-hclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-MAD-hclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-MAD-hclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-MAD-hclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> MAD:hclust 51    0.648 2
#> MAD:hclust 51    0.642 3
#> MAD:hclust 50    0.833 4
#> MAD:hclust 49    0.632 5
#> MAD:hclust 49    0.632 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:kmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "kmeans"]
# you can also extract it by
# res = res_list["MAD:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.421           0.676       0.802         0.3855 0.633   0.633
#> 3 3 1.000           0.977       0.943         0.4650 0.788   0.665
#> 4 4 0.708           0.356       0.785         0.2186 0.977   0.946
#> 5 5 0.681           0.760       0.768         0.0887 0.776   0.450
#> 6 6 0.689           0.811       0.801         0.0623 0.961   0.817

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.925     0.7690 0.660 0.340
#> GSM782697     1   0.925     0.7690 0.660 0.340
#> GSM782698     1   0.925     0.7690 0.660 0.340
#> GSM782699     1   0.925     0.7690 0.660 0.340
#> GSM782700     1   0.913    -0.0649 0.672 0.328
#> GSM782701     1   0.925     0.7690 0.660 0.340
#> GSM782702     1   0.925     0.7690 0.660 0.340
#> GSM782703     2   0.000     1.0000 0.000 1.000
#> GSM782704     2   0.000     1.0000 0.000 1.000
#> GSM782705     1   0.925     0.7690 0.660 0.340
#> GSM782706     1   0.925     0.7690 0.660 0.340
#> GSM782707     1   0.925     0.7690 0.660 0.340
#> GSM782708     2   0.000     1.0000 0.000 1.000
#> GSM782709     1   0.925     0.7690 0.660 0.340
#> GSM782710     1   0.925     0.7690 0.660 0.340
#> GSM782711     1   0.925     0.7690 0.660 0.340
#> GSM782712     1   0.925     0.7690 0.660 0.340
#> GSM782713     2   0.000     1.0000 0.000 1.000
#> GSM782714     1   0.913    -0.0649 0.672 0.328
#> GSM782715     1   0.925     0.7690 0.660 0.340
#> GSM782716     2   0.000     1.0000 0.000 1.000
#> GSM782717     1   0.925     0.7690 0.660 0.340
#> GSM782718     1   0.925     0.7690 0.660 0.340
#> GSM782719     1   0.925     0.7690 0.660 0.340
#> GSM782720     2   0.000     1.0000 0.000 1.000
#> GSM782721     1   0.925     0.7690 0.660 0.340
#> GSM782722     1   0.925     0.7690 0.660 0.340
#> GSM782723     1   0.913    -0.0649 0.672 0.328
#> GSM782724     1   0.913    -0.0649 0.672 0.328
#> GSM782725     1   0.925     0.7690 0.660 0.340
#> GSM782726     1   0.925     0.7690 0.660 0.340
#> GSM782727     2   0.000     1.0000 0.000 1.000
#> GSM782728     1   0.913    -0.0649 0.672 0.328
#> GSM782729     1   0.925     0.7690 0.660 0.340
#> GSM782730     2   0.000     1.0000 0.000 1.000
#> GSM782731     1   0.925     0.7690 0.660 0.340
#> GSM782732     1   0.925     0.7690 0.660 0.340
#> GSM782733     2   0.000     1.0000 0.000 1.000
#> GSM782734     1   0.925     0.7690 0.660 0.340
#> GSM782735     1   0.913    -0.0649 0.672 0.328
#> GSM782736     1   0.925     0.7690 0.660 0.340
#> GSM782737     1   0.913    -0.0649 0.672 0.328
#> GSM782738     1   0.925     0.7690 0.660 0.340
#> GSM782739     1   0.925     0.7690 0.660 0.340
#> GSM782740     1   0.913    -0.0649 0.672 0.328
#> GSM782741     1   0.925     0.7690 0.660 0.340
#> GSM782742     2   0.000     1.0000 0.000 1.000
#> GSM782743     2   0.000     1.0000 0.000 1.000
#> GSM782744     2   0.000     1.0000 0.000 1.000
#> GSM782745     1   0.925     0.7690 0.660 0.340
#> GSM782746     1   0.913    -0.0649 0.672 0.328

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1  0.1289      0.975 0.968 0.032 0.000
#> GSM782697     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782698     1  0.1753      0.972 0.952 0.048 0.000
#> GSM782699     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782700     2  0.4007      0.990 0.036 0.880 0.084
#> GSM782701     1  0.1289      0.975 0.968 0.032 0.000
#> GSM782702     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782703     3  0.1860      0.985 0.052 0.000 0.948
#> GSM782704     3  0.3253      0.982 0.052 0.036 0.912
#> GSM782705     1  0.0424      0.977 0.992 0.008 0.000
#> GSM782706     1  0.1529      0.973 0.960 0.040 0.000
#> GSM782707     1  0.1289      0.975 0.968 0.032 0.000
#> GSM782708     3  0.3253      0.982 0.052 0.036 0.912
#> GSM782709     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782710     1  0.0237      0.976 0.996 0.004 0.000
#> GSM782711     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782712     1  0.0592      0.976 0.988 0.012 0.000
#> GSM782713     3  0.1860      0.985 0.052 0.000 0.948
#> GSM782714     2  0.4174      0.989 0.036 0.872 0.092
#> GSM782715     1  0.2261      0.960 0.932 0.068 0.000
#> GSM782716     3  0.3253      0.982 0.052 0.036 0.912
#> GSM782717     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782718     1  0.2261      0.960 0.932 0.068 0.000
#> GSM782719     1  0.1289      0.975 0.968 0.032 0.000
#> GSM782720     3  0.1860      0.985 0.052 0.000 0.948
#> GSM782721     1  0.1529      0.973 0.960 0.040 0.000
#> GSM782722     1  0.2356      0.959 0.928 0.072 0.000
#> GSM782723     2  0.4489      0.985 0.036 0.856 0.108
#> GSM782724     2  0.4489      0.985 0.036 0.856 0.108
#> GSM782725     1  0.2356      0.960 0.928 0.072 0.000
#> GSM782726     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782727     3  0.1860      0.985 0.052 0.000 0.948
#> GSM782728     2  0.4007      0.990 0.036 0.880 0.084
#> GSM782729     1  0.2356      0.960 0.928 0.072 0.000
#> GSM782730     3  0.1860      0.985 0.052 0.000 0.948
#> GSM782731     1  0.0892      0.974 0.980 0.020 0.000
#> GSM782732     1  0.0892      0.974 0.980 0.020 0.000
#> GSM782733     3  0.3253      0.982 0.052 0.036 0.912
#> GSM782734     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782735     2  0.4563      0.980 0.036 0.852 0.112
#> GSM782736     1  0.2356      0.959 0.928 0.072 0.000
#> GSM782737     2  0.4174      0.989 0.036 0.872 0.092
#> GSM782738     1  0.2261      0.960 0.932 0.068 0.000
#> GSM782739     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782740     2  0.4007      0.990 0.036 0.880 0.084
#> GSM782741     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782742     3  0.1860      0.985 0.052 0.000 0.948
#> GSM782743     3  0.3253      0.982 0.052 0.036 0.912
#> GSM782744     3  0.2599      0.981 0.052 0.016 0.932
#> GSM782745     1  0.0424      0.976 0.992 0.008 0.000
#> GSM782746     2  0.4563      0.980 0.036 0.852 0.112

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1    p2    p3    p4
#> GSM782696     1  0.4925    -0.6920 0.572 0.000 0.000 0.428
#> GSM782697     1  0.4134    -0.1144 0.740 0.000 0.000 0.260
#> GSM782698     4  0.5000     0.0000 0.496 0.000 0.000 0.504
#> GSM782699     1  0.4134    -0.1144 0.740 0.000 0.000 0.260
#> GSM782700     2  0.1109     0.9744 0.000 0.968 0.028 0.004
#> GSM782701     1  0.5088    -0.6940 0.572 0.004 0.000 0.424
#> GSM782702     1  0.4134    -0.1144 0.740 0.000 0.000 0.260
#> GSM782703     3  0.0469     0.9434 0.012 0.000 0.988 0.000
#> GSM782704     3  0.3324     0.9324 0.012 0.000 0.852 0.136
#> GSM782705     1  0.2647     0.2515 0.880 0.000 0.000 0.120
#> GSM782706     1  0.5257    -0.7666 0.548 0.008 0.000 0.444
#> GSM782707     1  0.4925    -0.6920 0.572 0.000 0.000 0.428
#> GSM782708     3  0.3324     0.9324 0.012 0.000 0.852 0.136
#> GSM782709     1  0.4134    -0.1144 0.740 0.000 0.000 0.260
#> GSM782710     1  0.2216     0.2264 0.908 0.000 0.000 0.092
#> GSM782711     1  0.4331    -0.2027 0.712 0.000 0.000 0.288
#> GSM782712     1  0.4500    -0.2981 0.684 0.000 0.000 0.316
#> GSM782713     3  0.0469     0.9434 0.012 0.000 0.988 0.000
#> GSM782714     2  0.1256     0.9742 0.000 0.964 0.028 0.008
#> GSM782715     1  0.5526     0.0573 0.564 0.020 0.000 0.416
#> GSM782716     3  0.3324     0.9324 0.012 0.000 0.852 0.136
#> GSM782717     1  0.0000     0.3265 1.000 0.000 0.000 0.000
#> GSM782718     1  0.5452     0.0276 0.556 0.016 0.000 0.428
#> GSM782719     1  0.5088    -0.6940 0.572 0.004 0.000 0.424
#> GSM782720     3  0.0469     0.9434 0.012 0.000 0.988 0.000
#> GSM782721     1  0.5257    -0.7666 0.548 0.008 0.000 0.444
#> GSM782722     1  0.5643     0.0557 0.548 0.024 0.000 0.428
#> GSM782723     2  0.2623     0.9568 0.000 0.908 0.028 0.064
#> GSM782724     2  0.2845     0.9536 0.000 0.896 0.028 0.076
#> GSM782725     1  0.5510     0.1105 0.600 0.024 0.000 0.376
#> GSM782726     1  0.0817     0.3242 0.976 0.000 0.000 0.024
#> GSM782727     3  0.0469     0.9434 0.012 0.000 0.988 0.000
#> GSM782728     2  0.0921     0.9743 0.000 0.972 0.028 0.000
#> GSM782729     1  0.5510     0.1105 0.600 0.024 0.000 0.376
#> GSM782730     3  0.0469     0.9434 0.012 0.000 0.988 0.000
#> GSM782731     1  0.1867     0.3052 0.928 0.000 0.000 0.072
#> GSM782732     1  0.1867     0.3052 0.928 0.000 0.000 0.072
#> GSM782733     3  0.3324     0.9324 0.012 0.000 0.852 0.136
#> GSM782734     1  0.0336     0.3272 0.992 0.000 0.000 0.008
#> GSM782735     2  0.2830     0.9510 0.000 0.900 0.040 0.060
#> GSM782736     1  0.5517     0.0626 0.568 0.020 0.000 0.412
#> GSM782737     2  0.1256     0.9742 0.000 0.964 0.028 0.008
#> GSM782738     1  0.5517     0.0562 0.568 0.020 0.000 0.412
#> GSM782739     1  0.0000     0.3265 1.000 0.000 0.000 0.000
#> GSM782740     2  0.0921     0.9743 0.000 0.972 0.028 0.000
#> GSM782741     1  0.0000     0.3265 1.000 0.000 0.000 0.000
#> GSM782742     3  0.0469     0.9434 0.012 0.000 0.988 0.000
#> GSM782743     3  0.3324     0.9324 0.012 0.000 0.852 0.136
#> GSM782744     3  0.3427     0.9106 0.028 0.000 0.860 0.112
#> GSM782745     1  0.0817     0.3242 0.976 0.000 0.000 0.024
#> GSM782746     2  0.2830     0.9510 0.000 0.900 0.040 0.060

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1    p2    p3    p4    p5
#> GSM782696     1  0.3661      0.836 0.724 0.000 0.000 0.276 0.000
#> GSM782697     1  0.4251      0.771 0.756 0.004 0.000 0.200 0.040
#> GSM782698     1  0.4118      0.776 0.660 0.004 0.000 0.336 0.000
#> GSM782699     1  0.4251      0.771 0.756 0.004 0.000 0.200 0.040
#> GSM782700     2  0.0510      0.950 0.000 0.984 0.016 0.000 0.000
#> GSM782701     1  0.4656      0.834 0.692 0.004 0.000 0.268 0.036
#> GSM782702     1  0.4400      0.750 0.744 0.000 0.000 0.196 0.060
#> GSM782703     3  0.0162      0.898 0.000 0.000 0.996 0.004 0.000
#> GSM782704     3  0.3521      0.879 0.000 0.000 0.764 0.004 0.232
#> GSM782705     4  0.5635     -0.181 0.428 0.000 0.000 0.496 0.076
#> GSM782706     1  0.5256      0.738 0.592 0.004 0.000 0.356 0.048
#> GSM782707     1  0.4581      0.835 0.696 0.004 0.000 0.268 0.032
#> GSM782708     3  0.3521      0.879 0.000 0.000 0.764 0.004 0.232
#> GSM782709     1  0.4540      0.743 0.748 0.004 0.000 0.180 0.068
#> GSM782710     5  0.6739      0.783 0.336 0.000 0.000 0.264 0.400
#> GSM782711     1  0.3074      0.809 0.804 0.000 0.000 0.196 0.000
#> GSM782712     1  0.4335      0.829 0.740 0.004 0.000 0.220 0.036
#> GSM782713     3  0.0162      0.898 0.000 0.000 0.996 0.004 0.000
#> GSM782714     2  0.1179      0.949 0.004 0.964 0.016 0.000 0.016
#> GSM782715     4  0.2067      0.662 0.048 0.000 0.000 0.920 0.032
#> GSM782716     3  0.3521      0.879 0.000 0.000 0.764 0.004 0.232
#> GSM782717     5  0.6721      0.926 0.252 0.000 0.000 0.352 0.396
#> GSM782718     4  0.2020      0.635 0.100 0.000 0.000 0.900 0.000
#> GSM782719     1  0.4656      0.834 0.692 0.004 0.000 0.268 0.036
#> GSM782720     3  0.0162      0.898 0.000 0.000 0.996 0.004 0.000
#> GSM782721     1  0.5256      0.738 0.592 0.004 0.000 0.356 0.048
#> GSM782722     4  0.2011      0.637 0.020 0.008 0.000 0.928 0.044
#> GSM782723     2  0.2857      0.926 0.028 0.888 0.020 0.000 0.064
#> GSM782724     2  0.3423      0.917 0.068 0.856 0.016 0.000 0.060
#> GSM782725     4  0.2204      0.642 0.036 0.008 0.000 0.920 0.036
#> GSM782726     5  0.6597      0.890 0.224 0.000 0.000 0.332 0.444
#> GSM782727     3  0.0162      0.898 0.000 0.000 0.996 0.004 0.000
#> GSM782728     2  0.0510      0.950 0.000 0.984 0.016 0.000 0.000
#> GSM782729     4  0.2122      0.643 0.036 0.008 0.000 0.924 0.032
#> GSM782730     3  0.0162      0.898 0.000 0.000 0.996 0.004 0.000
#> GSM782731     4  0.6337     -0.541 0.192 0.000 0.000 0.512 0.296
#> GSM782732     4  0.6337     -0.541 0.192 0.000 0.000 0.512 0.296
#> GSM782733     3  0.3521      0.879 0.000 0.000 0.764 0.004 0.232
#> GSM782734     5  0.6718      0.925 0.252 0.000 0.000 0.348 0.400
#> GSM782735     2  0.3783      0.891 0.040 0.824 0.016 0.000 0.120
#> GSM782736     4  0.1386      0.666 0.032 0.000 0.000 0.952 0.016
#> GSM782737     2  0.1179      0.949 0.004 0.964 0.016 0.000 0.016
#> GSM782738     4  0.2046      0.655 0.068 0.000 0.000 0.916 0.016
#> GSM782739     5  0.6721      0.926 0.252 0.000 0.000 0.352 0.396
#> GSM782740     2  0.0510      0.950 0.000 0.984 0.016 0.000 0.000
#> GSM782741     5  0.6721      0.926 0.252 0.000 0.000 0.352 0.396
#> GSM782742     3  0.0162      0.898 0.000 0.000 0.996 0.004 0.000
#> GSM782743     3  0.3521      0.879 0.000 0.000 0.764 0.004 0.232
#> GSM782744     3  0.4621      0.818 0.076 0.000 0.744 0.004 0.176
#> GSM782745     5  0.6597      0.890 0.224 0.000 0.000 0.332 0.444
#> GSM782746     2  0.3783      0.891 0.040 0.824 0.016 0.000 0.120

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4 p5    p6
#> GSM782696     1  0.3837      0.785 0.752 0.000 0.000 0.052 NA 0.196
#> GSM782697     1  0.3933      0.741 0.676 0.000 0.000 0.008 NA 0.308
#> GSM782698     1  0.4371      0.721 0.740 0.000 0.000 0.132 NA 0.120
#> GSM782699     1  0.3933      0.741 0.676 0.000 0.000 0.008 NA 0.308
#> GSM782700     2  0.0458      0.923 0.016 0.984 0.000 0.000 NA 0.000
#> GSM782701     1  0.5866      0.774 0.612 0.000 0.000 0.056 NA 0.200
#> GSM782702     1  0.3728      0.732 0.652 0.000 0.000 0.004 NA 0.344
#> GSM782703     3  0.0692      0.821 0.020 0.000 0.976 0.000 NA 0.004
#> GSM782704     3  0.4265      0.787 0.016 0.000 0.596 0.000 NA 0.004
#> GSM782705     1  0.5820      0.201 0.416 0.000 0.000 0.184 NA 0.400
#> GSM782706     1  0.7155      0.658 0.456 0.000 0.000 0.160 NA 0.216
#> GSM782707     1  0.5806      0.777 0.620 0.000 0.000 0.056 NA 0.196
#> GSM782708     3  0.3890      0.786 0.000 0.000 0.596 0.000 NA 0.004
#> GSM782709     1  0.3925      0.731 0.656 0.000 0.000 0.004 NA 0.332
#> GSM782710     6  0.1716      0.863 0.036 0.000 0.000 0.004 NA 0.932
#> GSM782711     1  0.3380      0.776 0.748 0.000 0.000 0.004 NA 0.244
#> GSM782712     1  0.5495      0.769 0.600 0.000 0.000 0.016 NA 0.256
#> GSM782713     3  0.0508      0.821 0.012 0.000 0.984 0.000 NA 0.004
#> GSM782714     2  0.0603      0.924 0.004 0.980 0.000 0.000 NA 0.000
#> GSM782715     4  0.4025      0.897 0.052 0.000 0.000 0.760 NA 0.176
#> GSM782716     3  0.3890      0.786 0.000 0.000 0.596 0.000 NA 0.004
#> GSM782717     6  0.0508      0.902 0.004 0.000 0.000 0.012 NA 0.984
#> GSM782718     4  0.4054      0.874 0.072 0.000 0.000 0.740 NA 0.188
#> GSM782719     1  0.5787      0.776 0.620 0.000 0.000 0.052 NA 0.196
#> GSM782720     3  0.0146      0.822 0.000 0.000 0.996 0.000 NA 0.004
#> GSM782721     1  0.7155      0.658 0.456 0.000 0.000 0.160 NA 0.216
#> GSM782722     4  0.4052      0.876 0.036 0.000 0.000 0.788 NA 0.116
#> GSM782723     2  0.2841      0.892 0.028 0.872 0.000 0.028 NA 0.000
#> GSM782724     2  0.3775      0.872 0.048 0.816 0.000 0.060 NA 0.000
#> GSM782725     4  0.3971      0.876 0.012 0.000 0.000 0.772 NA 0.156
#> GSM782726     6  0.1075      0.888 0.000 0.000 0.000 0.000 NA 0.952
#> GSM782727     3  0.0291      0.821 0.004 0.000 0.992 0.000 NA 0.004
#> GSM782728     2  0.0000      0.924 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782729     4  0.4017      0.880 0.012 0.000 0.000 0.764 NA 0.168
#> GSM782730     3  0.0291      0.822 0.000 0.000 0.992 0.004 NA 0.004
#> GSM782731     6  0.2871      0.706 0.004 0.000 0.000 0.192 NA 0.804
#> GSM782732     6  0.2871      0.706 0.004 0.000 0.000 0.192 NA 0.804
#> GSM782733     3  0.3890      0.786 0.000 0.000 0.596 0.000 NA 0.004
#> GSM782734     6  0.0951      0.899 0.004 0.000 0.000 0.008 NA 0.968
#> GSM782735     2  0.3991      0.831 0.044 0.764 0.000 0.016 NA 0.000
#> GSM782736     4  0.3440      0.899 0.028 0.000 0.000 0.776 NA 0.196
#> GSM782737     2  0.0748      0.924 0.004 0.976 0.004 0.000 NA 0.000
#> GSM782738     4  0.3683      0.896 0.044 0.000 0.000 0.764 NA 0.192
#> GSM782739     6  0.0508      0.902 0.004 0.000 0.000 0.012 NA 0.984
#> GSM782740     2  0.0000      0.924 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782741     6  0.0508      0.902 0.004 0.000 0.000 0.012 NA 0.984
#> GSM782742     3  0.0146      0.822 0.000 0.000 0.996 0.000 NA 0.004
#> GSM782743     3  0.4015      0.786 0.000 0.000 0.596 0.004 NA 0.004
#> GSM782744     3  0.5606      0.746 0.076 0.000 0.664 0.052 NA 0.016
#> GSM782745     6  0.1075      0.888 0.000 0.000 0.000 0.000 NA 0.952
#> GSM782746     2  0.3991      0.831 0.044 0.764 0.000 0.016 NA 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-kmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-MAD-kmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-MAD-kmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-MAD-kmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-MAD-kmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-kmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-MAD-kmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-MAD-kmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-MAD-kmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-MAD-kmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-kmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-MAD-kmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-MAD-kmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-MAD-kmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-MAD-kmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-kmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-MAD-kmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-MAD-kmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-MAD-kmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-MAD-kmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-kmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-MAD-kmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-MAD-kmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-MAD-kmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-MAD-kmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> MAD:kmeans 42    0.557 2
#> MAD:kmeans 51    0.642 3
#> MAD:kmeans 21    0.529 4
#> MAD:kmeans 48    0.520 5
#> MAD:kmeans 50    0.494 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:skmeans**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "skmeans"]
# you can also extract it by
# res = res_list["MAD:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.4946 0.506   0.506
#> 3 3 1.000           0.999       0.999         0.1715 0.915   0.833
#> 4 4 0.860           0.905       0.933         0.2909 0.824   0.583
#> 5 5 0.969           0.939       0.968         0.0766 0.938   0.752
#> 6 6 0.869           0.772       0.839         0.0298 0.967   0.829

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 2 3

There is also optional best \(k\) = 2 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     2       0          1  0  1
#> GSM782704     2       0          1  0  1
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     2       0          1  0  1
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     2       0          1  0  1
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     2       0          1  0  1
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     2       0          1  0  1
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     2       0          1  0  1
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     2       0          1  0  1
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     2       0          1  0  1
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     2       0          1  0  1
#> GSM782743     2       0          1  0  1
#> GSM782744     2       0          1  0  1
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782697     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782698     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782699     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782700     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782701     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782702     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782703     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782704     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782705     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782706     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782707     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782708     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782709     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782710     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782711     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782712     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782713     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782714     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782715     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782716     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782717     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782718     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782719     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782720     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782721     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782722     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782723     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782724     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782725     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782726     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782727     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782728     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782729     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782730     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782731     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782732     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782733     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782734     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782735     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782736     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782737     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782738     1  0.0000      0.999 1.000 0.000 0.000
#> GSM782739     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782740     2  0.0237      1.000 0.000 0.996 0.004
#> GSM782741     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782742     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782743     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782744     3  0.0000      1.000 0.000 0.000 1.000
#> GSM782745     1  0.0237      0.997 0.996 0.004 0.000
#> GSM782746     2  0.0237      1.000 0.000 0.996 0.004

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.0188      0.932 0.996  0 0.000 0.004
#> GSM782697     1  0.2081      0.891 0.916  0 0.000 0.084
#> GSM782698     1  0.1389      0.887 0.952  0 0.000 0.048
#> GSM782699     1  0.1211      0.923 0.960  0 0.000 0.040
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.0000      0.934 1.000  0 0.000 0.000
#> GSM782702     1  0.1940      0.897 0.924  0 0.000 0.076
#> GSM782703     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782704     3  0.0188      0.998 0.000  0 0.996 0.004
#> GSM782705     4  0.4543      0.742 0.324  0 0.000 0.676
#> GSM782706     1  0.0188      0.933 0.996  0 0.000 0.004
#> GSM782707     1  0.0188      0.932 0.996  0 0.000 0.004
#> GSM782708     3  0.0188      0.998 0.000  0 0.996 0.004
#> GSM782709     1  0.2814      0.843 0.868  0 0.000 0.132
#> GSM782710     1  0.4277      0.638 0.720  0 0.000 0.280
#> GSM782711     1  0.0469      0.932 0.988  0 0.000 0.012
#> GSM782712     1  0.0000      0.934 1.000  0 0.000 0.000
#> GSM782713     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     4  0.4382      0.776 0.296  0 0.000 0.704
#> GSM782716     3  0.0188      0.998 0.000  0 0.996 0.004
#> GSM782717     4  0.1557      0.803 0.056  0 0.000 0.944
#> GSM782718     4  0.4454      0.764 0.308  0 0.000 0.692
#> GSM782719     1  0.0000      0.934 1.000  0 0.000 0.000
#> GSM782720     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782721     1  0.0188      0.933 0.996  0 0.000 0.004
#> GSM782722     4  0.4304      0.785 0.284  0 0.000 0.716
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     4  0.4250      0.790 0.276  0 0.000 0.724
#> GSM782726     4  0.1474      0.799 0.052  0 0.000 0.948
#> GSM782727     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     4  0.4250      0.790 0.276  0 0.000 0.724
#> GSM782730     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782731     4  0.0817      0.804 0.024  0 0.000 0.976
#> GSM782732     4  0.1022      0.806 0.032  0 0.000 0.968
#> GSM782733     3  0.0188      0.998 0.000  0 0.996 0.004
#> GSM782734     4  0.1474      0.799 0.052  0 0.000 0.948
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     4  0.4277      0.788 0.280  0 0.000 0.720
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     4  0.4356      0.780 0.292  0 0.000 0.708
#> GSM782739     4  0.1389      0.802 0.048  0 0.000 0.952
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     4  0.1557      0.801 0.056  0 0.000 0.944
#> GSM782742     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782743     3  0.0188      0.998 0.000  0 0.996 0.004
#> GSM782744     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782745     4  0.1474      0.799 0.052  0 0.000 0.948
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2 p3    p4    p5
#> GSM782696     1  0.0290      0.986 0.992  0  0 0.008 0.000
#> GSM782697     1  0.0404      0.982 0.988  0  0 0.000 0.012
#> GSM782698     1  0.0566      0.980 0.984  0  0 0.012 0.004
#> GSM782699     1  0.0324      0.983 0.992  0  0 0.004 0.004
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782701     1  0.0566      0.987 0.984  0  0 0.012 0.004
#> GSM782702     1  0.0771      0.978 0.976  0  0 0.004 0.020
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782705     4  0.2597      0.824 0.092  0  0 0.884 0.024
#> GSM782706     1  0.0671      0.985 0.980  0  0 0.016 0.004
#> GSM782707     1  0.0566      0.987 0.984  0  0 0.012 0.004
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782709     1  0.0963      0.965 0.964  0  0 0.000 0.036
#> GSM782710     5  0.2377      0.811 0.128  0  0 0.000 0.872
#> GSM782711     1  0.0000      0.984 1.000  0  0 0.000 0.000
#> GSM782712     1  0.0566      0.987 0.984  0  0 0.012 0.004
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782715     4  0.0566      0.885 0.012  0  0 0.984 0.004
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782717     5  0.2377      0.854 0.000  0  0 0.128 0.872
#> GSM782718     4  0.1205      0.871 0.040  0  0 0.956 0.004
#> GSM782719     1  0.0566      0.987 0.984  0  0 0.012 0.004
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782721     1  0.0798      0.984 0.976  0  0 0.016 0.008
#> GSM782722     4  0.0000      0.885 0.000  0  0 1.000 0.000
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782725     4  0.0162      0.885 0.000  0  0 0.996 0.004
#> GSM782726     5  0.0290      0.919 0.000  0  0 0.008 0.992
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782729     4  0.0162      0.885 0.000  0  0 0.996 0.004
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782731     4  0.4161      0.392 0.000  0  0 0.608 0.392
#> GSM782732     4  0.3966      0.517 0.000  0  0 0.664 0.336
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782734     5  0.0404      0.919 0.000  0  0 0.012 0.988
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782736     4  0.0162      0.885 0.000  0  0 0.996 0.004
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782738     4  0.0798      0.884 0.016  0  0 0.976 0.008
#> GSM782739     5  0.2329      0.858 0.000  0  0 0.124 0.876
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000 0.000
#> GSM782741     5  0.1485      0.914 0.020  0  0 0.032 0.948
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000 0.000
#> GSM782745     5  0.0290      0.919 0.000  0  0 0.008 0.992
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1  0.3810     -0.550 0.572  0 0.000 0.000 0.428 0.000
#> GSM782697     1  0.0551      0.635 0.984  0 0.000 0.004 0.008 0.004
#> GSM782698     1  0.0717      0.643 0.976  0 0.000 0.008 0.016 0.000
#> GSM782699     1  0.0146      0.642 0.996  0 0.000 0.004 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     5  0.3847      0.778 0.456  0 0.000 0.000 0.544 0.000
#> GSM782702     1  0.3827      0.139 0.680  0 0.000 0.004 0.308 0.008
#> GSM782703     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782704     3  0.0146      0.998 0.000  0 0.996 0.000 0.004 0.000
#> GSM782705     4  0.4165      0.656 0.172  0 0.000 0.756 0.052 0.020
#> GSM782706     5  0.4316      0.709 0.312  0 0.000 0.040 0.648 0.000
#> GSM782707     5  0.3866      0.739 0.484  0 0.000 0.000 0.516 0.000
#> GSM782708     3  0.0146      0.998 0.000  0 0.996 0.000 0.004 0.000
#> GSM782709     1  0.2333      0.607 0.884  0 0.000 0.000 0.092 0.024
#> GSM782710     6  0.4451      0.616 0.148  0 0.000 0.004 0.124 0.724
#> GSM782711     1  0.3288      0.196 0.724  0 0.000 0.000 0.276 0.000
#> GSM782712     5  0.3797      0.785 0.420  0 0.000 0.000 0.580 0.000
#> GSM782713     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     4  0.1556      0.770 0.000  0 0.000 0.920 0.080 0.000
#> GSM782716     3  0.0146      0.998 0.000  0 0.996 0.000 0.004 0.000
#> GSM782717     6  0.4412      0.650 0.008  0 0.000 0.236 0.056 0.700
#> GSM782718     4  0.1745      0.768 0.020  0 0.000 0.924 0.056 0.000
#> GSM782719     5  0.3866      0.735 0.484  0 0.000 0.000 0.516 0.000
#> GSM782720     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782721     5  0.4316      0.709 0.312  0 0.000 0.040 0.648 0.000
#> GSM782722     4  0.2912      0.724 0.000  0 0.000 0.784 0.216 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     4  0.3076      0.712 0.000  0 0.000 0.760 0.240 0.000
#> GSM782726     6  0.1007      0.768 0.000  0 0.000 0.000 0.044 0.956
#> GSM782727     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     4  0.3076      0.712 0.000  0 0.000 0.760 0.240 0.000
#> GSM782730     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782731     4  0.4278      0.381 0.000  0 0.000 0.632 0.032 0.336
#> GSM782732     4  0.4152      0.448 0.000  0 0.000 0.664 0.032 0.304
#> GSM782733     3  0.0146      0.998 0.000  0 0.996 0.000 0.004 0.000
#> GSM782734     6  0.1572      0.774 0.000  0 0.000 0.036 0.028 0.936
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     4  0.0146      0.771 0.000  0 0.000 0.996 0.004 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     4  0.1411      0.771 0.004  0 0.000 0.936 0.060 0.000
#> GSM782739     6  0.4520      0.627 0.012  0 0.000 0.248 0.052 0.688
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     6  0.4871      0.685 0.008  0 0.000 0.112 0.204 0.676
#> GSM782742     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782743     3  0.0146      0.998 0.000  0 0.996 0.000 0.004 0.000
#> GSM782744     3  0.0000      0.998 0.000  0 1.000 0.000 0.000 0.000
#> GSM782745     6  0.1007      0.768 0.000  0 0.000 0.000 0.044 0.956
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-skmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-MAD-skmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-MAD-skmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-MAD-skmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-MAD-skmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-skmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-MAD-skmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-MAD-skmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-MAD-skmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-MAD-skmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-skmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-MAD-skmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-MAD-skmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-MAD-skmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-MAD-skmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-skmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-MAD-skmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-MAD-skmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-MAD-skmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-MAD-skmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-skmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-MAD-skmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-MAD-skmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-MAD-skmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-MAD-skmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) k
#> MAD:skmeans 51    0.493 2
#> MAD:skmeans 51    0.642 3
#> MAD:skmeans 51    0.544 4
#> MAD:skmeans 50    0.538 5
#> MAD:skmeans 46    0.403 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:pam*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "pam"]
# you can also extract it by
# res = res_list["MAD:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 5.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.956           0.939       0.975         0.2997 0.824   0.583
#> 5 5 0.924           0.921       0.962         0.0371 0.973   0.888
#> 6 6 0.877           0.771       0.927         0.0244 0.990   0.953

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 5
#> attr(,"optional")
#> [1] 2 3 4

There is also optional best \(k\) = 2 3 4 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782697     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782698     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782699     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782701     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782702     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782705     4  0.2345      0.855 0.100  0  0 0.900
#> GSM782706     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782707     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782709     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782710     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782711     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782712     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782715     1  0.1118      0.936 0.964  0  0 0.036
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782717     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782718     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782719     1  0.0000      0.966 1.000  0  0 0.000
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782721     1  0.2216      0.878 0.908  0  0 0.092
#> GSM782722     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782725     4  0.0188      0.929 0.004  0  0 0.996
#> GSM782726     4  0.4955      0.193 0.444  0  0 0.556
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782729     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782731     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782732     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782734     4  0.2704      0.842 0.124  0  0 0.876
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782736     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782738     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782739     4  0.0000      0.931 0.000  0  0 1.000
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782741     1  0.4624      0.456 0.660  0  0 0.340
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782745     4  0.2530      0.854 0.112  0  0 0.888
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782697     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782698     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782699     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782702     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782703     3  0.3424      0.676 0.000  0 0.760 0.000 0.240
#> GSM782704     3  0.0290      0.953 0.000  0 0.992 0.000 0.008
#> GSM782705     4  0.2074      0.842 0.104  0 0.000 0.896 0.000
#> GSM782706     1  0.0693      0.951 0.980  0 0.000 0.008 0.012
#> GSM782707     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782708     3  0.0000      0.955 0.000  0 1.000 0.000 0.000
#> GSM782709     1  0.0290      0.957 0.992  0 0.000 0.008 0.000
#> GSM782710     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782711     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782712     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782713     5  0.0880      1.000 0.000  0 0.032 0.000 0.968
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     1  0.1281      0.931 0.956  0 0.000 0.032 0.012
#> GSM782716     3  0.0000      0.955 0.000  0 1.000 0.000 0.000
#> GSM782717     4  0.0000      0.914 0.000  0 0.000 1.000 0.000
#> GSM782718     4  0.0404      0.914 0.000  0 0.000 0.988 0.012
#> GSM782719     1  0.0000      0.962 1.000  0 0.000 0.000 0.000
#> GSM782720     5  0.0880      1.000 0.000  0 0.032 0.000 0.968
#> GSM782721     1  0.2248      0.876 0.900  0 0.000 0.088 0.012
#> GSM782722     4  0.0880      0.910 0.000  0 0.000 0.968 0.032
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.1041      0.909 0.004  0 0.000 0.964 0.032
#> GSM782726     4  0.4268      0.181 0.444  0 0.000 0.556 0.000
#> GSM782727     5  0.0880      1.000 0.000  0 0.032 0.000 0.968
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.1012      0.910 0.012  0 0.000 0.968 0.020
#> GSM782730     5  0.0880      1.000 0.000  0 0.032 0.000 0.968
#> GSM782731     4  0.0000      0.914 0.000  0 0.000 1.000 0.000
#> GSM782732     4  0.0000      0.914 0.000  0 0.000 1.000 0.000
#> GSM782733     3  0.0000      0.955 0.000  0 1.000 0.000 0.000
#> GSM782734     4  0.2329      0.824 0.124  0 0.000 0.876 0.000
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.0510      0.914 0.000  0 0.000 0.984 0.016
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     4  0.0693      0.914 0.008  0 0.000 0.980 0.012
#> GSM782739     4  0.0000      0.914 0.000  0 0.000 1.000 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.3983      0.469 0.660  0 0.000 0.340 0.000
#> GSM782742     5  0.0880      1.000 0.000  0 0.032 0.000 0.968
#> GSM782743     3  0.0000      0.955 0.000  0 1.000 0.000 0.000
#> GSM782744     3  0.0290      0.953 0.000  0 0.992 0.000 0.008
#> GSM782745     4  0.2179      0.836 0.112  0 0.000 0.888 0.000
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1   p2    p3    p4    p5    p6
#> GSM782696     1  0.0146     0.9431 0.996 0.00 0.000 0.004 0.000 0.000
#> GSM782697     1  0.0000     0.9433 1.000 0.00 0.000 0.000 0.000 0.000
#> GSM782698     1  0.0146     0.9431 0.996 0.00 0.000 0.004 0.000 0.000
#> GSM782699     1  0.0146     0.9431 0.996 0.00 0.000 0.004 0.000 0.000
#> GSM782700     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782701     1  0.0000     0.9433 1.000 0.00 0.000 0.000 0.000 0.000
#> GSM782702     1  0.0000     0.9433 1.000 0.00 0.000 0.000 0.000 0.000
#> GSM782703     3  0.3266     0.6136 0.000 0.00 0.728 0.000 0.272 0.000
#> GSM782704     3  0.0260     0.8997 0.000 0.00 0.992 0.000 0.008 0.000
#> GSM782705     6  0.1204     0.6468 0.056 0.00 0.000 0.000 0.000 0.944
#> GSM782706     1  0.2841     0.8188 0.824 0.00 0.000 0.164 0.000 0.012
#> GSM782707     1  0.0000     0.9433 1.000 0.00 0.000 0.000 0.000 0.000
#> GSM782708     3  0.0000     0.9027 0.000 0.00 1.000 0.000 0.000 0.000
#> GSM782709     1  0.0260     0.9401 0.992 0.00 0.000 0.000 0.000 0.008
#> GSM782710     1  0.0000     0.9433 1.000 0.00 0.000 0.000 0.000 0.000
#> GSM782711     1  0.0146     0.9431 0.996 0.00 0.000 0.004 0.000 0.000
#> GSM782712     1  0.0000     0.9433 1.000 0.00 0.000 0.000 0.000 0.000
#> GSM782713     5  0.0000     1.0000 0.000 0.00 0.000 0.000 1.000 0.000
#> GSM782714     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782715     1  0.1074     0.9193 0.960 0.00 0.000 0.012 0.000 0.028
#> GSM782716     3  0.0000     0.9027 0.000 0.00 1.000 0.000 0.000 0.000
#> GSM782717     6  0.0000     0.6920 0.000 0.00 0.000 0.000 0.000 1.000
#> GSM782718     6  0.0458     0.6873 0.000 0.00 0.000 0.016 0.000 0.984
#> GSM782719     1  0.1007     0.9227 0.956 0.00 0.000 0.044 0.000 0.000
#> GSM782720     5  0.0000     1.0000 0.000 0.00 0.000 0.000 1.000 0.000
#> GSM782721     1  0.3578     0.7815 0.784 0.00 0.000 0.164 0.000 0.052
#> GSM782722     4  0.3672     0.0000 0.000 0.00 0.000 0.632 0.000 0.368
#> GSM782723     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782725     6  0.3866    -0.6393 0.000 0.00 0.000 0.484 0.000 0.516
#> GSM782726     6  0.3860     0.0581 0.472 0.00 0.000 0.000 0.000 0.528
#> GSM782727     5  0.0000     1.0000 0.000 0.00 0.000 0.000 1.000 0.000
#> GSM782728     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782729     6  0.4179    -0.6362 0.012 0.00 0.000 0.472 0.000 0.516
#> GSM782730     5  0.0000     1.0000 0.000 0.00 0.000 0.000 1.000 0.000
#> GSM782731     6  0.0000     0.6920 0.000 0.00 0.000 0.000 0.000 1.000
#> GSM782732     6  0.0000     0.6920 0.000 0.00 0.000 0.000 0.000 1.000
#> GSM782733     3  0.0000     0.9027 0.000 0.00 1.000 0.000 0.000 0.000
#> GSM782734     6  0.2416     0.5280 0.156 0.00 0.000 0.000 0.000 0.844
#> GSM782735     2  0.0937     0.9701 0.000 0.96 0.000 0.040 0.000 0.000
#> GSM782736     6  0.0547     0.6836 0.000 0.00 0.000 0.020 0.000 0.980
#> GSM782737     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782738     6  0.0725     0.6844 0.012 0.00 0.000 0.012 0.000 0.976
#> GSM782739     6  0.0000     0.6920 0.000 0.00 0.000 0.000 0.000 1.000
#> GSM782740     2  0.0000     0.9916 0.000 1.00 0.000 0.000 0.000 0.000
#> GSM782741     1  0.3547     0.4873 0.668 0.00 0.000 0.000 0.000 0.332
#> GSM782742     5  0.0000     1.0000 0.000 0.00 0.000 0.000 1.000 0.000
#> GSM782743     3  0.0000     0.9027 0.000 0.00 1.000 0.000 0.000 0.000
#> GSM782744     3  0.3758     0.6688 0.000 0.00 0.668 0.324 0.008 0.000
#> GSM782745     6  0.2260     0.5512 0.140 0.00 0.000 0.000 0.000 0.860
#> GSM782746     2  0.0937     0.9701 0.000 0.96 0.000 0.040 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-pam-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-MAD-pam-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-MAD-pam-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-MAD-pam-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-MAD-pam-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-pam-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-MAD-pam-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-MAD-pam-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-MAD-pam-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-MAD-pam-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-pam-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-MAD-pam-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-MAD-pam-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-MAD-pam-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-MAD-pam-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-pam-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-MAD-pam-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-MAD-pam-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-MAD-pam-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-MAD-pam-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-pam-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-MAD-pam-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-MAD-pam-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-MAD-pam-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-MAD-pam-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) k
#> MAD:pam 51    0.648 2
#> MAD:pam 51    0.642 3
#> MAD:pam 49    0.551 4
#> MAD:pam 49    0.520 5
#> MAD:pam 46    0.523 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:mclust**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "mclust"]
# you can also extract it by
# res = res_list["MAD:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.633           0.903       0.919         0.4268 0.506   0.506
#> 3 3 1.000           0.998       0.999         0.3560 0.915   0.833
#> 4 4 0.701           0.698       0.838         0.1957 0.956   0.896
#> 5 5 0.652           0.532       0.743         0.0859 0.802   0.509
#> 6 6 0.776           0.662       0.865         0.0650 0.823   0.418

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.000      1.000 1.000 0.000
#> GSM782697     1   0.000      1.000 1.000 0.000
#> GSM782698     1   0.000      1.000 1.000 0.000
#> GSM782699     1   0.000      1.000 1.000 0.000
#> GSM782700     2   0.000      0.767 0.000 1.000
#> GSM782701     1   0.000      1.000 1.000 0.000
#> GSM782702     1   0.000      1.000 1.000 0.000
#> GSM782703     2   0.929      0.764 0.344 0.656
#> GSM782704     2   0.929      0.764 0.344 0.656
#> GSM782705     1   0.000      1.000 1.000 0.000
#> GSM782706     1   0.000      1.000 1.000 0.000
#> GSM782707     1   0.000      1.000 1.000 0.000
#> GSM782708     2   0.929      0.764 0.344 0.656
#> GSM782709     1   0.000      1.000 1.000 0.000
#> GSM782710     1   0.000      1.000 1.000 0.000
#> GSM782711     1   0.000      1.000 1.000 0.000
#> GSM782712     1   0.000      1.000 1.000 0.000
#> GSM782713     2   0.929      0.764 0.344 0.656
#> GSM782714     2   0.000      0.767 0.000 1.000
#> GSM782715     1   0.000      1.000 1.000 0.000
#> GSM782716     2   0.929      0.764 0.344 0.656
#> GSM782717     1   0.000      1.000 1.000 0.000
#> GSM782718     1   0.000      1.000 1.000 0.000
#> GSM782719     1   0.000      1.000 1.000 0.000
#> GSM782720     2   0.929      0.764 0.344 0.656
#> GSM782721     1   0.000      1.000 1.000 0.000
#> GSM782722     1   0.000      1.000 1.000 0.000
#> GSM782723     2   0.000      0.767 0.000 1.000
#> GSM782724     2   0.000      0.767 0.000 1.000
#> GSM782725     1   0.000      1.000 1.000 0.000
#> GSM782726     1   0.000      1.000 1.000 0.000
#> GSM782727     2   0.929      0.764 0.344 0.656
#> GSM782728     2   0.000      0.767 0.000 1.000
#> GSM782729     1   0.000      1.000 1.000 0.000
#> GSM782730     2   0.929      0.764 0.344 0.656
#> GSM782731     1   0.000      1.000 1.000 0.000
#> GSM782732     1   0.000      1.000 1.000 0.000
#> GSM782733     2   0.929      0.764 0.344 0.656
#> GSM782734     1   0.000      1.000 1.000 0.000
#> GSM782735     2   0.000      0.767 0.000 1.000
#> GSM782736     1   0.000      1.000 1.000 0.000
#> GSM782737     2   0.000      0.767 0.000 1.000
#> GSM782738     1   0.000      1.000 1.000 0.000
#> GSM782739     1   0.000      1.000 1.000 0.000
#> GSM782740     2   0.000      0.767 0.000 1.000
#> GSM782741     1   0.000      1.000 1.000 0.000
#> GSM782742     2   0.929      0.764 0.344 0.656
#> GSM782743     2   0.929      0.764 0.344 0.656
#> GSM782744     2   0.929      0.764 0.344 0.656
#> GSM782745     1   0.000      1.000 1.000 0.000
#> GSM782746     2   0.000      0.767 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1    p2    p3
#> GSM782696     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782697     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782698     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782699     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782701     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782702     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782703     3  0.0237      0.993 0.000 0.004 0.996
#> GSM782704     3  0.0000      0.993 0.000 0.000 1.000
#> GSM782705     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782706     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782707     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782708     3  0.0000      0.993 0.000 0.000 1.000
#> GSM782709     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782710     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782711     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782712     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782713     3  0.0237      0.993 0.000 0.004 0.996
#> GSM782714     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782715     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782716     3  0.0000      0.993 0.000 0.000 1.000
#> GSM782717     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782718     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782719     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782720     3  0.0237      0.993 0.000 0.004 0.996
#> GSM782721     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782722     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782723     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782724     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782725     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782726     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782727     3  0.0237      0.993 0.000 0.004 0.996
#> GSM782728     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782729     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782730     3  0.0237      0.993 0.000 0.004 0.996
#> GSM782731     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782732     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782733     3  0.0000      0.993 0.000 0.000 1.000
#> GSM782734     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782735     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782736     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782737     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782738     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782739     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782740     2  0.0000      1.000 0.000 1.000 0.000
#> GSM782741     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782742     3  0.0237      0.993 0.000 0.004 0.996
#> GSM782743     3  0.0000      0.993 0.000 0.000 1.000
#> GSM782744     3  0.1411      0.948 0.036 0.000 0.964
#> GSM782745     1  0.0000      1.000 1.000 0.000 0.000
#> GSM782746     2  0.0000      1.000 0.000 1.000 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.2973      0.518 0.856  0 0.000 0.144
#> GSM782697     1  0.1211      0.563 0.960  0 0.000 0.040
#> GSM782698     1  0.4477      0.502 0.688  0 0.000 0.312
#> GSM782699     1  0.2704      0.509 0.876  0 0.000 0.124
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.4804      0.474 0.616  0 0.000 0.384
#> GSM782702     1  0.0469      0.566 0.988  0 0.000 0.012
#> GSM782703     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782705     1  0.0921      0.569 0.972  0 0.000 0.028
#> GSM782706     1  0.4790      0.480 0.620  0 0.000 0.380
#> GSM782707     1  0.4222      0.534 0.728  0 0.000 0.272
#> GSM782708     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782709     1  0.4277      0.500 0.720  0 0.000 0.280
#> GSM782710     1  0.3266      0.275 0.832  0 0.000 0.168
#> GSM782711     1  0.2704      0.509 0.876  0 0.000 0.124
#> GSM782712     1  0.2345      0.528 0.900  0 0.000 0.100
#> GSM782713     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.4977      0.227 0.540  0 0.000 0.460
#> GSM782716     3  0.0188      0.978 0.000  0 0.996 0.004
#> GSM782717     1  0.3219      0.502 0.836  0 0.000 0.164
#> GSM782718     1  0.3610      0.592 0.800  0 0.000 0.200
#> GSM782719     1  0.4431      0.515 0.696  0 0.000 0.304
#> GSM782720     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782721     1  0.4817      0.474 0.612  0 0.000 0.388
#> GSM782722     1  0.4277      0.555 0.720  0 0.000 0.280
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     1  0.4406     -0.150 0.700  0 0.000 0.300
#> GSM782726     4  0.4916      0.989 0.424  0 0.000 0.576
#> GSM782727     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     1  0.1389      0.548 0.952  0 0.000 0.048
#> GSM782730     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782731     1  0.4585      0.474 0.668  0 0.000 0.332
#> GSM782732     1  0.4222      0.505 0.728  0 0.000 0.272
#> GSM782733     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782734     1  0.4643      0.353 0.656  0 0.000 0.344
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     1  0.4916      0.437 0.576  0 0.000 0.424
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.4661      0.514 0.652  0 0.000 0.348
#> GSM782739     1  0.1867      0.558 0.928  0 0.000 0.072
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.3569      0.473 0.804  0 0.000 0.196
#> GSM782742     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782743     3  0.0000      0.980 0.000  0 1.000 0.000
#> GSM782744     3  0.4827      0.741 0.092  0 0.784 0.124
#> GSM782745     4  0.4925      0.989 0.428  0 0.000 0.572
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.4235      0.520 0.576  0 0.000 0.424 0.000
#> GSM782697     1  0.4437      0.483 0.532  0 0.000 0.464 0.004
#> GSM782698     1  0.4227      0.398 0.580  0 0.000 0.420 0.000
#> GSM782699     1  0.3913      0.578 0.676  0 0.000 0.324 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     4  0.4201     -0.351 0.408  0 0.000 0.592 0.000
#> GSM782702     1  0.4283      0.457 0.544  0 0.000 0.456 0.000
#> GSM782703     3  0.3774      0.850 0.000  0 0.704 0.000 0.296
#> GSM782704     3  0.4101      0.756 0.000  0 0.628 0.000 0.372
#> GSM782705     1  0.3983      0.576 0.660  0 0.000 0.340 0.000
#> GSM782706     4  0.4307     -0.441 0.500  0 0.000 0.500 0.000
#> GSM782707     1  0.4306      0.397 0.508  0 0.000 0.492 0.000
#> GSM782708     5  0.0794      0.964 0.000  0 0.028 0.000 0.972
#> GSM782709     4  0.4430     -0.463 0.456  0 0.000 0.540 0.004
#> GSM782710     4  0.4789      0.253 0.392  0 0.024 0.584 0.000
#> GSM782711     1  0.4030      0.576 0.648  0 0.000 0.352 0.000
#> GSM782712     1  0.4126      0.557 0.620  0 0.000 0.380 0.000
#> GSM782713     3  0.3480      0.883 0.000  0 0.752 0.000 0.248
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     4  0.2011      0.413 0.088  0 0.000 0.908 0.004
#> GSM782716     5  0.0162      0.972 0.000  0 0.004 0.000 0.996
#> GSM782717     4  0.3109      0.342 0.200  0 0.000 0.800 0.000
#> GSM782718     4  0.3837      0.184 0.308  0 0.000 0.692 0.000
#> GSM782719     1  0.4307      0.364 0.500  0 0.000 0.500 0.000
#> GSM782720     3  0.3336      0.880 0.000  0 0.772 0.000 0.228
#> GSM782721     4  0.4114     -0.290 0.376  0 0.000 0.624 0.000
#> GSM782722     4  0.3983      0.250 0.340  0 0.000 0.660 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     1  0.4440     -0.309 0.528  0 0.004 0.468 0.000
#> GSM782726     4  0.7479      0.224 0.320  0 0.164 0.448 0.068
#> GSM782727     3  0.3508      0.882 0.000  0 0.748 0.000 0.252
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.4074      0.274 0.364  0 0.000 0.636 0.000
#> GSM782730     3  0.3395      0.883 0.000  0 0.764 0.000 0.236
#> GSM782731     4  0.0162      0.419 0.004  0 0.000 0.996 0.000
#> GSM782732     4  0.2020      0.392 0.100  0 0.000 0.900 0.000
#> GSM782733     5  0.0162      0.972 0.000  0 0.004 0.000 0.996
#> GSM782734     4  0.0963      0.419 0.036  0 0.000 0.964 0.000
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.3480      0.308 0.248  0 0.000 0.752 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     4  0.2813      0.366 0.168  0 0.000 0.832 0.000
#> GSM782739     4  0.3003      0.343 0.188  0 0.000 0.812 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     4  0.3003      0.348 0.188  0 0.000 0.812 0.000
#> GSM782742     3  0.3461      0.876 0.004  0 0.772 0.000 0.224
#> GSM782743     5  0.0880      0.959 0.000  0 0.032 0.000 0.968
#> GSM782744     3  0.6490      0.443 0.028  0 0.584 0.160 0.228
#> GSM782745     4  0.7469      0.224 0.328  0 0.160 0.444 0.068
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1  0.2912     0.5856 0.784  0 0.000 0.000 0.000 0.216
#> GSM782697     1  0.3995     0.0995 0.516  0 0.000 0.000 0.004 0.480
#> GSM782698     1  0.0508     0.6440 0.984  0 0.000 0.000 0.004 0.012
#> GSM782699     1  0.3833     0.2193 0.556  0 0.000 0.000 0.000 0.444
#> GSM782700     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     1  0.1918     0.6749 0.904  0 0.000 0.000 0.008 0.088
#> GSM782702     6  0.2135     0.6196 0.128  0 0.000 0.000 0.000 0.872
#> GSM782703     3  0.0405     0.8629 0.000  0 0.988 0.008 0.004 0.000
#> GSM782704     3  0.3789     0.3270 0.000  0 0.584 0.416 0.000 0.000
#> GSM782705     6  0.3862    -0.1562 0.476  0 0.000 0.000 0.000 0.524
#> GSM782706     1  0.1524     0.6706 0.932  0 0.000 0.000 0.008 0.060
#> GSM782707     1  0.1765     0.6716 0.904  0 0.000 0.000 0.000 0.096
#> GSM782708     4  0.0000     1.0000 0.000  0 0.000 1.000 0.000 0.000
#> GSM782709     1  0.4093     0.1515 0.516  0 0.000 0.000 0.008 0.476
#> GSM782710     6  0.3290     0.5008 0.004  0 0.000 0.000 0.252 0.744
#> GSM782711     6  0.3869    -0.1876 0.500  0 0.000 0.000 0.000 0.500
#> GSM782712     6  0.3838    -0.0383 0.448  0 0.000 0.000 0.000 0.552
#> GSM782713     3  0.0260     0.8637 0.000  0 0.992 0.008 0.000 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     6  0.3110     0.5248 0.196  0 0.000 0.000 0.012 0.792
#> GSM782716     4  0.0000     1.0000 0.000  0 0.000 1.000 0.000 0.000
#> GSM782717     6  0.0520     0.7128 0.008  0 0.000 0.000 0.008 0.984
#> GSM782718     1  0.3309     0.5214 0.720  0 0.000 0.000 0.000 0.280
#> GSM782719     1  0.1075     0.6705 0.952  0 0.000 0.000 0.000 0.048
#> GSM782720     3  0.0000     0.8637 0.000  0 1.000 0.000 0.000 0.000
#> GSM782721     1  0.2513     0.6656 0.852  0 0.000 0.000 0.008 0.140
#> GSM782722     1  0.3795     0.2794 0.632  0 0.000 0.000 0.004 0.364
#> GSM782723     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     6  0.3394     0.5671 0.012  0 0.000 0.000 0.236 0.752
#> GSM782726     5  0.0291     0.9926 0.004  0 0.000 0.000 0.992 0.004
#> GSM782727     3  0.0260     0.8637 0.000  0 0.992 0.008 0.000 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     6  0.1168     0.7078 0.016  0 0.000 0.000 0.028 0.956
#> GSM782730     3  0.0000     0.8637 0.000  0 1.000 0.000 0.000 0.000
#> GSM782731     6  0.0806     0.7105 0.020  0 0.000 0.000 0.008 0.972
#> GSM782732     6  0.0000     0.7117 0.000  0 0.000 0.000 0.000 1.000
#> GSM782733     4  0.0000     1.0000 0.000  0 0.000 1.000 0.000 0.000
#> GSM782734     6  0.0858     0.7091 0.004  0 0.000 0.000 0.028 0.968
#> GSM782735     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     1  0.3930     0.1639 0.576  0 0.000 0.000 0.004 0.420
#> GSM782737     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     6  0.3841     0.1728 0.380  0 0.000 0.000 0.004 0.616
#> GSM782739     6  0.0622     0.7133 0.008  0 0.000 0.000 0.012 0.980
#> GSM782740     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     6  0.0146     0.7126 0.004  0 0.000 0.000 0.000 0.996
#> GSM782742     3  0.0000     0.8637 0.000  0 1.000 0.000 0.000 0.000
#> GSM782743     4  0.0000     1.0000 0.000  0 0.000 1.000 0.000 0.000
#> GSM782744     3  0.4212     0.2688 0.000  0 0.560 0.016 0.424 0.000
#> GSM782745     5  0.0260     0.9926 0.000  0 0.000 0.000 0.992 0.008
#> GSM782746     2  0.0000     1.0000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-mclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-MAD-mclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-MAD-mclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-MAD-mclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-MAD-mclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-mclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-MAD-mclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-MAD-mclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-MAD-mclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-MAD-mclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-mclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-MAD-mclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-MAD-mclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-MAD-mclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-MAD-mclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-mclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-MAD-mclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-MAD-mclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-MAD-mclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-MAD-mclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-mclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-MAD-mclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-MAD-mclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-MAD-mclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-MAD-mclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> MAD:mclust 51    0.493 2
#> MAD:mclust 51    0.642 3
#> MAD:mclust 40    0.754 4
#> MAD:mclust 25    0.428 5
#> MAD:mclust 40    0.576 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


MAD:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["MAD", "NMF"]
# you can also extract it by
# res = res_list["MAD:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'MAD' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk MAD-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk MAD-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.999       1.000         0.2977 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9456 0.718   0.599
#> 4 4 0.730           0.639       0.859         0.1833 0.956   0.896
#> 5 5 0.736           0.765       0.858         0.1179 0.825   0.547
#> 6 6 0.782           0.713       0.831         0.0352 1.000   1.000

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1  0.0000      0.999 1.000 0.000
#> GSM782697     1  0.0000      0.999 1.000 0.000
#> GSM782698     1  0.0000      0.999 1.000 0.000
#> GSM782699     1  0.0000      0.999 1.000 0.000
#> GSM782700     2  0.0000      1.000 0.000 1.000
#> GSM782701     1  0.0000      0.999 1.000 0.000
#> GSM782702     1  0.0000      0.999 1.000 0.000
#> GSM782703     1  0.1414      0.980 0.980 0.020
#> GSM782704     1  0.0000      0.999 1.000 0.000
#> GSM782705     1  0.0000      0.999 1.000 0.000
#> GSM782706     1  0.0000      0.999 1.000 0.000
#> GSM782707     1  0.0000      0.999 1.000 0.000
#> GSM782708     1  0.0000      0.999 1.000 0.000
#> GSM782709     1  0.0000      0.999 1.000 0.000
#> GSM782710     1  0.0000      0.999 1.000 0.000
#> GSM782711     1  0.0000      0.999 1.000 0.000
#> GSM782712     1  0.0000      0.999 1.000 0.000
#> GSM782713     1  0.0376      0.996 0.996 0.004
#> GSM782714     2  0.0000      1.000 0.000 1.000
#> GSM782715     1  0.0000      0.999 1.000 0.000
#> GSM782716     1  0.0000      0.999 1.000 0.000
#> GSM782717     1  0.0000      0.999 1.000 0.000
#> GSM782718     1  0.0000      0.999 1.000 0.000
#> GSM782719     1  0.0000      0.999 1.000 0.000
#> GSM782720     1  0.0000      0.999 1.000 0.000
#> GSM782721     1  0.0000      0.999 1.000 0.000
#> GSM782722     1  0.0000      0.999 1.000 0.000
#> GSM782723     2  0.0000      1.000 0.000 1.000
#> GSM782724     2  0.0000      1.000 0.000 1.000
#> GSM782725     1  0.0000      0.999 1.000 0.000
#> GSM782726     1  0.0000      0.999 1.000 0.000
#> GSM782727     1  0.0000      0.999 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000 1.000
#> GSM782729     1  0.0000      0.999 1.000 0.000
#> GSM782730     1  0.0000      0.999 1.000 0.000
#> GSM782731     1  0.0000      0.999 1.000 0.000
#> GSM782732     1  0.0000      0.999 1.000 0.000
#> GSM782733     1  0.0000      0.999 1.000 0.000
#> GSM782734     1  0.0000      0.999 1.000 0.000
#> GSM782735     2  0.0000      1.000 0.000 1.000
#> GSM782736     1  0.0000      0.999 1.000 0.000
#> GSM782737     2  0.0000      1.000 0.000 1.000
#> GSM782738     1  0.0000      0.999 1.000 0.000
#> GSM782739     1  0.0000      0.999 1.000 0.000
#> GSM782740     2  0.0000      1.000 0.000 1.000
#> GSM782741     1  0.0000      0.999 1.000 0.000
#> GSM782742     1  0.0000      0.999 1.000 0.000
#> GSM782743     1  0.0000      0.999 1.000 0.000
#> GSM782744     1  0.0000      0.999 1.000 0.000
#> GSM782745     1  0.0000      0.999 1.000 0.000
#> GSM782746     2  0.0000      1.000 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.3726      0.392 0.788  0 0.000 0.212
#> GSM782697     1  0.4843     -0.278 0.604  0 0.000 0.396
#> GSM782698     1  0.4008      0.352 0.756  0 0.000 0.244
#> GSM782699     1  0.3172      0.479 0.840  0 0.000 0.160
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.4817     -0.255 0.612  0 0.000 0.388
#> GSM782702     1  0.2647      0.524 0.880  0 0.000 0.120
#> GSM782703     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782705     1  0.1474      0.599 0.948  0 0.000 0.052
#> GSM782706     4  0.4992      0.291 0.476  0 0.000 0.524
#> GSM782707     1  0.4304      0.217 0.716  0 0.000 0.284
#> GSM782708     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782709     1  0.3444      0.430 0.816  0 0.000 0.184
#> GSM782710     1  0.1211      0.596 0.960  0 0.000 0.040
#> GSM782711     1  0.4040      0.292 0.752  0 0.000 0.248
#> GSM782712     1  0.4679     -0.108 0.648  0 0.000 0.352
#> GSM782713     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.4277      0.460 0.720  0 0.000 0.280
#> GSM782716     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782717     1  0.0188      0.601 0.996  0 0.000 0.004
#> GSM782718     1  0.3975      0.495 0.760  0 0.000 0.240
#> GSM782719     4  0.4790      0.502 0.380  0 0.000 0.620
#> GSM782720     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782721     1  0.4888     -0.252 0.588  0 0.000 0.412
#> GSM782722     1  0.4697      0.374 0.644  0 0.000 0.356
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     1  0.4356      0.446 0.708  0 0.000 0.292
#> GSM782726     1  0.1716      0.602 0.936  0 0.000 0.064
#> GSM782727     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     1  0.3975      0.489 0.760  0 0.000 0.240
#> GSM782730     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782731     1  0.2973      0.566 0.856  0 0.000 0.144
#> GSM782732     1  0.2469      0.585 0.892  0 0.000 0.108
#> GSM782733     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782734     1  0.1022      0.600 0.968  0 0.000 0.032
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     1  0.4382      0.446 0.704  0 0.000 0.296
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.4382      0.455 0.704  0 0.000 0.296
#> GSM782739     1  0.0817      0.606 0.976  0 0.000 0.024
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.2469      0.548 0.892  0 0.000 0.108
#> GSM782742     3  0.0000      0.998 0.000  0 1.000 0.000
#> GSM782743     3  0.0188      0.996 0.000  0 0.996 0.004
#> GSM782744     3  0.0707      0.982 0.000  0 0.980 0.020
#> GSM782745     1  0.2216      0.590 0.908  0 0.000 0.092
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.4425     -0.346 0.544  0 0.000 0.004 0.452
#> GSM782697     1  0.4272      0.508 0.752  0 0.000 0.052 0.196
#> GSM782698     1  0.5144      0.342 0.640  0 0.000 0.068 0.292
#> GSM782699     1  0.3389      0.625 0.836  0 0.000 0.048 0.116
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     5  0.5320      0.801 0.368  0 0.000 0.060 0.572
#> GSM782702     1  0.2795      0.649 0.872  0 0.000 0.028 0.100
#> GSM782703     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782704     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782705     1  0.2653      0.703 0.880  0 0.000 0.096 0.024
#> GSM782706     4  0.6117      0.287 0.136  0 0.000 0.504 0.360
#> GSM782707     5  0.5707      0.762 0.364  0 0.000 0.092 0.544
#> GSM782708     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782709     1  0.3696      0.498 0.772  0 0.000 0.016 0.212
#> GSM782710     1  0.0451      0.714 0.988  0 0.000 0.004 0.008
#> GSM782711     1  0.3837      0.307 0.692  0 0.000 0.000 0.308
#> GSM782712     5  0.4958      0.793 0.372  0 0.000 0.036 0.592
#> GSM782713     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     4  0.3366      0.776 0.212  0 0.000 0.784 0.004
#> GSM782716     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782717     1  0.1608      0.728 0.928  0 0.000 0.072 0.000
#> GSM782718     4  0.3663      0.777 0.208  0 0.000 0.776 0.016
#> GSM782719     5  0.3419      0.649 0.180  0 0.000 0.016 0.804
#> GSM782720     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782721     4  0.6447      0.198 0.192  0 0.000 0.472 0.336
#> GSM782722     4  0.2824      0.764 0.116  0 0.000 0.864 0.020
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.2719      0.782 0.144  0 0.000 0.852 0.004
#> GSM782726     1  0.1877      0.728 0.924  0 0.000 0.064 0.012
#> GSM782727     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.4356      0.563 0.340  0 0.000 0.648 0.012
#> GSM782730     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782731     1  0.4161      0.500 0.704  0 0.000 0.280 0.016
#> GSM782732     1  0.3565      0.659 0.800  0 0.000 0.176 0.024
#> GSM782733     3  0.0162      0.992 0.000  0 0.996 0.004 0.000
#> GSM782734     1  0.2411      0.716 0.884  0 0.000 0.108 0.008
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.3093      0.784 0.168  0 0.000 0.824 0.008
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     4  0.3438      0.787 0.172  0 0.000 0.808 0.020
#> GSM782739     1  0.1965      0.724 0.904  0 0.000 0.096 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.4155      0.642 0.780  0 0.000 0.144 0.076
#> GSM782742     3  0.0000      0.994 0.000  0 1.000 0.000 0.000
#> GSM782743     3  0.0162      0.992 0.000  0 0.996 0.004 0.000
#> GSM782744     3  0.1571      0.934 0.000  0 0.936 0.060 0.004
#> GSM782745     1  0.2361      0.718 0.892  0 0.000 0.096 0.012
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4 p5    p6
#> GSM782696     6  0.4561     -0.174 0.428 0.000 0.000 0.000 NA 0.536
#> GSM782697     6  0.4624      0.562 0.120 0.000 0.000 0.000 NA 0.688
#> GSM782698     6  0.6329      0.139 0.308 0.000 0.000 0.012 NA 0.412
#> GSM782699     6  0.3412      0.640 0.064 0.000 0.000 0.000 NA 0.808
#> GSM782700     2  0.0146      0.998 0.000 0.996 0.000 0.000 NA 0.000
#> GSM782701     1  0.4464      0.749 0.624 0.000 0.000 0.028 NA 0.340
#> GSM782702     6  0.3121      0.567 0.192 0.000 0.000 0.004 NA 0.796
#> GSM782703     3  0.0146      0.981 0.000 0.000 0.996 0.000 NA 0.000
#> GSM782704     3  0.0000      0.981 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782705     6  0.3732      0.576 0.004 0.000 0.000 0.024 NA 0.744
#> GSM782706     4  0.6721     -0.197 0.352 0.000 0.000 0.404 NA 0.192
#> GSM782707     1  0.4552      0.778 0.684 0.000 0.000 0.040 NA 0.256
#> GSM782708     3  0.0000      0.981 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782709     6  0.3507      0.478 0.232 0.000 0.000 0.004 NA 0.752
#> GSM782710     6  0.2095      0.660 0.076 0.000 0.000 0.004 NA 0.904
#> GSM782711     6  0.4153      0.241 0.340 0.000 0.000 0.000 NA 0.636
#> GSM782712     1  0.4015      0.764 0.656 0.000 0.000 0.008 NA 0.328
#> GSM782713     3  0.0146      0.981 0.000 0.000 0.996 0.000 NA 0.000
#> GSM782714     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782715     4  0.2595      0.735 0.020 0.000 0.000 0.880 NA 0.084
#> GSM782716     3  0.0000      0.981 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782717     6  0.1364      0.680 0.012 0.000 0.000 0.020 NA 0.952
#> GSM782718     4  0.3174      0.727 0.012 0.000 0.000 0.840 NA 0.108
#> GSM782719     1  0.3657      0.629 0.792 0.000 0.000 0.000 NA 0.100
#> GSM782720     3  0.0146      0.981 0.000 0.000 0.996 0.000 NA 0.000
#> GSM782721     4  0.6994     -0.290 0.324 0.000 0.000 0.368 NA 0.244
#> GSM782722     4  0.1321      0.719 0.024 0.000 0.000 0.952 NA 0.020
#> GSM782723     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782724     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782725     4  0.1398      0.736 0.000 0.000 0.000 0.940 NA 0.052
#> GSM782726     6  0.1426      0.671 0.028 0.000 0.000 0.008 NA 0.948
#> GSM782727     3  0.0260      0.980 0.000 0.000 0.992 0.000 NA 0.000
#> GSM782728     2  0.0146      0.998 0.000 0.996 0.000 0.000 NA 0.000
#> GSM782729     4  0.4812      0.532 0.000 0.000 0.000 0.640 NA 0.264
#> GSM782730     3  0.0000      0.981 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782731     6  0.4587      0.381 0.000 0.000 0.000 0.296 NA 0.640
#> GSM782732     6  0.4636      0.513 0.000 0.000 0.000 0.160 NA 0.692
#> GSM782733     3  0.0363      0.975 0.000 0.000 0.988 0.000 NA 0.000
#> GSM782734     6  0.2365      0.648 0.068 0.000 0.000 0.012 NA 0.896
#> GSM782735     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782736     4  0.3402      0.719 0.004 0.000 0.000 0.820 NA 0.104
#> GSM782737     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782738     4  0.2076      0.734 0.016 0.000 0.000 0.912 NA 0.060
#> GSM782739     6  0.1297      0.676 0.000 0.000 0.000 0.012 NA 0.948
#> GSM782740     2  0.0146      0.998 0.000 0.996 0.000 0.000 NA 0.000
#> GSM782741     6  0.3999      0.541 0.156 0.000 0.000 0.036 NA 0.776
#> GSM782742     3  0.0260      0.980 0.000 0.000 0.992 0.000 NA 0.000
#> GSM782743     3  0.0000      0.981 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782744     3  0.3729      0.797 0.008 0.000 0.808 0.116 NA 0.008
#> GSM782745     6  0.1555      0.674 0.008 0.000 0.000 0.040 NA 0.940
#> GSM782746     2  0.0000      0.999 0.000 1.000 0.000 0.000 NA 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-MAD-NMF-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-MAD-NMF-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-MAD-NMF-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-MAD-NMF-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-MAD-NMF-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-MAD-NMF-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-MAD-NMF-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-MAD-NMF-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-MAD-NMF-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-MAD-NMF-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-MAD-NMF-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-MAD-NMF-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-MAD-NMF-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-MAD-NMF-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-MAD-NMF-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-MAD-NMF-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-MAD-NMF-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-MAD-NMF-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-MAD-NMF-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-MAD-NMF-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk MAD-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-MAD-NMF-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-MAD-NMF-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-MAD-NMF-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-MAD-NMF-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-MAD-NMF-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk MAD-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) k
#> MAD:NMF 51    0.648 2
#> MAD:NMF 51    0.642 3
#> MAD:NMF 33    0.406 4
#> MAD:NMF 44    0.403 5
#> MAD:NMF 44    0.403 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:hclust**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "hclust"]
# you can also extract it by
# res = res_list["ATC:hclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'hclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-hclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-hclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.785           0.914       0.949         0.0796 0.991   0.980
#> 5 5 0.834           0.848       0.920         0.1092 0.918   0.802
#> 6 6 0.790           0.782       0.905         0.1160 0.871   0.619

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2   p3    p4
#> GSM782696     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782697     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782698     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782699     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782700     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782701     1  0.0188      0.923 0.996  0 0.00 0.004
#> GSM782702     1  0.0000      0.924 1.000  0 0.00 0.000
#> GSM782703     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782704     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782705     1  0.0336      0.924 0.992  0 0.00 0.008
#> GSM782706     1  0.2530      0.874 0.888  0 0.00 0.112
#> GSM782707     1  0.0188      0.923 0.996  0 0.00 0.004
#> GSM782708     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782709     1  0.3528      0.808 0.808  0 0.00 0.192
#> GSM782710     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782711     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782712     1  0.0188      0.923 0.996  0 0.00 0.004
#> GSM782713     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782715     1  0.3266      0.843 0.832  0 0.00 0.168
#> GSM782716     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782717     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782718     1  0.3219      0.846 0.836  0 0.00 0.164
#> GSM782719     1  0.0188      0.923 0.996  0 0.00 0.004
#> GSM782720     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782721     1  0.2530      0.874 0.888  0 0.00 0.112
#> GSM782722     1  0.3266      0.843 0.832  0 0.00 0.168
#> GSM782723     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782725     1  0.3266      0.843 0.832  0 0.00 0.168
#> GSM782726     1  0.3528      0.808 0.808  0 0.00 0.192
#> GSM782727     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782729     1  0.3266      0.843 0.832  0 0.00 0.168
#> GSM782730     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782731     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782732     1  0.0188      0.924 0.996  0 0.00 0.004
#> GSM782733     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782734     1  0.3528      0.808 0.808  0 0.00 0.192
#> GSM782735     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782736     1  0.3219      0.846 0.836  0 0.00 0.164
#> GSM782737     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782738     1  0.3219      0.846 0.836  0 0.00 0.164
#> GSM782739     1  0.0336      0.923 0.992  0 0.00 0.008
#> GSM782740     2  0.0000      1.000 0.000  1 0.00 0.000
#> GSM782741     1  0.0336      0.923 0.992  0 0.00 0.008
#> GSM782742     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782743     3  0.0000      1.000 0.000  0 1.00 0.000
#> GSM782744     4  0.4713      0.000 0.000  0 0.36 0.640
#> GSM782745     1  0.3528      0.808 0.808  0 0.00 0.192
#> GSM782746     2  0.0000      1.000 0.000  1 0.00 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2 p3    p4 p5
#> GSM782696     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782697     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782698     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782699     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782701     1  0.0290      0.828 0.992  0  0 0.008  0
#> GSM782702     1  0.0609      0.817 0.980  0  0 0.020  0
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782705     1  0.0404      0.829 0.988  0  0 0.012  0
#> GSM782706     1  0.3684      0.344 0.720  0  0 0.280  0
#> GSM782707     1  0.0162      0.828 0.996  0  0 0.004  0
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782709     4  0.3816      1.000 0.304  0  0 0.696  0
#> GSM782710     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782711     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782712     1  0.0162      0.828 0.996  0  0 0.004  0
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782715     1  0.3816      0.646 0.696  0  0 0.304  0
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782717     1  0.0404      0.827 0.988  0  0 0.012  0
#> GSM782718     1  0.3796      0.650 0.700  0  0 0.300  0
#> GSM782719     1  0.0162      0.828 0.996  0  0 0.004  0
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782721     1  0.3684      0.344 0.720  0  0 0.280  0
#> GSM782722     1  0.3816      0.646 0.696  0  0 0.304  0
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782725     1  0.3816      0.646 0.696  0  0 0.304  0
#> GSM782726     4  0.3816      1.000 0.304  0  0 0.696  0
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782729     1  0.3816      0.646 0.696  0  0 0.304  0
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782731     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782732     1  0.0290      0.829 0.992  0  0 0.008  0
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782734     4  0.3816      1.000 0.304  0  0 0.696  0
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782736     1  0.3796      0.650 0.700  0  0 0.300  0
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782738     1  0.3796      0.650 0.700  0  0 0.300  0
#> GSM782739     1  0.1197      0.791 0.952  0  0 0.048  0
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000  0
#> GSM782741     1  0.1197      0.791 0.952  0  0 0.048  0
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000  0
#> GSM782744     5  0.0000      0.000 0.000  0  0 0.000  1
#> GSM782745     4  0.3816      1.000 0.304  0  0 0.696  0
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000  0

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4 p5    p6
#> GSM782696     1  0.0865      0.825 0.964  0 0.000 0.036  0 0.000
#> GSM782697     1  0.0146      0.814 0.996  0 0.000 0.004  0 0.000
#> GSM782698     1  0.0146      0.814 0.996  0 0.000 0.004  0 0.000
#> GSM782699     1  0.0146      0.814 0.996  0 0.000 0.004  0 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782701     1  0.2772      0.773 0.816  0 0.000 0.180  0 0.004
#> GSM782702     1  0.3408      0.762 0.800  0 0.000 0.152  0 0.048
#> GSM782703     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782704     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782705     1  0.0458      0.812 0.984  0 0.000 0.016  0 0.000
#> GSM782706     6  0.4806      0.435 0.060  0 0.000 0.380  0 0.560
#> GSM782707     1  0.2631      0.775 0.820  0 0.000 0.180  0 0.000
#> GSM782708     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782709     6  0.0000      0.743 0.000  0 0.000 0.000  0 1.000
#> GSM782710     1  0.0146      0.814 0.996  0 0.000 0.004  0 0.000
#> GSM782711     1  0.0146      0.814 0.996  0 0.000 0.004  0 0.000
#> GSM782712     1  0.2527      0.783 0.832  0 0.000 0.168  0 0.000
#> GSM782713     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782715     4  0.3847      0.464 0.456  0 0.000 0.544  0 0.000
#> GSM782716     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782717     1  0.1958      0.821 0.896  0 0.000 0.100  0 0.004
#> GSM782718     1  0.3864     -0.416 0.520  0 0.000 0.480  0 0.000
#> GSM782719     1  0.1765      0.814 0.904  0 0.000 0.096  0 0.000
#> GSM782720     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782721     6  0.4806      0.435 0.060  0 0.000 0.380  0 0.560
#> GSM782722     4  0.1714      0.623 0.092  0 0.000 0.908  0 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782725     4  0.1957      0.650 0.112  0 0.000 0.888  0 0.000
#> GSM782726     6  0.0000      0.743 0.000  0 0.000 0.000  0 1.000
#> GSM782727     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782729     4  0.2219      0.653 0.136  0 0.000 0.864  0 0.000
#> GSM782730     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782731     1  0.1765      0.823 0.904  0 0.000 0.096  0 0.000
#> GSM782732     1  0.1765      0.823 0.904  0 0.000 0.096  0 0.000
#> GSM782733     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782734     6  0.0000      0.743 0.000  0 0.000 0.000  0 1.000
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782736     4  0.3823      0.414 0.436  0 0.000 0.564  0 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782738     4  0.3823      0.414 0.436  0 0.000 0.564  0 0.000
#> GSM782739     1  0.4242      0.671 0.736  0 0.000 0.136  0 0.128
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000
#> GSM782741     1  0.4242      0.671 0.736  0 0.000 0.136  0 0.128
#> GSM782742     3  0.0000      0.992 0.000  0 1.000 0.000  0 0.000
#> GSM782743     3  0.1663      0.909 0.000  0 0.912 0.088  0 0.000
#> GSM782744     5  0.0000      0.000 0.000  0 0.000 0.000  1 0.000
#> GSM782745     6  0.0000      0.743 0.000  0 0.000 0.000  0 1.000
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000  0 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-hclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-ATC-hclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-ATC-hclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-ATC-hclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-ATC-hclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-hclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-ATC-hclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-ATC-hclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-ATC-hclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-ATC-hclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-hclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-ATC-hclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-ATC-hclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-ATC-hclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-ATC-hclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-hclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-ATC-hclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-ATC-hclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-ATC-hclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-ATC-hclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-hclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-hclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-ATC-hclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-ATC-hclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-ATC-hclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-ATC-hclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-hclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> ATC:hclust 51    0.648 2
#> ATC:hclust 51    0.642 3
#> ATC:hclust 50    0.583 4
#> ATC:hclust 48    0.747 5
#> ATC:hclust 44    0.601 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:kmeans

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "kmeans"]
# you can also extract it by
# res = res_list["ATC:kmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'kmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-kmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-kmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 0.500           0.819       0.850         0.3293 0.704   0.704
#> 3 3 0.681           0.996       0.973         0.6771 0.718   0.599
#> 4 4 0.731           0.669       0.729         0.2216 0.836   0.611
#> 5 5 0.680           0.746       0.828         0.1072 0.836   0.535
#> 6 6 0.697           0.774       0.807         0.0495 0.925   0.734

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.929      0.835 0.656 0.344
#> GSM782697     1   0.929      0.835 0.656 0.344
#> GSM782698     1   0.929      0.835 0.656 0.344
#> GSM782699     1   0.929      0.835 0.656 0.344
#> GSM782700     2   0.000      1.000 0.000 1.000
#> GSM782701     1   0.929      0.835 0.656 0.344
#> GSM782702     1   0.929      0.835 0.656 0.344
#> GSM782703     1   0.000      0.660 1.000 0.000
#> GSM782704     1   0.000      0.660 1.000 0.000
#> GSM782705     1   0.929      0.835 0.656 0.344
#> GSM782706     1   0.929      0.835 0.656 0.344
#> GSM782707     1   0.929      0.835 0.656 0.344
#> GSM782708     1   0.000      0.660 1.000 0.000
#> GSM782709     1   0.850      0.804 0.724 0.276
#> GSM782710     1   0.929      0.835 0.656 0.344
#> GSM782711     1   0.929      0.835 0.656 0.344
#> GSM782712     1   0.929      0.835 0.656 0.344
#> GSM782713     1   0.000      0.660 1.000 0.000
#> GSM782714     2   0.000      1.000 0.000 1.000
#> GSM782715     1   0.929      0.835 0.656 0.344
#> GSM782716     1   0.000      0.660 1.000 0.000
#> GSM782717     1   0.929      0.835 0.656 0.344
#> GSM782718     1   0.929      0.835 0.656 0.344
#> GSM782719     1   0.929      0.835 0.656 0.344
#> GSM782720     1   0.000      0.660 1.000 0.000
#> GSM782721     1   0.929      0.835 0.656 0.344
#> GSM782722     1   0.929      0.835 0.656 0.344
#> GSM782723     2   0.000      1.000 0.000 1.000
#> GSM782724     2   0.000      1.000 0.000 1.000
#> GSM782725     1   0.929      0.835 0.656 0.344
#> GSM782726     1   0.402      0.699 0.920 0.080
#> GSM782727     1   0.000      0.660 1.000 0.000
#> GSM782728     2   0.000      1.000 0.000 1.000
#> GSM782729     1   0.929      0.835 0.656 0.344
#> GSM782730     1   0.000      0.660 1.000 0.000
#> GSM782731     1   0.929      0.835 0.656 0.344
#> GSM782732     1   0.929      0.835 0.656 0.344
#> GSM782733     1   0.000      0.660 1.000 0.000
#> GSM782734     1   0.886      0.818 0.696 0.304
#> GSM782735     2   0.000      1.000 0.000 1.000
#> GSM782736     1   0.929      0.835 0.656 0.344
#> GSM782737     2   0.000      1.000 0.000 1.000
#> GSM782738     1   0.929      0.835 0.656 0.344
#> GSM782739     1   0.929      0.835 0.656 0.344
#> GSM782740     2   0.000      1.000 0.000 1.000
#> GSM782741     1   0.929      0.835 0.656 0.344
#> GSM782742     1   0.000      0.660 1.000 0.000
#> GSM782743     1   0.000      0.660 1.000 0.000
#> GSM782744     1   0.000      0.660 1.000 0.000
#> GSM782745     1   0.886      0.818 0.696 0.304
#> GSM782746     2   0.000      1.000 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette  p1    p2    p3
#> GSM782696     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782697     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782698     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782699     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782700     2  0.0237      0.984 0.0 0.996 0.004
#> GSM782701     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782702     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782703     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782704     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782705     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782706     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782707     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782708     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782709     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782710     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782711     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782712     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782713     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782714     2  0.0000      0.984 0.0 1.000 0.000
#> GSM782715     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782716     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782717     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782718     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782719     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782720     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782721     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782722     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782723     2  0.1529      0.976 0.0 0.960 0.040
#> GSM782724     2  0.2165      0.966 0.0 0.936 0.064
#> GSM782725     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782726     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782727     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782728     2  0.0000      0.984 0.0 1.000 0.000
#> GSM782729     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782730     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782731     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782732     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782733     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782734     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782735     2  0.1411      0.975 0.0 0.964 0.036
#> GSM782736     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782737     2  0.0892      0.982 0.0 0.980 0.020
#> GSM782738     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782739     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782740     2  0.0000      0.984 0.0 1.000 0.000
#> GSM782741     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782742     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782743     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782744     3  0.2959      1.000 0.1 0.000 0.900
#> GSM782745     1  0.0000      1.000 1.0 0.000 0.000
#> GSM782746     2  0.1411      0.975 0.0 0.964 0.036

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1    p2    p3    p4
#> GSM782696     1  0.4961     -0.569 0.552 0.000 0.000 0.448
#> GSM782697     1  0.4941     -0.556 0.564 0.000 0.000 0.436
#> GSM782698     4  0.4955      0.977 0.444 0.000 0.000 0.556
#> GSM782699     1  0.4941     -0.556 0.564 0.000 0.000 0.436
#> GSM782700     2  0.0188      0.966 0.000 0.996 0.000 0.004
#> GSM782701     1  0.0817      0.601 0.976 0.000 0.000 0.024
#> GSM782702     1  0.1867      0.575 0.928 0.000 0.000 0.072
#> GSM782703     3  0.0895      0.960 0.004 0.000 0.976 0.020
#> GSM782704     3  0.2593      0.936 0.004 0.000 0.892 0.104
#> GSM782705     4  0.4972      0.967 0.456 0.000 0.000 0.544
#> GSM782706     1  0.0592      0.600 0.984 0.000 0.000 0.016
#> GSM782707     1  0.4967     -0.575 0.548 0.000 0.000 0.452
#> GSM782708     3  0.2593      0.936 0.004 0.000 0.892 0.104
#> GSM782709     1  0.0000      0.604 1.000 0.000 0.000 0.000
#> GSM782710     1  0.4356      0.128 0.708 0.000 0.000 0.292
#> GSM782711     1  0.4961     -0.569 0.552 0.000 0.000 0.448
#> GSM782712     1  0.3356      0.480 0.824 0.000 0.000 0.176
#> GSM782713     3  0.0188      0.961 0.004 0.000 0.996 0.000
#> GSM782714     2  0.0000      0.966 0.000 1.000 0.000 0.000
#> GSM782715     4  0.4948      0.980 0.440 0.000 0.000 0.560
#> GSM782716     3  0.0895      0.960 0.004 0.000 0.976 0.020
#> GSM782717     1  0.3569      0.431 0.804 0.000 0.000 0.196
#> GSM782718     4  0.4948      0.980 0.440 0.000 0.000 0.560
#> GSM782719     1  0.4967     -0.575 0.548 0.000 0.000 0.452
#> GSM782720     3  0.0188      0.961 0.004 0.000 0.996 0.000
#> GSM782721     1  0.0592      0.600 0.984 0.000 0.000 0.016
#> GSM782722     4  0.4948      0.980 0.440 0.000 0.000 0.560
#> GSM782723     2  0.2281      0.942 0.000 0.904 0.000 0.096
#> GSM782724     2  0.2868      0.925 0.000 0.864 0.000 0.136
#> GSM782725     4  0.4948      0.980 0.440 0.000 0.000 0.560
#> GSM782726     1  0.0000      0.604 1.000 0.000 0.000 0.000
#> GSM782727     3  0.0188      0.961 0.004 0.000 0.996 0.000
#> GSM782728     2  0.0000      0.966 0.000 1.000 0.000 0.000
#> GSM782729     4  0.4972      0.967 0.456 0.000 0.000 0.544
#> GSM782730     3  0.0188      0.961 0.004 0.000 0.996 0.000
#> GSM782731     4  0.4972      0.967 0.456 0.000 0.000 0.544
#> GSM782732     4  0.4972      0.967 0.456 0.000 0.000 0.544
#> GSM782733     3  0.0895      0.960 0.004 0.000 0.976 0.020
#> GSM782734     1  0.0000      0.604 1.000 0.000 0.000 0.000
#> GSM782735     2  0.1743      0.950 0.000 0.940 0.004 0.056
#> GSM782736     4  0.4948      0.980 0.440 0.000 0.000 0.560
#> GSM782737     2  0.1637      0.954 0.000 0.940 0.000 0.060
#> GSM782738     4  0.4948      0.980 0.440 0.000 0.000 0.560
#> GSM782739     1  0.3356      0.468 0.824 0.000 0.000 0.176
#> GSM782740     2  0.0000      0.966 0.000 1.000 0.000 0.000
#> GSM782741     1  0.0000      0.604 1.000 0.000 0.000 0.000
#> GSM782742     3  0.0188      0.961 0.004 0.000 0.996 0.000
#> GSM782743     3  0.2593      0.936 0.004 0.000 0.892 0.104
#> GSM782744     3  0.4053      0.837 0.004 0.000 0.768 0.228
#> GSM782745     1  0.0000      0.604 1.000 0.000 0.000 0.000
#> GSM782746     2  0.1743      0.950 0.000 0.940 0.004 0.056

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1    p2    p3    p4    p5
#> GSM782696     4  0.2763     0.6506 0.148 0.000 0.000 0.848 0.004
#> GSM782697     4  0.2921     0.6497 0.124 0.000 0.000 0.856 0.020
#> GSM782698     4  0.0000     0.6838 0.000 0.000 0.000 1.000 0.000
#> GSM782699     4  0.2825     0.6518 0.124 0.000 0.000 0.860 0.016
#> GSM782700     2  0.0740     0.9540 0.008 0.980 0.004 0.000 0.008
#> GSM782701     1  0.3456     0.8421 0.800 0.000 0.000 0.184 0.016
#> GSM782702     4  0.4902     0.0956 0.408 0.000 0.000 0.564 0.028
#> GSM782703     3  0.0451     0.9312 0.008 0.000 0.988 0.004 0.000
#> GSM782704     3  0.3684     0.8801 0.056 0.000 0.824 0.004 0.116
#> GSM782705     4  0.0162     0.6833 0.004 0.000 0.000 0.996 0.000
#> GSM782706     1  0.3495     0.8512 0.812 0.000 0.000 0.160 0.028
#> GSM782707     4  0.3885     0.5660 0.268 0.000 0.000 0.724 0.008
#> GSM782708     3  0.3684     0.8801 0.056 0.000 0.824 0.004 0.116
#> GSM782709     1  0.5379     0.8719 0.668 0.000 0.000 0.168 0.164
#> GSM782710     4  0.4223     0.5051 0.248 0.000 0.000 0.724 0.028
#> GSM782711     4  0.2763     0.6506 0.148 0.000 0.000 0.848 0.004
#> GSM782712     4  0.4533     0.1391 0.448 0.000 0.000 0.544 0.008
#> GSM782713     3  0.0865     0.9328 0.000 0.000 0.972 0.004 0.024
#> GSM782714     2  0.0000     0.9552 0.000 1.000 0.000 0.000 0.000
#> GSM782715     4  0.4777     0.5374 0.044 0.000 0.000 0.664 0.292
#> GSM782716     3  0.0162     0.9317 0.000 0.000 0.996 0.004 0.000
#> GSM782717     4  0.4703     0.3340 0.340 0.000 0.000 0.632 0.028
#> GSM782718     4  0.3967     0.5775 0.012 0.000 0.000 0.724 0.264
#> GSM782719     4  0.4063     0.5503 0.280 0.000 0.000 0.708 0.012
#> GSM782720     3  0.0955     0.9325 0.000 0.000 0.968 0.004 0.028
#> GSM782721     1  0.3495     0.8512 0.812 0.000 0.000 0.160 0.028
#> GSM782722     4  0.5714     0.4608 0.108 0.000 0.000 0.580 0.312
#> GSM782723     2  0.2278     0.9356 0.032 0.908 0.000 0.000 0.060
#> GSM782724     2  0.3413     0.9024 0.044 0.832 0.000 0.000 0.124
#> GSM782725     4  0.4040     0.5743 0.012 0.000 0.000 0.712 0.276
#> GSM782726     1  0.5379     0.8719 0.668 0.000 0.000 0.168 0.164
#> GSM782727     3  0.0955     0.9325 0.000 0.000 0.968 0.004 0.028
#> GSM782728     2  0.0000     0.9552 0.000 1.000 0.000 0.000 0.000
#> GSM782729     4  0.1357     0.6809 0.004 0.000 0.000 0.948 0.048
#> GSM782730     3  0.1116     0.9321 0.004 0.000 0.964 0.004 0.028
#> GSM782731     4  0.1041     0.6821 0.004 0.000 0.000 0.964 0.032
#> GSM782732     4  0.1041     0.6821 0.004 0.000 0.000 0.964 0.032
#> GSM782733     3  0.0451     0.9312 0.008 0.000 0.988 0.004 0.000
#> GSM782734     1  0.5379     0.8719 0.668 0.000 0.000 0.168 0.164
#> GSM782735     2  0.2370     0.9286 0.040 0.904 0.000 0.000 0.056
#> GSM782736     4  0.3942     0.5783 0.012 0.000 0.000 0.728 0.260
#> GSM782737     2  0.1668     0.9454 0.032 0.940 0.000 0.000 0.028
#> GSM782738     4  0.4326     0.5698 0.028 0.000 0.000 0.708 0.264
#> GSM782739     4  0.4733     0.3121 0.348 0.000 0.000 0.624 0.028
#> GSM782740     2  0.0000     0.9552 0.000 1.000 0.000 0.000 0.000
#> GSM782741     1  0.2929     0.8523 0.820 0.000 0.000 0.180 0.000
#> GSM782742     3  0.0955     0.9325 0.000 0.000 0.968 0.004 0.028
#> GSM782743     3  0.3750     0.8788 0.060 0.000 0.820 0.004 0.116
#> GSM782744     3  0.4118     0.7805 0.000 0.000 0.660 0.004 0.336
#> GSM782745     1  0.5379     0.8719 0.668 0.000 0.000 0.168 0.164
#> GSM782746     2  0.2370     0.9286 0.040 0.904 0.000 0.000 0.056

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4 p5    p6
#> GSM782696     1  0.0820      0.721 0.972 0.000 0.000 0.012 NA 0.000
#> GSM782697     1  0.0820      0.724 0.972 0.000 0.000 0.000 NA 0.016
#> GSM782698     1  0.1913      0.669 0.908 0.000 0.000 0.080 NA 0.000
#> GSM782699     1  0.0820      0.724 0.972 0.000 0.000 0.000 NA 0.016
#> GSM782700     2  0.0914      0.936 0.000 0.968 0.000 0.016 NA 0.016
#> GSM782701     6  0.6458      0.700 0.212 0.000 0.000 0.028 NA 0.432
#> GSM782702     1  0.3492      0.625 0.788 0.000 0.000 0.004 NA 0.176
#> GSM782703     3  0.2252      0.892 0.000 0.000 0.908 0.028 NA 0.020
#> GSM782704     3  0.4427      0.825 0.000 0.000 0.716 0.136 NA 0.000
#> GSM782705     1  0.2019      0.662 0.900 0.000 0.000 0.088 NA 0.000
#> GSM782706     6  0.6356      0.738 0.164 0.000 0.000 0.036 NA 0.464
#> GSM782707     1  0.3936      0.454 0.688 0.000 0.000 0.024 NA 0.000
#> GSM782708     3  0.4427      0.825 0.000 0.000 0.716 0.136 NA 0.000
#> GSM782709     6  0.2416      0.763 0.156 0.000 0.000 0.000 NA 0.844
#> GSM782710     1  0.1951      0.713 0.908 0.000 0.000 0.000 NA 0.076
#> GSM782711     1  0.0820      0.721 0.972 0.000 0.000 0.012 NA 0.000
#> GSM782712     1  0.5679      0.222 0.552 0.000 0.000 0.024 NA 0.104
#> GSM782713     3  0.0000      0.896 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782714     2  0.0146      0.938 0.000 0.996 0.000 0.000 NA 0.000
#> GSM782715     4  0.4504      0.839 0.296 0.000 0.000 0.652 NA 0.004
#> GSM782716     3  0.1710      0.895 0.000 0.000 0.936 0.016 NA 0.020
#> GSM782717     1  0.3310      0.672 0.816 0.000 0.000 0.020 NA 0.148
#> GSM782718     4  0.3852      0.894 0.384 0.000 0.000 0.612 NA 0.000
#> GSM782719     1  0.4062      0.417 0.660 0.000 0.000 0.024 NA 0.000
#> GSM782720     3  0.0000      0.896 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782721     6  0.6333      0.740 0.160 0.000 0.000 0.036 NA 0.468
#> GSM782722     4  0.4659      0.799 0.252 0.000 0.000 0.668 NA 0.004
#> GSM782723     2  0.2458      0.917 0.000 0.892 0.000 0.016 NA 0.024
#> GSM782724     2  0.4176      0.875 0.000 0.788 0.000 0.076 NA 0.060
#> GSM782725     4  0.4322      0.881 0.372 0.000 0.000 0.600 NA 0.000
#> GSM782726     6  0.2416      0.763 0.156 0.000 0.000 0.000 NA 0.844
#> GSM782727     3  0.0806      0.895 0.000 0.000 0.972 0.008 NA 0.020
#> GSM782728     2  0.0000      0.938 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782729     1  0.3248      0.541 0.804 0.000 0.000 0.164 NA 0.000
#> GSM782730     3  0.0458      0.893 0.000 0.000 0.984 0.016 NA 0.000
#> GSM782731     1  0.2631      0.600 0.840 0.000 0.000 0.152 NA 0.000
#> GSM782732     1  0.2631      0.600 0.840 0.000 0.000 0.152 NA 0.000
#> GSM782733     3  0.2252      0.892 0.000 0.000 0.908 0.028 NA 0.020
#> GSM782734     6  0.2416      0.763 0.156 0.000 0.000 0.000 NA 0.844
#> GSM782735     2  0.2677      0.902 0.000 0.876 0.000 0.016 NA 0.024
#> GSM782736     4  0.3841      0.896 0.380 0.000 0.000 0.616 NA 0.000
#> GSM782737     2  0.2318      0.922 0.000 0.904 0.000 0.020 NA 0.028
#> GSM782738     4  0.3841      0.896 0.380 0.000 0.000 0.616 NA 0.000
#> GSM782739     1  0.2964      0.680 0.836 0.000 0.000 0.012 NA 0.140
#> GSM782740     2  0.0000      0.938 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782741     6  0.6141      0.734 0.192 0.000 0.000 0.016 NA 0.476
#> GSM782742     3  0.0000      0.896 0.000 0.000 1.000 0.000 NA 0.000
#> GSM782743     3  0.4745      0.818 0.000 0.000 0.700 0.144 NA 0.008
#> GSM782744     3  0.4810      0.675 0.000 0.000 0.588 0.040 NA 0.012
#> GSM782745     6  0.2416      0.763 0.156 0.000 0.000 0.000 NA 0.844
#> GSM782746     2  0.2677      0.902 0.000 0.876 0.000 0.016 NA 0.024

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-kmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-ATC-kmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-ATC-kmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-ATC-kmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-ATC-kmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-kmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-ATC-kmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-ATC-kmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-ATC-kmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-ATC-kmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-kmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-ATC-kmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-ATC-kmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-ATC-kmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-ATC-kmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-kmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-ATC-kmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-ATC-kmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-ATC-kmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-ATC-kmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-kmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-kmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-ATC-kmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-ATC-kmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-ATC-kmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-ATC-kmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-kmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> ATC:kmeans 51    0.648 2
#> ATC:kmeans 51    0.642 3
#> ATC:kmeans 41    0.528 4
#> ATC:kmeans 46    0.600 5
#> ATC:kmeans 48    0.495 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:skmeans*

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "skmeans"]
# you can also extract it by
# res = res_list["ATC:skmeans"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'skmeans' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 4.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-skmeans-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-skmeans-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           0.959       0.985         1.0036 0.693   0.563
#> 4 4 0.936           0.966       0.978         0.2613 0.817   0.558
#> 5 5 0.827           0.804       0.884         0.0752 0.928   0.716
#> 6 6 0.846           0.752       0.861         0.0306 0.947   0.734

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 4
#> attr(,"optional")
#> [1] 2 3

There is also optional best \(k\) = 2 3 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1 p2    p3
#> GSM782696     1   0.000      0.999 1.000  0 0.000
#> GSM782697     1   0.000      0.999 1.000  0 0.000
#> GSM782698     1   0.000      0.999 1.000  0 0.000
#> GSM782699     1   0.000      0.999 1.000  0 0.000
#> GSM782700     2   0.000      1.000 0.000  1 0.000
#> GSM782701     1   0.000      0.999 1.000  0 0.000
#> GSM782702     1   0.000      0.999 1.000  0 0.000
#> GSM782703     3   0.000      0.922 0.000  0 1.000
#> GSM782704     3   0.000      0.922 0.000  0 1.000
#> GSM782705     1   0.000      0.999 1.000  0 0.000
#> GSM782706     1   0.000      0.999 1.000  0 0.000
#> GSM782707     1   0.000      0.999 1.000  0 0.000
#> GSM782708     3   0.000      0.922 0.000  0 1.000
#> GSM782709     3   0.619      0.321 0.420  0 0.580
#> GSM782710     1   0.000      0.999 1.000  0 0.000
#> GSM782711     1   0.000      0.999 1.000  0 0.000
#> GSM782712     1   0.000      0.999 1.000  0 0.000
#> GSM782713     3   0.000      0.922 0.000  0 1.000
#> GSM782714     2   0.000      1.000 0.000  1 0.000
#> GSM782715     1   0.000      0.999 1.000  0 0.000
#> GSM782716     3   0.000      0.922 0.000  0 1.000
#> GSM782717     1   0.000      0.999 1.000  0 0.000
#> GSM782718     1   0.000      0.999 1.000  0 0.000
#> GSM782719     1   0.000      0.999 1.000  0 0.000
#> GSM782720     3   0.000      0.922 0.000  0 1.000
#> GSM782721     1   0.000      0.999 1.000  0 0.000
#> GSM782722     1   0.000      0.999 1.000  0 0.000
#> GSM782723     2   0.000      1.000 0.000  1 0.000
#> GSM782724     2   0.000      1.000 0.000  1 0.000
#> GSM782725     1   0.000      0.999 1.000  0 0.000
#> GSM782726     3   0.568      0.557 0.316  0 0.684
#> GSM782727     3   0.000      0.922 0.000  0 1.000
#> GSM782728     2   0.000      1.000 0.000  1 0.000
#> GSM782729     1   0.000      0.999 1.000  0 0.000
#> GSM782730     3   0.000      0.922 0.000  0 1.000
#> GSM782731     1   0.000      0.999 1.000  0 0.000
#> GSM782732     1   0.000      0.999 1.000  0 0.000
#> GSM782733     3   0.000      0.922 0.000  0 1.000
#> GSM782734     1   0.000      0.999 1.000  0 0.000
#> GSM782735     2   0.000      1.000 0.000  1 0.000
#> GSM782736     1   0.000      0.999 1.000  0 0.000
#> GSM782737     2   0.000      1.000 0.000  1 0.000
#> GSM782738     1   0.000      0.999 1.000  0 0.000
#> GSM782739     1   0.000      0.999 1.000  0 0.000
#> GSM782740     2   0.000      1.000 0.000  1 0.000
#> GSM782741     1   0.000      0.999 1.000  0 0.000
#> GSM782742     3   0.000      0.922 0.000  0 1.000
#> GSM782743     3   0.000      0.922 0.000  0 1.000
#> GSM782744     3   0.000      0.922 0.000  0 1.000
#> GSM782745     1   0.103      0.973 0.976  0 0.024
#> GSM782746     2   0.000      1.000 0.000  1 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2 p3    p4
#> GSM782696     1  0.2868      0.883 0.864  0  0 0.136
#> GSM782697     1  0.3444      0.848 0.816  0  0 0.184
#> GSM782698     1  0.0336      0.934 0.992  0  0 0.008
#> GSM782699     1  0.3528      0.839 0.808  0  0 0.192
#> GSM782700     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782701     4  0.0707      0.981 0.020  0  0 0.980
#> GSM782702     4  0.0000      0.987 0.000  0  0 1.000
#> GSM782703     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782704     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782705     1  0.0592      0.934 0.984  0  0 0.016
#> GSM782706     4  0.0592      0.983 0.016  0  0 0.984
#> GSM782707     1  0.2921      0.880 0.860  0  0 0.140
#> GSM782708     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782709     4  0.0000      0.987 0.000  0  0 1.000
#> GSM782710     4  0.0469      0.984 0.012  0  0 0.988
#> GSM782711     1  0.2868      0.883 0.864  0  0 0.136
#> GSM782712     4  0.0921      0.976 0.028  0  0 0.972
#> GSM782713     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782714     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782715     1  0.0000      0.935 1.000  0  0 0.000
#> GSM782716     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782717     4  0.1211      0.957 0.040  0  0 0.960
#> GSM782718     1  0.0000      0.935 1.000  0  0 0.000
#> GSM782719     1  0.2973      0.878 0.856  0  0 0.144
#> GSM782720     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782721     4  0.0469      0.984 0.012  0  0 0.988
#> GSM782722     1  0.0000      0.935 1.000  0  0 0.000
#> GSM782723     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782724     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782725     1  0.0000      0.935 1.000  0  0 0.000
#> GSM782726     4  0.0000      0.987 0.000  0  0 1.000
#> GSM782727     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782728     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782729     1  0.0469      0.933 0.988  0  0 0.012
#> GSM782730     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782731     1  0.0707      0.933 0.980  0  0 0.020
#> GSM782732     1  0.0336      0.934 0.992  0  0 0.008
#> GSM782733     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782734     4  0.0000      0.987 0.000  0  0 1.000
#> GSM782735     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782736     1  0.0000      0.935 1.000  0  0 0.000
#> GSM782737     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782738     1  0.0000      0.935 1.000  0  0 0.000
#> GSM782739     4  0.0469      0.983 0.012  0  0 0.988
#> GSM782740     2  0.0000      1.000 0.000  1  0 0.000
#> GSM782741     4  0.0000      0.987 0.000  0  0 1.000
#> GSM782742     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782743     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782744     3  0.0000      1.000 0.000  0  1 0.000
#> GSM782745     4  0.0000      0.987 0.000  0  0 1.000
#> GSM782746     2  0.0000      1.000 0.000  1  0 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2 p3    p4    p5
#> GSM782696     5  0.2763     0.6265 0.004  0  0 0.148 0.848
#> GSM782697     5  0.4822     0.5850 0.220  0  0 0.076 0.704
#> GSM782698     5  0.4403     0.2840 0.008  0  0 0.384 0.608
#> GSM782699     5  0.4449     0.6148 0.168  0  0 0.080 0.752
#> GSM782700     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782701     1  0.4963     0.6240 0.608  0  0 0.040 0.352
#> GSM782702     1  0.2471     0.7430 0.864  0  0 0.000 0.136
#> GSM782703     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782704     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782705     5  0.4976     0.0128 0.028  0  0 0.468 0.504
#> GSM782706     1  0.4714     0.6521 0.644  0  0 0.032 0.324
#> GSM782707     5  0.4613     0.5340 0.072  0  0 0.200 0.728
#> GSM782708     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782709     1  0.0000     0.7566 1.000  0  0 0.000 0.000
#> GSM782710     5  0.4211     0.3920 0.360  0  0 0.004 0.636
#> GSM782711     5  0.3151     0.6340 0.020  0  0 0.144 0.836
#> GSM782712     1  0.5351     0.4312 0.484  0  0 0.052 0.464
#> GSM782713     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782715     4  0.0703     0.8967 0.000  0  0 0.976 0.024
#> GSM782716     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782717     1  0.4234     0.5571 0.760  0  0 0.056 0.184
#> GSM782718     4  0.1270     0.8958 0.000  0  0 0.948 0.052
#> GSM782719     5  0.4953     0.5037 0.088  0  0 0.216 0.696
#> GSM782720     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782721     1  0.4309     0.6711 0.676  0  0 0.016 0.308
#> GSM782722     4  0.0609     0.8767 0.000  0  0 0.980 0.020
#> GSM782723     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782725     4  0.0703     0.8880 0.000  0  0 0.976 0.024
#> GSM782726     1  0.0000     0.7566 1.000  0  0 0.000 0.000
#> GSM782727     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782729     4  0.3055     0.8097 0.016  0  0 0.840 0.144
#> GSM782730     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782731     4  0.3532     0.8087 0.048  0  0 0.824 0.128
#> GSM782732     4  0.3586     0.7516 0.020  0  0 0.792 0.188
#> GSM782733     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782734     1  0.0162     0.7574 0.996  0  0 0.000 0.004
#> GSM782735     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782736     4  0.0963     0.8999 0.000  0  0 0.964 0.036
#> GSM782737     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782738     4  0.1043     0.8975 0.000  0  0 0.960 0.040
#> GSM782739     1  0.2813     0.6805 0.868  0  0 0.024 0.108
#> GSM782740     2  0.0000     1.0000 0.000  1  0 0.000 0.000
#> GSM782741     1  0.3388     0.7304 0.792  0  0 0.008 0.200
#> GSM782742     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782743     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782744     3  0.0000     1.0000 0.000  0  1 0.000 0.000
#> GSM782745     1  0.0000     0.7566 1.000  0  0 0.000 0.000
#> GSM782746     2  0.0000     1.0000 0.000  1  0 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2 p3    p4    p5    p6
#> GSM782696     1  0.4981     0.3198 0.584  0  0 0.072 0.340 0.004
#> GSM782697     5  0.2407     0.7061 0.048  0  0 0.004 0.892 0.056
#> GSM782698     5  0.3344     0.6548 0.044  0  0 0.152 0.804 0.000
#> GSM782699     5  0.2617     0.6950 0.080  0  0 0.004 0.876 0.040
#> GSM782700     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782701     1  0.3861     0.5242 0.672  0  0 0.004 0.008 0.316
#> GSM782702     6  0.4349     0.5399 0.208  0  0 0.000 0.084 0.708
#> GSM782703     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782704     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782705     5  0.3993     0.3563 0.024  0  0 0.300 0.676 0.000
#> GSM782706     1  0.3940     0.4923 0.652  0  0 0.004 0.008 0.336
#> GSM782707     1  0.4682     0.6056 0.740  0  0 0.064 0.136 0.060
#> GSM782708     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782709     6  0.0000     0.7521 0.000  0  0 0.000 0.000 1.000
#> GSM782710     5  0.5373     0.3551 0.136  0  0 0.000 0.552 0.312
#> GSM782711     1  0.5071    -0.0600 0.488  0  0 0.064 0.444 0.004
#> GSM782712     1  0.3780     0.5923 0.744  0  0 0.004 0.028 0.224
#> GSM782713     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782714     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782715     4  0.2250     0.7964 0.064  0  0 0.896 0.040 0.000
#> GSM782716     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782717     6  0.6197     0.4232 0.124  0  0 0.072 0.236 0.568
#> GSM782718     4  0.2384     0.7950 0.064  0  0 0.888 0.048 0.000
#> GSM782719     1  0.4327     0.6021 0.772  0  0 0.072 0.108 0.048
#> GSM782720     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782721     1  0.3975     0.3849 0.600  0  0 0.000 0.008 0.392
#> GSM782722     4  0.1858     0.7805 0.076  0  0 0.912 0.012 0.000
#> GSM782723     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782724     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782725     4  0.3757     0.7094 0.136  0  0 0.780 0.084 0.000
#> GSM782726     6  0.0000     0.7521 0.000  0  0 0.000 0.000 1.000
#> GSM782727     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782728     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782729     4  0.5144     0.5821 0.120  0  0 0.620 0.256 0.004
#> GSM782730     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782731     4  0.4779     0.6305 0.028  0  0 0.676 0.248 0.048
#> GSM782732     4  0.4576     0.6205 0.044  0  0 0.676 0.264 0.016
#> GSM782733     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782734     6  0.0146     0.7513 0.004  0  0 0.000 0.000 0.996
#> GSM782735     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782736     4  0.1616     0.8034 0.020  0  0 0.932 0.048 0.000
#> GSM782737     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782738     4  0.1794     0.8022 0.036  0  0 0.924 0.040 0.000
#> GSM782739     6  0.4410     0.6123 0.056  0  0 0.020 0.196 0.728
#> GSM782740     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000
#> GSM782741     6  0.4025     0.0234 0.416  0  0 0.000 0.008 0.576
#> GSM782742     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782743     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782744     3  0.0000     1.0000 0.000  0  1 0.000 0.000 0.000
#> GSM782745     6  0.0000     0.7521 0.000  0  0 0.000 0.000 1.000
#> GSM782746     2  0.0000     1.0000 0.000  1  0 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-skmeans-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-ATC-skmeans-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-ATC-skmeans-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-ATC-skmeans-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-ATC-skmeans-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-skmeans-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-ATC-skmeans-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-ATC-skmeans-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-ATC-skmeans-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-ATC-skmeans-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-skmeans-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-ATC-skmeans-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-ATC-skmeans-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-ATC-skmeans-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-ATC-skmeans-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-skmeans-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-ATC-skmeans-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-ATC-skmeans-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-ATC-skmeans-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-ATC-skmeans-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-skmeans-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-skmeans-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-ATC-skmeans-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-ATC-skmeans-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-ATC-skmeans-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-ATC-skmeans-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-skmeans-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>              n agent(p) k
#> ATC:skmeans 51    0.648 2
#> ATC:skmeans 50    0.627 3
#> ATC:skmeans 51    0.567 4
#> ATC:skmeans 47    0.440 5
#> ATC:skmeans 43    0.400 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:pam**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "pam"]
# you can also extract it by
# res = res_list["ATC:pam"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'pam' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-pam-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-pam-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           1.000       1.000         0.9492 0.718   0.599
#> 4 4 0.824           0.880       0.915         0.2560 0.852   0.648
#> 5 5 0.803           0.865       0.919         0.0456 0.973   0.899
#> 6 6 0.819           0.849       0.930         0.0080 0.997   0.987

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette p1 p2 p3
#> GSM782696     1       0          1  1  0  0
#> GSM782697     1       0          1  1  0  0
#> GSM782698     1       0          1  1  0  0
#> GSM782699     1       0          1  1  0  0
#> GSM782700     2       0          1  0  1  0
#> GSM782701     1       0          1  1  0  0
#> GSM782702     1       0          1  1  0  0
#> GSM782703     3       0          1  0  0  1
#> GSM782704     3       0          1  0  0  1
#> GSM782705     1       0          1  1  0  0
#> GSM782706     1       0          1  1  0  0
#> GSM782707     1       0          1  1  0  0
#> GSM782708     3       0          1  0  0  1
#> GSM782709     1       0          1  1  0  0
#> GSM782710     1       0          1  1  0  0
#> GSM782711     1       0          1  1  0  0
#> GSM782712     1       0          1  1  0  0
#> GSM782713     3       0          1  0  0  1
#> GSM782714     2       0          1  0  1  0
#> GSM782715     1       0          1  1  0  0
#> GSM782716     3       0          1  0  0  1
#> GSM782717     1       0          1  1  0  0
#> GSM782718     1       0          1  1  0  0
#> GSM782719     1       0          1  1  0  0
#> GSM782720     3       0          1  0  0  1
#> GSM782721     1       0          1  1  0  0
#> GSM782722     1       0          1  1  0  0
#> GSM782723     2       0          1  0  1  0
#> GSM782724     2       0          1  0  1  0
#> GSM782725     1       0          1  1  0  0
#> GSM782726     1       0          1  1  0  0
#> GSM782727     3       0          1  0  0  1
#> GSM782728     2       0          1  0  1  0
#> GSM782729     1       0          1  1  0  0
#> GSM782730     3       0          1  0  0  1
#> GSM782731     1       0          1  1  0  0
#> GSM782732     1       0          1  1  0  0
#> GSM782733     3       0          1  0  0  1
#> GSM782734     1       0          1  1  0  0
#> GSM782735     2       0          1  0  1  0
#> GSM782736     1       0          1  1  0  0
#> GSM782737     2       0          1  0  1  0
#> GSM782738     1       0          1  1  0  0
#> GSM782739     1       0          1  1  0  0
#> GSM782740     2       0          1  0  1  0
#> GSM782741     1       0          1  1  0  0
#> GSM782742     3       0          1  0  0  1
#> GSM782743     3       0          1  0  0  1
#> GSM782744     3       0          1  0  0  1
#> GSM782745     1       0          1  1  0  0
#> GSM782746     2       0          1  0  1  0

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.4761      0.581 0.628  0 0.000 0.372
#> GSM782697     1  0.4477      0.650 0.688  0 0.000 0.312
#> GSM782698     1  0.3486      0.757 0.812  0 0.000 0.188
#> GSM782699     1  0.4761      0.581 0.628  0 0.000 0.372
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     4  0.3172      0.852 0.160  0 0.000 0.840
#> GSM782702     4  0.1940      0.970 0.076  0 0.000 0.924
#> GSM782703     3  0.1716      0.972 0.000  0 0.936 0.064
#> GSM782704     3  0.1716      0.972 0.000  0 0.936 0.064
#> GSM782705     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782706     4  0.1716      0.977 0.064  0 0.000 0.936
#> GSM782707     1  0.4761      0.581 0.628  0 0.000 0.372
#> GSM782708     3  0.1716      0.972 0.000  0 0.936 0.064
#> GSM782709     4  0.1716      0.977 0.064  0 0.000 0.936
#> GSM782710     1  0.4761      0.581 0.628  0 0.000 0.372
#> GSM782711     1  0.3764      0.738 0.784  0 0.000 0.216
#> GSM782712     1  0.4830      0.541 0.608  0 0.000 0.392
#> GSM782713     3  0.0000      0.977 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782716     3  0.0000      0.977 0.000  0 1.000 0.000
#> GSM782717     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782718     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782719     1  0.3311      0.766 0.828  0 0.000 0.172
#> GSM782720     3  0.0000      0.977 0.000  0 1.000 0.000
#> GSM782721     4  0.1716      0.977 0.064  0 0.000 0.936
#> GSM782722     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782726     4  0.1716      0.977 0.064  0 0.000 0.936
#> GSM782727     3  0.0188      0.977 0.000  0 0.996 0.004
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782730     3  0.0000      0.977 0.000  0 1.000 0.000
#> GSM782731     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782732     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782733     3  0.0817      0.976 0.000  0 0.976 0.024
#> GSM782734     4  0.1792      0.974 0.068  0 0.000 0.932
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.0000      0.822 1.000  0 0.000 0.000
#> GSM782739     1  0.3528      0.738 0.808  0 0.000 0.192
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     4  0.2081      0.962 0.084  0 0.000 0.916
#> GSM782742     3  0.0000      0.977 0.000  0 1.000 0.000
#> GSM782743     3  0.1716      0.972 0.000  0 0.936 0.064
#> GSM782744     3  0.1716      0.972 0.000  0 0.936 0.064
#> GSM782745     4  0.1716      0.977 0.064  0 0.000 0.936
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     4  0.4138      0.602 0.384  0 0.000 0.616 0.000
#> GSM782697     4  0.3895      0.669 0.320  0 0.000 0.680 0.000
#> GSM782698     4  0.3074      0.765 0.196  0 0.000 0.804 0.000
#> GSM782699     4  0.4138      0.602 0.384  0 0.000 0.616 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.1965      0.863 0.904  0 0.000 0.096 0.000
#> GSM782702     1  0.0404      0.970 0.988  0 0.000 0.012 0.000
#> GSM782703     5  0.2561      0.954 0.000  0 0.144 0.000 0.856
#> GSM782704     5  0.2561      0.954 0.000  0 0.144 0.000 0.856
#> GSM782705     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782706     1  0.0000      0.977 1.000  0 0.000 0.000 0.000
#> GSM782707     4  0.4138      0.602 0.384  0 0.000 0.616 0.000
#> GSM782708     5  0.2561      0.954 0.000  0 0.144 0.000 0.856
#> GSM782709     1  0.0000      0.977 1.000  0 0.000 0.000 0.000
#> GSM782710     4  0.4138      0.602 0.384  0 0.000 0.616 0.000
#> GSM782711     4  0.3336      0.745 0.228  0 0.000 0.772 0.000
#> GSM782712     4  0.4249      0.511 0.432  0 0.000 0.568 0.000
#> GSM782713     3  0.0000      0.936 0.000  0 1.000 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782715     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782716     3  0.0000      0.936 0.000  0 1.000 0.000 0.000
#> GSM782717     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782718     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782719     4  0.2966      0.772 0.184  0 0.000 0.816 0.000
#> GSM782720     3  0.0000      0.936 0.000  0 1.000 0.000 0.000
#> GSM782721     1  0.0000      0.977 1.000  0 0.000 0.000 0.000
#> GSM782722     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782725     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782726     1  0.0000      0.977 1.000  0 0.000 0.000 0.000
#> GSM782727     3  0.0963      0.910 0.000  0 0.964 0.000 0.036
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782729     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782730     3  0.0000      0.936 0.000  0 1.000 0.000 0.000
#> GSM782731     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782732     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782733     3  0.3707      0.521 0.000  0 0.716 0.000 0.284
#> GSM782734     1  0.0162      0.974 0.996  0 0.000 0.004 0.000
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782738     4  0.0000      0.827 0.000  0 0.000 1.000 0.000
#> GSM782739     4  0.3039      0.752 0.192  0 0.000 0.808 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.0609      0.963 0.980  0 0.000 0.020 0.000
#> GSM782742     3  0.0000      0.936 0.000  0 1.000 0.000 0.000
#> GSM782743     5  0.2561      0.954 0.000  0 0.144 0.000 0.856
#> GSM782744     5  0.0000      0.827 0.000  0 0.000 0.000 1.000
#> GSM782745     1  0.0000      0.977 1.000  0 0.000 0.000 0.000
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3 p4    p5    p6
#> GSM782696     1  0.3717      0.602 0.616  0 0.000  0 0.000 0.384
#> GSM782697     1  0.3499      0.669 0.680  0 0.000  0 0.000 0.320
#> GSM782698     1  0.2762      0.765 0.804  0 0.000  0 0.000 0.196
#> GSM782699     1  0.3717      0.602 0.616  0 0.000  0 0.000 0.384
#> GSM782700     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782701     6  0.1765      0.845 0.096  0 0.000  0 0.000 0.904
#> GSM782702     6  0.0363      0.965 0.012  0 0.000  0 0.000 0.988
#> GSM782703     5  0.0146      0.994 0.000  0 0.004  0 0.996 0.000
#> GSM782704     5  0.0000      0.998 0.000  0 0.000  0 1.000 0.000
#> GSM782705     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782706     6  0.0000      0.973 0.000  0 0.000  0 0.000 1.000
#> GSM782707     1  0.3717      0.602 0.616  0 0.000  0 0.000 0.384
#> GSM782708     5  0.0000      0.998 0.000  0 0.000  0 1.000 0.000
#> GSM782709     6  0.0000      0.973 0.000  0 0.000  0 0.000 1.000
#> GSM782710     1  0.3717      0.602 0.616  0 0.000  0 0.000 0.384
#> GSM782711     1  0.2996      0.745 0.772  0 0.000  0 0.000 0.228
#> GSM782712     1  0.3817      0.511 0.568  0 0.000  0 0.000 0.432
#> GSM782713     3  0.0000      0.934 0.000  0 1.000  0 0.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782715     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782716     3  0.0000      0.934 0.000  0 1.000  0 0.000 0.000
#> GSM782717     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782718     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782719     1  0.2664      0.772 0.816  0 0.000  0 0.000 0.184
#> GSM782720     3  0.0000      0.934 0.000  0 1.000  0 0.000 0.000
#> GSM782721     6  0.0000      0.973 0.000  0 0.000  0 0.000 1.000
#> GSM782722     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782725     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782726     6  0.0000      0.973 0.000  0 0.000  0 0.000 1.000
#> GSM782727     3  0.0865      0.909 0.000  0 0.964  0 0.036 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782729     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782730     3  0.0000      0.934 0.000  0 1.000  0 0.000 0.000
#> GSM782731     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782732     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782733     3  0.3371      0.590 0.000  0 0.708  0 0.292 0.000
#> GSM782734     6  0.0146      0.970 0.004  0 0.000  0 0.000 0.996
#> GSM782735     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782736     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782738     1  0.0000      0.809 1.000  0 0.000  0 0.000 0.000
#> GSM782739     1  0.2730      0.752 0.808  0 0.000  0 0.000 0.192
#> GSM782740     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000
#> GSM782741     6  0.0547      0.957 0.020  0 0.000  0 0.000 0.980
#> GSM782742     3  0.0000      0.934 0.000  0 1.000  0 0.000 0.000
#> GSM782743     5  0.0000      0.998 0.000  0 0.000  0 1.000 0.000
#> GSM782744     4  0.0000      0.000 0.000  0 0.000  1 0.000 0.000
#> GSM782745     6  0.0000      0.973 0.000  0 0.000  0 0.000 1.000
#> GSM782746     2  0.0000      1.000 0.000  1 0.000  0 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-pam-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-ATC-pam-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-ATC-pam-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-ATC-pam-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-ATC-pam-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-pam-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-ATC-pam-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-ATC-pam-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-ATC-pam-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-ATC-pam-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-pam-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-ATC-pam-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-ATC-pam-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-ATC-pam-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-ATC-pam-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-pam-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-ATC-pam-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-ATC-pam-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-ATC-pam-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-ATC-pam-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-pam-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-pam-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-ATC-pam-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-ATC-pam-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-ATC-pam-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-ATC-pam-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-pam-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) k
#> ATC:pam 51    0.648 2
#> ATC:pam 51    0.642 3
#> ATC:pam 51    0.623 4
#> ATC:pam 51    0.626 5
#> ATC:pam 50    0.522 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:mclust**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "mclust"]
# you can also extract it by
# res = res_list["ATC:mclust"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'mclust' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-mclust-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-mclust-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           0.964       0.977         0.3160 0.704   0.704
#> 3 3 1.000           0.999       1.000         0.8338 0.718   0.599
#> 4 4 0.833           0.883       0.925         0.1723 0.936   0.849
#> 5 5 0.796           0.781       0.877         0.0820 0.920   0.779
#> 6 6 0.774           0.829       0.886         0.0786 0.892   0.637

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette    p1    p2
#> GSM782696     1   0.000      0.971 1.000 0.000
#> GSM782697     1   0.000      0.971 1.000 0.000
#> GSM782698     1   0.000      0.971 1.000 0.000
#> GSM782699     1   0.000      0.971 1.000 0.000
#> GSM782700     2   0.000      1.000 0.000 1.000
#> GSM782701     1   0.000      0.971 1.000 0.000
#> GSM782702     1   0.000      0.971 1.000 0.000
#> GSM782703     1   0.456      0.922 0.904 0.096
#> GSM782704     1   0.456      0.922 0.904 0.096
#> GSM782705     1   0.000      0.971 1.000 0.000
#> GSM782706     1   0.000      0.971 1.000 0.000
#> GSM782707     1   0.000      0.971 1.000 0.000
#> GSM782708     1   0.456      0.922 0.904 0.096
#> GSM782709     1   0.000      0.971 1.000 0.000
#> GSM782710     1   0.000      0.971 1.000 0.000
#> GSM782711     1   0.000      0.971 1.000 0.000
#> GSM782712     1   0.000      0.971 1.000 0.000
#> GSM782713     1   0.456      0.922 0.904 0.096
#> GSM782714     2   0.000      1.000 0.000 1.000
#> GSM782715     1   0.000      0.971 1.000 0.000
#> GSM782716     1   0.456      0.922 0.904 0.096
#> GSM782717     1   0.000      0.971 1.000 0.000
#> GSM782718     1   0.000      0.971 1.000 0.000
#> GSM782719     1   0.000      0.971 1.000 0.000
#> GSM782720     1   0.456      0.922 0.904 0.096
#> GSM782721     1   0.000      0.971 1.000 0.000
#> GSM782722     1   0.000      0.971 1.000 0.000
#> GSM782723     2   0.000      1.000 0.000 1.000
#> GSM782724     2   0.000      1.000 0.000 1.000
#> GSM782725     1   0.000      0.971 1.000 0.000
#> GSM782726     1   0.000      0.971 1.000 0.000
#> GSM782727     1   0.456      0.922 0.904 0.096
#> GSM782728     2   0.000      1.000 0.000 1.000
#> GSM782729     1   0.000      0.971 1.000 0.000
#> GSM782730     1   0.456      0.922 0.904 0.096
#> GSM782731     1   0.000      0.971 1.000 0.000
#> GSM782732     1   0.000      0.971 1.000 0.000
#> GSM782733     1   0.456      0.922 0.904 0.096
#> GSM782734     1   0.000      0.971 1.000 0.000
#> GSM782735     2   0.000      1.000 0.000 1.000
#> GSM782736     1   0.000      0.971 1.000 0.000
#> GSM782737     2   0.000      1.000 0.000 1.000
#> GSM782738     1   0.000      0.971 1.000 0.000
#> GSM782739     1   0.000      0.971 1.000 0.000
#> GSM782740     2   0.000      1.000 0.000 1.000
#> GSM782741     1   0.000      0.971 1.000 0.000
#> GSM782742     1   0.456      0.922 0.904 0.096
#> GSM782743     1   0.456      0.922 0.904 0.096
#> GSM782744     1   0.456      0.922 0.904 0.096
#> GSM782745     1   0.000      0.971 1.000 0.000
#> GSM782746     2   0.000      1.000 0.000 1.000

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1 p2    p3
#> GSM782696     1  0.0000      0.999 1.000  0 0.000
#> GSM782697     1  0.0000      0.999 1.000  0 0.000
#> GSM782698     1  0.0000      0.999 1.000  0 0.000
#> GSM782699     1  0.0000      0.999 1.000  0 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000
#> GSM782701     1  0.0000      0.999 1.000  0 0.000
#> GSM782702     1  0.0000      0.999 1.000  0 0.000
#> GSM782703     3  0.0000      1.000 0.000  0 1.000
#> GSM782704     3  0.0000      1.000 0.000  0 1.000
#> GSM782705     1  0.0000      0.999 1.000  0 0.000
#> GSM782706     1  0.0000      0.999 1.000  0 0.000
#> GSM782707     1  0.0000      0.999 1.000  0 0.000
#> GSM782708     3  0.0000      1.000 0.000  0 1.000
#> GSM782709     1  0.0000      0.999 1.000  0 0.000
#> GSM782710     1  0.0000      0.999 1.000  0 0.000
#> GSM782711     1  0.0000      0.999 1.000  0 0.000
#> GSM782712     1  0.0000      0.999 1.000  0 0.000
#> GSM782713     3  0.0000      1.000 0.000  0 1.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000
#> GSM782715     1  0.0424      0.992 0.992  0 0.008
#> GSM782716     3  0.0000      1.000 0.000  0 1.000
#> GSM782717     1  0.0000      0.999 1.000  0 0.000
#> GSM782718     1  0.0000      0.999 1.000  0 0.000
#> GSM782719     1  0.0000      0.999 1.000  0 0.000
#> GSM782720     3  0.0000      1.000 0.000  0 1.000
#> GSM782721     1  0.0000      0.999 1.000  0 0.000
#> GSM782722     1  0.0424      0.992 0.992  0 0.008
#> GSM782723     2  0.0000      1.000 0.000  1 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000
#> GSM782725     1  0.0000      0.999 1.000  0 0.000
#> GSM782726     1  0.0000      0.999 1.000  0 0.000
#> GSM782727     3  0.0000      1.000 0.000  0 1.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000
#> GSM782729     1  0.0000      0.999 1.000  0 0.000
#> GSM782730     3  0.0000      1.000 0.000  0 1.000
#> GSM782731     1  0.0000      0.999 1.000  0 0.000
#> GSM782732     1  0.0000      0.999 1.000  0 0.000
#> GSM782733     3  0.0000      1.000 0.000  0 1.000
#> GSM782734     1  0.0000      0.999 1.000  0 0.000
#> GSM782735     2  0.0000      1.000 0.000  1 0.000
#> GSM782736     1  0.0000      0.999 1.000  0 0.000
#> GSM782737     2  0.0000      1.000 0.000  1 0.000
#> GSM782738     1  0.0000      0.999 1.000  0 0.000
#> GSM782739     1  0.0000      0.999 1.000  0 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000
#> GSM782741     1  0.0000      0.999 1.000  0 0.000
#> GSM782742     3  0.0000      1.000 0.000  0 1.000
#> GSM782743     3  0.0000      1.000 0.000  0 1.000
#> GSM782744     3  0.0000      1.000 0.000  0 1.000
#> GSM782745     1  0.0000      0.999 1.000  0 0.000
#> GSM782746     2  0.0000      1.000 0.000  1 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1 p2    p3    p4
#> GSM782696     1  0.3649      0.792 0.796  0 0.000 0.204
#> GSM782697     1  0.1940      0.838 0.924  0 0.000 0.076
#> GSM782698     1  0.4776      0.613 0.624  0 0.000 0.376
#> GSM782699     1  0.3726      0.788 0.788  0 0.000 0.212
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782701     1  0.0592      0.839 0.984  0 0.000 0.016
#> GSM782702     1  0.0188      0.844 0.996  0 0.000 0.004
#> GSM782703     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782704     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782705     1  0.3942      0.774 0.764  0 0.000 0.236
#> GSM782706     1  0.0921      0.836 0.972  0 0.000 0.028
#> GSM782707     1  0.3172      0.811 0.840  0 0.000 0.160
#> GSM782708     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782709     1  0.0707      0.840 0.980  0 0.000 0.020
#> GSM782710     1  0.1302      0.843 0.956  0 0.000 0.044
#> GSM782711     1  0.3649      0.792 0.796  0 0.000 0.204
#> GSM782712     1  0.0188      0.844 0.996  0 0.000 0.004
#> GSM782713     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782715     4  0.0707      0.940 0.020  0 0.000 0.980
#> GSM782716     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782717     1  0.0707      0.845 0.980  0 0.000 0.020
#> GSM782718     1  0.4585      0.664 0.668  0 0.000 0.332
#> GSM782719     1  0.0000      0.843 1.000  0 0.000 0.000
#> GSM782720     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782721     1  0.0817      0.836 0.976  0 0.000 0.024
#> GSM782722     4  0.0707      0.940 0.020  0 0.000 0.980
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782725     1  0.4103      0.761 0.744  0 0.000 0.256
#> GSM782726     1  0.0707      0.840 0.980  0 0.000 0.020
#> GSM782727     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782729     1  0.4605      0.674 0.664  0 0.000 0.336
#> GSM782730     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782731     1  0.4605      0.674 0.664  0 0.000 0.336
#> GSM782732     1  0.4222      0.737 0.728  0 0.000 0.272
#> GSM782733     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782734     1  0.0592      0.839 0.984  0 0.000 0.016
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782736     4  0.2345      0.880 0.100  0 0.000 0.900
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782738     1  0.4790      0.606 0.620  0 0.000 0.380
#> GSM782739     1  0.0336      0.844 0.992  0 0.000 0.008
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000
#> GSM782741     1  0.0592      0.839 0.984  0 0.000 0.016
#> GSM782742     3  0.0000      0.999 0.000  0 1.000 0.000
#> GSM782743     3  0.0336      0.994 0.000  0 0.992 0.008
#> GSM782744     3  0.0336      0.994 0.000  0 0.992 0.008
#> GSM782745     1  0.0592      0.839 0.984  0 0.000 0.016
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1 p2    p3    p4    p5
#> GSM782696     1  0.1697    0.77211 0.932  0 0.000 0.060 0.008
#> GSM782697     1  0.1205    0.77501 0.956  0 0.000 0.040 0.004
#> GSM782698     1  0.6282    0.26106 0.536  0 0.000 0.248 0.216
#> GSM782699     1  0.1430    0.77252 0.944  0 0.000 0.052 0.004
#> GSM782700     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782701     1  0.2561    0.71397 0.856  0 0.000 0.000 0.144
#> GSM782702     1  0.0162    0.76442 0.996  0 0.000 0.000 0.004
#> GSM782703     3  0.0162    0.98382 0.000  0 0.996 0.000 0.004
#> GSM782704     3  0.0162    0.98382 0.000  0 0.996 0.004 0.000
#> GSM782705     1  0.4164    0.69698 0.784  0 0.000 0.096 0.120
#> GSM782706     1  0.3141    0.71176 0.832  0 0.000 0.016 0.152
#> GSM782707     1  0.3734    0.72748 0.812  0 0.000 0.060 0.128
#> GSM782708     3  0.0162    0.98382 0.000  0 0.996 0.004 0.000
#> GSM782709     5  0.3913    1.00000 0.324  0 0.000 0.000 0.676
#> GSM782710     1  0.1282    0.77427 0.952  0 0.000 0.044 0.004
#> GSM782711     1  0.1697    0.77211 0.932  0 0.000 0.060 0.008
#> GSM782712     1  0.0162    0.76438 0.996  0 0.000 0.000 0.004
#> GSM782713     3  0.0162    0.98382 0.000  0 0.996 0.004 0.000
#> GSM782714     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782715     4  0.0290    0.53855 0.008  0 0.000 0.992 0.000
#> GSM782716     3  0.0324    0.98378 0.000  0 0.992 0.004 0.004
#> GSM782717     1  0.1300    0.76949 0.956  0 0.000 0.016 0.028
#> GSM782718     4  0.6652    0.28900 0.348  0 0.000 0.420 0.232
#> GSM782719     1  0.1981    0.76772 0.920  0 0.000 0.016 0.064
#> GSM782720     3  0.0451    0.98368 0.000  0 0.988 0.004 0.008
#> GSM782721     1  0.3039    0.70679 0.836  0 0.000 0.012 0.152
#> GSM782722     4  0.0404    0.54224 0.012  0 0.000 0.988 0.000
#> GSM782723     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782724     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782725     1  0.4985    0.58186 0.680  0 0.000 0.076 0.244
#> GSM782726     5  0.3913    1.00000 0.324  0 0.000 0.000 0.676
#> GSM782727     3  0.0162    0.98382 0.000  0 0.996 0.000 0.004
#> GSM782728     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782729     1  0.5775    0.47060 0.608  0 0.000 0.148 0.244
#> GSM782730     3  0.0324    0.98378 0.000  0 0.992 0.004 0.004
#> GSM782731     1  0.5941    0.42827 0.588  0 0.000 0.168 0.244
#> GSM782732     1  0.5628    0.51886 0.632  0 0.000 0.148 0.220
#> GSM782733     3  0.0162    0.98382 0.000  0 0.996 0.000 0.004
#> GSM782734     1  0.2377    0.67211 0.872  0 0.000 0.000 0.128
#> GSM782735     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782736     4  0.3035    0.56200 0.032  0 0.000 0.856 0.112
#> GSM782737     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782738     4  0.6652    0.28995 0.348  0 0.000 0.420 0.232
#> GSM782739     1  0.0290    0.76299 0.992  0 0.000 0.000 0.008
#> GSM782740     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000
#> GSM782741     1  0.1410    0.73690 0.940  0 0.000 0.000 0.060
#> GSM782742     3  0.0451    0.98368 0.000  0 0.988 0.004 0.008
#> GSM782743     3  0.1914    0.94368 0.000  0 0.924 0.016 0.060
#> GSM782744     3  0.2046    0.93792 0.000  0 0.916 0.016 0.068
#> GSM782745     1  0.4015   -0.00892 0.652  0 0.000 0.000 0.348
#> GSM782746     2  0.0000    1.00000 0.000  1 0.000 0.000 0.000

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1 p2    p3    p4    p5    p6
#> GSM782696     1  0.2416      0.776 0.844  0 0.000 0.156 0.000 0.000
#> GSM782697     1  0.0790      0.859 0.968  0 0.000 0.032 0.000 0.000
#> GSM782698     4  0.2489      0.811 0.128  0 0.000 0.860 0.012 0.000
#> GSM782699     1  0.1204      0.853 0.944  0 0.000 0.056 0.000 0.000
#> GSM782700     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782701     1  0.2221      0.844 0.896  0 0.000 0.072 0.000 0.032
#> GSM782702     1  0.0260      0.857 0.992  0 0.000 0.008 0.000 0.000
#> GSM782703     3  0.0260      0.918 0.000  0 0.992 0.000 0.000 0.008
#> GSM782704     3  0.3268      0.845 0.000  0 0.808 0.020 0.164 0.008
#> GSM782705     4  0.3330      0.699 0.284  0 0.000 0.716 0.000 0.000
#> GSM782706     1  0.2361      0.841 0.884  0 0.000 0.088 0.000 0.028
#> GSM782707     1  0.3464      0.591 0.688  0 0.000 0.312 0.000 0.000
#> GSM782708     3  0.3268      0.845 0.000  0 0.808 0.020 0.164 0.008
#> GSM782709     6  0.0713      0.700 0.028  0 0.000 0.000 0.000 0.972
#> GSM782710     1  0.0458      0.859 0.984  0 0.000 0.016 0.000 0.000
#> GSM782711     1  0.2416      0.776 0.844  0 0.000 0.156 0.000 0.000
#> GSM782712     1  0.0547      0.862 0.980  0 0.000 0.020 0.000 0.000
#> GSM782713     3  0.0146      0.919 0.000  0 0.996 0.000 0.000 0.004
#> GSM782714     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782715     5  0.3126      0.868 0.000  0 0.000 0.248 0.752 0.000
#> GSM782716     3  0.0146      0.919 0.000  0 0.996 0.000 0.000 0.004
#> GSM782717     1  0.2020      0.844 0.896  0 0.000 0.096 0.000 0.008
#> GSM782718     4  0.3950      0.343 0.040  0 0.000 0.720 0.240 0.000
#> GSM782719     1  0.3215      0.725 0.756  0 0.000 0.240 0.000 0.004
#> GSM782720     3  0.0146      0.919 0.000  0 0.996 0.000 0.000 0.004
#> GSM782721     1  0.2733      0.826 0.864  0 0.000 0.080 0.000 0.056
#> GSM782722     5  0.3175      0.871 0.000  0 0.000 0.256 0.744 0.000
#> GSM782723     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782724     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782725     4  0.2673      0.798 0.132  0 0.000 0.852 0.004 0.012
#> GSM782726     6  0.0713      0.700 0.028  0 0.000 0.000 0.000 0.972
#> GSM782727     3  0.0146      0.919 0.000  0 0.996 0.000 0.000 0.004
#> GSM782728     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782729     4  0.2219      0.827 0.136  0 0.000 0.864 0.000 0.000
#> GSM782730     3  0.0291      0.918 0.000  0 0.992 0.000 0.004 0.004
#> GSM782731     4  0.2340      0.826 0.148  0 0.000 0.852 0.000 0.000
#> GSM782732     4  0.2527      0.814 0.168  0 0.000 0.832 0.000 0.000
#> GSM782733     3  0.0146      0.919 0.000  0 0.996 0.000 0.000 0.004
#> GSM782734     1  0.3288      0.498 0.724  0 0.000 0.000 0.000 0.276
#> GSM782735     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782736     5  0.4502      0.689 0.016  0 0.000 0.404 0.568 0.012
#> GSM782737     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782738     4  0.3253      0.680 0.068  0 0.000 0.832 0.096 0.004
#> GSM782739     1  0.0260      0.857 0.992  0 0.000 0.008 0.000 0.000
#> GSM782740     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000
#> GSM782741     1  0.0972      0.859 0.964  0 0.000 0.028 0.000 0.008
#> GSM782742     3  0.0000      0.919 0.000  0 1.000 0.000 0.000 0.000
#> GSM782743     3  0.4176      0.776 0.000  0 0.708 0.044 0.244 0.004
#> GSM782744     3  0.4176      0.772 0.000  0 0.708 0.044 0.244 0.004
#> GSM782745     6  0.3684      0.364 0.372  0 0.000 0.000 0.000 0.628
#> GSM782746     2  0.0000      1.000 0.000  1 0.000 0.000 0.000 0.000

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-mclust-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-ATC-mclust-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-ATC-mclust-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-ATC-mclust-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-ATC-mclust-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-mclust-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-ATC-mclust-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-ATC-mclust-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-ATC-mclust-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-ATC-mclust-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-mclust-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-ATC-mclust-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-ATC-mclust-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-ATC-mclust-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-ATC-mclust-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-mclust-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-ATC-mclust-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-ATC-mclust-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-ATC-mclust-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-ATC-mclust-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-mclust-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-mclust-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-ATC-mclust-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-ATC-mclust-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-ATC-mclust-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-ATC-mclust-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-mclust-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>             n agent(p) k
#> ATC:mclust 51    0.648 2
#> ATC:mclust 51    0.642 3
#> ATC:mclust 51    0.502 4
#> ATC:mclust 45    0.395 5
#> ATC:mclust 48    0.384 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.


ATC:NMF**

The object with results only for a single top-value method and a single partition method can be extracted as:

res = res_list["ATC", "NMF"]
# you can also extract it by
# res = res_list["ATC:NMF"]

A summary of res and all the functions that can be applied to it:

res
#> A 'ConsensusPartition' object with k = 2, 3, 4, 5, 6.
#>   On a matrix with 51941 rows and 51 columns.
#>   Top rows (1000, 2000, 3000, 4000, 5000) are extracted by 'ATC' method.
#>   Subgroups are detected by 'NMF' method.
#>   Performed in total 1250 partitions by row resampling.
#>   Best k for subgroups seems to be 3.
#> 
#> Following methods can be applied to this 'ConsensusPartition' object:
#>  [1] "cola_report"             "collect_classes"         "collect_plots"          
#>  [4] "collect_stats"           "colnames"                "compare_signatures"     
#>  [7] "consensus_heatmap"       "dimension_reduction"     "functional_enrichment"  
#> [10] "get_anno_col"            "get_anno"                "get_classes"            
#> [13] "get_consensus"           "get_matrix"              "get_membership"         
#> [16] "get_param"               "get_signatures"          "get_stats"              
#> [19] "is_best_k"               "is_stable_k"             "membership_heatmap"     
#> [22] "ncol"                    "nrow"                    "plot_ecdf"              
#> [25] "rownames"                "select_partition_number" "show"                   
#> [28] "suggest_best_k"          "test_to_known_factors"

collect_plots() function collects all the plots made from res for all k (number of partitions) into one single page to provide an easy and fast comparison between different k.

collect_plots(res)

plot of chunk ATC-NMF-collect-plots

The plots are:

All the plots in panels can be made by individual functions and they are plotted later in this section.

select_partition_number() produces several plots showing different statistics for choosing “optimized” k. There are following statistics:

The detailed explanations of these statistics can be found in the cola vignette.

Generally speaking, lower PAC score, higher mean silhouette score or higher concordance corresponds to better partition. Rand index and Jaccard index measure how similar the current partition is compared to partition with k-1. If they are too similar, we won't accept k is better than k-1.

select_partition_number(res)

plot of chunk ATC-NMF-select-partition-number

The numeric values for all these statistics can be obtained by get_stats().

get_stats(res)
#>   k 1-PAC mean_silhouette concordance area_increased  Rand Jaccard
#> 2 2 1.000           1.000       1.000         0.2972 0.704   0.704
#> 3 3 1.000           0.998       0.999         0.9516 0.718   0.599
#> 4 4 0.778           0.887       0.904         0.1348 1.000   1.000
#> 5 5 0.689           0.701       0.848         0.0747 0.902   0.767
#> 6 6 0.682           0.673       0.813         0.0459 0.956   0.867

suggest_best_k() suggests the best \(k\) based on these statistics. The rules are as follows:

suggest_best_k(res)
#> [1] 3
#> attr(,"optional")
#> [1] 2

There is also optional best \(k\) = 2 that is worth to check.

Following shows the table of the partitions (You need to click the show/hide code output link to see it). The membership matrix (columns with name p*) is inferred by clue::cl_consensus() function with the SE method. Basically the value in the membership matrix represents the probability to belong to a certain group. The finall class label for an item is determined with the group with highest probability it belongs to.

In get_classes() function, the entropy is calculated from the membership matrix and the silhouette score is calculated from the consensus matrix.

show/hide code output

cbind(get_classes(res, k = 2), get_membership(res, k = 2))
#>           class entropy silhouette p1 p2
#> GSM782696     1       0          1  1  0
#> GSM782697     1       0          1  1  0
#> GSM782698     1       0          1  1  0
#> GSM782699     1       0          1  1  0
#> GSM782700     2       0          1  0  1
#> GSM782701     1       0          1  1  0
#> GSM782702     1       0          1  1  0
#> GSM782703     1       0          1  1  0
#> GSM782704     1       0          1  1  0
#> GSM782705     1       0          1  1  0
#> GSM782706     1       0          1  1  0
#> GSM782707     1       0          1  1  0
#> GSM782708     1       0          1  1  0
#> GSM782709     1       0          1  1  0
#> GSM782710     1       0          1  1  0
#> GSM782711     1       0          1  1  0
#> GSM782712     1       0          1  1  0
#> GSM782713     1       0          1  1  0
#> GSM782714     2       0          1  0  1
#> GSM782715     1       0          1  1  0
#> GSM782716     1       0          1  1  0
#> GSM782717     1       0          1  1  0
#> GSM782718     1       0          1  1  0
#> GSM782719     1       0          1  1  0
#> GSM782720     1       0          1  1  0
#> GSM782721     1       0          1  1  0
#> GSM782722     1       0          1  1  0
#> GSM782723     2       0          1  0  1
#> GSM782724     2       0          1  0  1
#> GSM782725     1       0          1  1  0
#> GSM782726     1       0          1  1  0
#> GSM782727     1       0          1  1  0
#> GSM782728     2       0          1  0  1
#> GSM782729     1       0          1  1  0
#> GSM782730     1       0          1  1  0
#> GSM782731     1       0          1  1  0
#> GSM782732     1       0          1  1  0
#> GSM782733     1       0          1  1  0
#> GSM782734     1       0          1  1  0
#> GSM782735     2       0          1  0  1
#> GSM782736     1       0          1  1  0
#> GSM782737     2       0          1  0  1
#> GSM782738     1       0          1  1  0
#> GSM782739     1       0          1  1  0
#> GSM782740     2       0          1  0  1
#> GSM782741     1       0          1  1  0
#> GSM782742     1       0          1  1  0
#> GSM782743     1       0          1  1  0
#> GSM782744     1       0          1  1  0
#> GSM782745     1       0          1  1  0
#> GSM782746     2       0          1  0  1

show/hide code output

cbind(get_classes(res, k = 3), get_membership(res, k = 3))
#>           class entropy silhouette    p1 p2    p3
#> GSM782696     1   0.000      0.998 1.000  0 0.000
#> GSM782697     1   0.000      0.998 1.000  0 0.000
#> GSM782698     1   0.000      0.998 1.000  0 0.000
#> GSM782699     1   0.000      0.998 1.000  0 0.000
#> GSM782700     2   0.000      1.000 0.000  1 0.000
#> GSM782701     1   0.000      0.998 1.000  0 0.000
#> GSM782702     1   0.000      0.998 1.000  0 0.000
#> GSM782703     3   0.000      1.000 0.000  0 1.000
#> GSM782704     3   0.000      1.000 0.000  0 1.000
#> GSM782705     1   0.000      0.998 1.000  0 0.000
#> GSM782706     1   0.000      0.998 1.000  0 0.000
#> GSM782707     1   0.000      0.998 1.000  0 0.000
#> GSM782708     3   0.000      1.000 0.000  0 1.000
#> GSM782709     1   0.000      0.998 1.000  0 0.000
#> GSM782710     1   0.000      0.998 1.000  0 0.000
#> GSM782711     1   0.000      0.998 1.000  0 0.000
#> GSM782712     1   0.000      0.998 1.000  0 0.000
#> GSM782713     3   0.000      1.000 0.000  0 1.000
#> GSM782714     2   0.000      1.000 0.000  1 0.000
#> GSM782715     1   0.000      0.998 1.000  0 0.000
#> GSM782716     3   0.000      1.000 0.000  0 1.000
#> GSM782717     1   0.000      0.998 1.000  0 0.000
#> GSM782718     1   0.000      0.998 1.000  0 0.000
#> GSM782719     1   0.000      0.998 1.000  0 0.000
#> GSM782720     3   0.000      1.000 0.000  0 1.000
#> GSM782721     1   0.000      0.998 1.000  0 0.000
#> GSM782722     1   0.000      0.998 1.000  0 0.000
#> GSM782723     2   0.000      1.000 0.000  1 0.000
#> GSM782724     2   0.000      1.000 0.000  1 0.000
#> GSM782725     1   0.000      0.998 1.000  0 0.000
#> GSM782726     1   0.196      0.939 0.944  0 0.056
#> GSM782727     3   0.000      1.000 0.000  0 1.000
#> GSM782728     2   0.000      1.000 0.000  1 0.000
#> GSM782729     1   0.000      0.998 1.000  0 0.000
#> GSM782730     3   0.000      1.000 0.000  0 1.000
#> GSM782731     1   0.000      0.998 1.000  0 0.000
#> GSM782732     1   0.000      0.998 1.000  0 0.000
#> GSM782733     3   0.000      1.000 0.000  0 1.000
#> GSM782734     1   0.000      0.998 1.000  0 0.000
#> GSM782735     2   0.000      1.000 0.000  1 0.000
#> GSM782736     1   0.000      0.998 1.000  0 0.000
#> GSM782737     2   0.000      1.000 0.000  1 0.000
#> GSM782738     1   0.000      0.998 1.000  0 0.000
#> GSM782739     1   0.000      0.998 1.000  0 0.000
#> GSM782740     2   0.000      1.000 0.000  1 0.000
#> GSM782741     1   0.000      0.998 1.000  0 0.000
#> GSM782742     3   0.000      1.000 0.000  0 1.000
#> GSM782743     3   0.000      1.000 0.000  0 1.000
#> GSM782744     3   0.000      1.000 0.000  0 1.000
#> GSM782745     1   0.000      0.998 1.000  0 0.000
#> GSM782746     2   0.000      1.000 0.000  1 0.000

show/hide code output

cbind(get_classes(res, k = 4), get_membership(res, k = 4))
#>           class entropy silhouette    p1    p2    p3 p4
#> GSM782696     1  0.0707      0.863 0.980 0.000 0.000 NA
#> GSM782697     1  0.1118      0.864 0.964 0.000 0.000 NA
#> GSM782698     1  0.4697      0.738 0.644 0.000 0.000 NA
#> GSM782699     1  0.0592      0.863 0.984 0.000 0.000 NA
#> GSM782700     2  0.0000      0.999 0.000 1.000 0.000 NA
#> GSM782701     1  0.1792      0.852 0.932 0.000 0.000 NA
#> GSM782702     1  0.1474      0.852 0.948 0.000 0.000 NA
#> GSM782703     3  0.0336      0.992 0.000 0.000 0.992 NA
#> GSM782704     3  0.0336      0.992 0.000 0.000 0.992 NA
#> GSM782705     1  0.3569      0.832 0.804 0.000 0.000 NA
#> GSM782706     1  0.2345      0.844 0.900 0.000 0.000 NA
#> GSM782707     1  0.2408      0.856 0.896 0.000 0.000 NA
#> GSM782708     3  0.0336      0.992 0.000 0.000 0.992 NA
#> GSM782709     1  0.4155      0.735 0.756 0.000 0.004 NA
#> GSM782710     1  0.0592      0.862 0.984 0.000 0.000 NA
#> GSM782711     1  0.1022      0.864 0.968 0.000 0.000 NA
#> GSM782712     1  0.1302      0.855 0.956 0.000 0.000 NA
#> GSM782713     3  0.0000      0.994 0.000 0.000 1.000 NA
#> GSM782714     2  0.0188      0.998 0.000 0.996 0.000 NA
#> GSM782715     1  0.4999      0.615 0.508 0.000 0.000 NA
#> GSM782716     3  0.0000      0.994 0.000 0.000 1.000 NA
#> GSM782717     1  0.0469      0.863 0.988 0.000 0.000 NA
#> GSM782718     1  0.4643      0.752 0.656 0.000 0.000 NA
#> GSM782719     1  0.1940      0.861 0.924 0.000 0.000 NA
#> GSM782720     3  0.0000      0.994 0.000 0.000 1.000 NA
#> GSM782721     1  0.3266      0.808 0.832 0.000 0.000 NA
#> GSM782722     1  0.4925      0.683 0.572 0.000 0.000 NA
#> GSM782723     2  0.0188      0.998 0.000 0.996 0.000 NA
#> GSM782724     2  0.0188      0.998 0.000 0.996 0.000 NA
#> GSM782725     1  0.3569      0.833 0.804 0.000 0.000 NA
#> GSM782726     1  0.5464      0.695 0.716 0.000 0.072 NA
#> GSM782727     3  0.0000      0.994 0.000 0.000 1.000 NA
#> GSM782728     2  0.0000      0.999 0.000 1.000 0.000 NA
#> GSM782729     1  0.4072      0.807 0.748 0.000 0.000 NA
#> GSM782730     3  0.0469      0.990 0.000 0.000 0.988 NA
#> GSM782731     1  0.3486      0.836 0.812 0.000 0.000 NA
#> GSM782732     1  0.3528      0.833 0.808 0.000 0.000 NA
#> GSM782733     3  0.0000      0.994 0.000 0.000 1.000 NA
#> GSM782734     1  0.2408      0.835 0.896 0.000 0.000 NA
#> GSM782735     2  0.0000      0.999 0.000 1.000 0.000 NA
#> GSM782736     1  0.4776      0.728 0.624 0.000 0.000 NA
#> GSM782737     2  0.0188      0.998 0.000 0.996 0.000 NA
#> GSM782738     1  0.3975      0.814 0.760 0.000 0.000 NA
#> GSM782739     1  0.0469      0.860 0.988 0.000 0.000 NA
#> GSM782740     2  0.0000      0.999 0.000 1.000 0.000 NA
#> GSM782741     1  0.1792      0.847 0.932 0.000 0.000 NA
#> GSM782742     3  0.0188      0.993 0.000 0.000 0.996 NA
#> GSM782743     3  0.0707      0.985 0.000 0.000 0.980 NA
#> GSM782744     3  0.0921      0.982 0.000 0.000 0.972 NA
#> GSM782745     1  0.2760      0.824 0.872 0.000 0.000 NA
#> GSM782746     2  0.0000      0.999 0.000 1.000 0.000 NA

show/hide code output

cbind(get_classes(res, k = 5), get_membership(res, k = 5))
#>           class entropy silhouette    p1    p2    p3    p4 p5
#> GSM782696     1  0.2962     0.6499 0.868 0.000 0.000 0.084 NA
#> GSM782697     1  0.3688     0.6071 0.816 0.000 0.000 0.124 NA
#> GSM782698     4  0.5068     0.7198 0.388 0.000 0.000 0.572 NA
#> GSM782699     1  0.2795     0.6490 0.880 0.000 0.000 0.064 NA
#> GSM782700     2  0.0000     0.9987 0.000 1.000 0.000 0.000 NA
#> GSM782701     1  0.3184     0.6353 0.852 0.000 0.000 0.048 NA
#> GSM782702     1  0.2408     0.6576 0.892 0.000 0.000 0.016 NA
#> GSM782703     3  0.0404     0.9765 0.000 0.000 0.988 0.000 NA
#> GSM782704     3  0.0451     0.9772 0.000 0.000 0.988 0.004 NA
#> GSM782705     1  0.4905     0.0572 0.624 0.000 0.000 0.336 NA
#> GSM782706     1  0.4918     0.5054 0.708 0.000 0.000 0.100 NA
#> GSM782707     1  0.3488     0.5404 0.808 0.000 0.000 0.168 NA
#> GSM782708     3  0.0566     0.9761 0.000 0.000 0.984 0.004 NA
#> GSM782709     1  0.4153     0.5334 0.740 0.000 0.008 0.016 NA
#> GSM782710     1  0.2685     0.6519 0.880 0.000 0.000 0.028 NA
#> GSM782711     1  0.1670     0.6591 0.936 0.000 0.000 0.052 NA
#> GSM782712     1  0.2067     0.6627 0.920 0.000 0.000 0.032 NA
#> GSM782713     3  0.0162     0.9774 0.000 0.000 0.996 0.004 NA
#> GSM782714     2  0.0000     0.9987 0.000 1.000 0.000 0.000 NA
#> GSM782715     4  0.4642     0.7740 0.308 0.000 0.000 0.660 NA
#> GSM782716     3  0.0162     0.9776 0.000 0.000 0.996 0.004 NA
#> GSM782717     1  0.2830     0.6465 0.876 0.000 0.000 0.080 NA
#> GSM782718     4  0.4597     0.7403 0.424 0.000 0.000 0.564 NA
#> GSM782719     1  0.3578     0.5710 0.820 0.000 0.000 0.132 NA
#> GSM782720     3  0.0290     0.9772 0.000 0.000 0.992 0.000 NA
#> GSM782721     1  0.4693     0.5008 0.700 0.000 0.000 0.056 NA
#> GSM782722     4  0.5533     0.7652 0.336 0.000 0.000 0.580 NA
#> GSM782723     2  0.0162     0.9975 0.000 0.996 0.000 0.004 NA
#> GSM782724     2  0.0162     0.9975 0.000 0.996 0.000 0.004 NA
#> GSM782725     1  0.5426     0.1362 0.640 0.000 0.000 0.252 NA
#> GSM782726     1  0.4946     0.4839 0.700 0.000 0.060 0.008 NA
#> GSM782727     3  0.0404     0.9776 0.000 0.000 0.988 0.000 NA
#> GSM782728     2  0.0000     0.9987 0.000 1.000 0.000 0.000 NA
#> GSM782729     1  0.4582    -0.2740 0.572 0.000 0.000 0.416 NA
#> GSM782730     3  0.0451     0.9765 0.000 0.000 0.988 0.004 NA
#> GSM782731     1  0.4250     0.3586 0.720 0.000 0.000 0.252 NA
#> GSM782732     1  0.4196     0.0496 0.640 0.000 0.000 0.356 NA
#> GSM782733     3  0.0324     0.9776 0.000 0.000 0.992 0.004 NA
#> GSM782734     1  0.2548     0.6373 0.876 0.000 0.004 0.004 NA
#> GSM782735     2  0.0000     0.9987 0.000 1.000 0.000 0.000 NA
#> GSM782736     4  0.4779     0.8040 0.388 0.000 0.000 0.588 NA
#> GSM782737     2  0.0324     0.9955 0.000 0.992 0.000 0.004 NA
#> GSM782738     1  0.4803    -0.4650 0.536 0.000 0.000 0.444 NA
#> GSM782739     1  0.1408     0.6700 0.948 0.000 0.000 0.008 NA
#> GSM782740     2  0.0000     0.9987 0.000 1.000 0.000 0.000 NA
#> GSM782741     1  0.2351     0.6634 0.896 0.000 0.000 0.016 NA
#> GSM782742     3  0.0451     0.9764 0.000 0.000 0.988 0.004 NA
#> GSM782743     3  0.0963     0.9599 0.000 0.000 0.964 0.036 NA
#> GSM782744     3  0.3891     0.8426 0.016 0.000 0.812 0.036 NA
#> GSM782745     1  0.3320     0.6202 0.844 0.000 0.016 0.016 NA
#> GSM782746     2  0.0000     0.9987 0.000 1.000 0.000 0.000 NA

show/hide code output

cbind(get_classes(res, k = 6), get_membership(res, k = 6))
#>           class entropy silhouette    p1    p2    p3    p4 p5    p6
#> GSM782696     1  0.3717     0.5978 0.812 0.000 0.000 0.104 NA 0.028
#> GSM782697     1  0.4800     0.4820 0.688 0.000 0.000 0.116 NA 0.008
#> GSM782698     4  0.5819     0.5082 0.340 0.000 0.000 0.536 NA 0.048
#> GSM782699     1  0.3159     0.5968 0.832 0.000 0.000 0.068 NA 0.000
#> GSM782700     2  0.0260     0.9941 0.000 0.992 0.000 0.000 NA 0.008
#> GSM782701     1  0.4162     0.5095 0.744 0.000 0.000 0.120 NA 0.000
#> GSM782702     1  0.2272     0.6335 0.900 0.000 0.000 0.004 NA 0.040
#> GSM782703     3  0.0993     0.9476 0.000 0.000 0.964 0.000 NA 0.012
#> GSM782704     3  0.0603     0.9507 0.000 0.000 0.980 0.000 NA 0.004
#> GSM782705     1  0.5724     0.1652 0.560 0.000 0.000 0.292 NA 0.020
#> GSM782706     1  0.5983     0.0949 0.520 0.000 0.000 0.220 NA 0.012
#> GSM782707     1  0.4678     0.2094 0.640 0.000 0.000 0.304 NA 0.012
#> GSM782708     3  0.0713     0.9490 0.000 0.000 0.972 0.000 NA 0.000
#> GSM782709     1  0.3875     0.5788 0.776 0.000 0.012 0.004 NA 0.036
#> GSM782710     1  0.4312     0.5436 0.744 0.000 0.004 0.060 NA 0.012
#> GSM782711     1  0.2036     0.6277 0.916 0.000 0.000 0.048 NA 0.008
#> GSM782712     1  0.3424     0.5857 0.824 0.000 0.000 0.076 NA 0.008
#> GSM782713     3  0.0653     0.9516 0.000 0.000 0.980 0.004 NA 0.004
#> GSM782714     2  0.0000     0.9952 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782715     4  0.4084     0.6884 0.196 0.000 0.000 0.744 NA 0.008
#> GSM782716     3  0.0363     0.9519 0.000 0.000 0.988 0.000 NA 0.000
#> GSM782717     1  0.2344     0.6150 0.892 0.000 0.000 0.076 NA 0.004
#> GSM782718     4  0.3950     0.7379 0.312 0.000 0.000 0.672 NA 0.008
#> GSM782719     1  0.4862     0.3325 0.664 0.000 0.000 0.244 NA 0.012
#> GSM782720     3  0.1010     0.9480 0.000 0.000 0.960 0.004 NA 0.000
#> GSM782721     1  0.5715     0.2232 0.540 0.000 0.000 0.160 NA 0.008
#> GSM782722     4  0.5465     0.6668 0.208 0.000 0.000 0.644 NA 0.040
#> GSM782723     2  0.0146     0.9946 0.000 0.996 0.000 0.004 NA 0.000
#> GSM782724     2  0.0146     0.9946 0.000 0.996 0.000 0.004 NA 0.000
#> GSM782725     4  0.5772     0.5367 0.404 0.000 0.000 0.472 NA 0.020
#> GSM782726     1  0.4182     0.5466 0.760 0.000 0.040 0.012 NA 0.012
#> GSM782727     3  0.0937     0.9495 0.000 0.000 0.960 0.000 NA 0.000
#> GSM782728     2  0.0000     0.9952 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782729     1  0.5009    -0.3114 0.500 0.000 0.000 0.444 NA 0.012
#> GSM782730     3  0.1606     0.9417 0.000 0.000 0.932 0.004 NA 0.008
#> GSM782731     1  0.4443     0.2342 0.656 0.000 0.000 0.300 NA 0.008
#> GSM782732     1  0.4456     0.0301 0.596 0.000 0.000 0.372 NA 0.004
#> GSM782733     3  0.0436     0.9517 0.000 0.000 0.988 0.004 NA 0.004
#> GSM782734     1  0.2356     0.6218 0.884 0.000 0.000 0.004 NA 0.016
#> GSM782735     2  0.0458     0.9904 0.000 0.984 0.000 0.000 NA 0.016
#> GSM782736     4  0.4071     0.7388 0.304 0.000 0.000 0.672 NA 0.004
#> GSM782737     2  0.0000     0.9952 0.000 1.000 0.000 0.000 NA 0.000
#> GSM782738     4  0.4799     0.6783 0.356 0.000 0.000 0.592 NA 0.012
#> GSM782739     1  0.1296     0.6319 0.952 0.000 0.000 0.012 NA 0.004
#> GSM782740     2  0.0260     0.9932 0.000 0.992 0.000 0.000 NA 0.008
#> GSM782741     1  0.3387     0.6011 0.836 0.000 0.000 0.052 NA 0.024
#> GSM782742     3  0.1327     0.9405 0.000 0.000 0.936 0.000 NA 0.000
#> GSM782743     3  0.1478     0.9434 0.000 0.000 0.944 0.020 NA 0.004
#> GSM782744     3  0.5673     0.6708 0.008 0.000 0.628 0.052 NA 0.072
#> GSM782745     1  0.3248     0.5961 0.828 0.000 0.004 0.016 NA 0.016
#> GSM782746     2  0.0458     0.9904 0.000 0.984 0.000 0.000 NA 0.016

Heatmaps for the consensus matrix. It visualizes the probability of two samples to be in a same group.

consensus_heatmap(res, k = 2)

plot of chunk tab-ATC-NMF-consensus-heatmap-1

consensus_heatmap(res, k = 3)

plot of chunk tab-ATC-NMF-consensus-heatmap-2

consensus_heatmap(res, k = 4)

plot of chunk tab-ATC-NMF-consensus-heatmap-3

consensus_heatmap(res, k = 5)

plot of chunk tab-ATC-NMF-consensus-heatmap-4

consensus_heatmap(res, k = 6)

plot of chunk tab-ATC-NMF-consensus-heatmap-5

Heatmaps for the membership of samples in all partitions to see how consistent they are:

membership_heatmap(res, k = 2)

plot of chunk tab-ATC-NMF-membership-heatmap-1

membership_heatmap(res, k = 3)

plot of chunk tab-ATC-NMF-membership-heatmap-2

membership_heatmap(res, k = 4)

plot of chunk tab-ATC-NMF-membership-heatmap-3

membership_heatmap(res, k = 5)

plot of chunk tab-ATC-NMF-membership-heatmap-4

membership_heatmap(res, k = 6)

plot of chunk tab-ATC-NMF-membership-heatmap-5

As soon as we have had the classes for columns, we can look for signatures which are significantly different between classes which can be candidate marks for certain classes. Following are the heatmaps for signatures.

Signature heatmaps where rows are scaled:

get_signatures(res, k = 2)

plot of chunk tab-ATC-NMF-get-signatures-1

get_signatures(res, k = 3)

plot of chunk tab-ATC-NMF-get-signatures-2

get_signatures(res, k = 4)

plot of chunk tab-ATC-NMF-get-signatures-3

get_signatures(res, k = 5)

plot of chunk tab-ATC-NMF-get-signatures-4

get_signatures(res, k = 6)

plot of chunk tab-ATC-NMF-get-signatures-5

Signature heatmaps where rows are not scaled:

get_signatures(res, k = 2, scale_rows = FALSE)

plot of chunk tab-ATC-NMF-get-signatures-no-scale-1

get_signatures(res, k = 3, scale_rows = FALSE)

plot of chunk tab-ATC-NMF-get-signatures-no-scale-2

get_signatures(res, k = 4, scale_rows = FALSE)

plot of chunk tab-ATC-NMF-get-signatures-no-scale-3

get_signatures(res, k = 5, scale_rows = FALSE)

plot of chunk tab-ATC-NMF-get-signatures-no-scale-4

get_signatures(res, k = 6, scale_rows = FALSE)

plot of chunk tab-ATC-NMF-get-signatures-no-scale-5

Compare the overlap of signatures from different k:

compare_signatures(res)

plot of chunk ATC-NMF-signature_compare

get_signature() returns a data frame invisibly. TO get the list of signatures, the function call should be assigned to a variable explicitly. In following code, if plot argument is set to FALSE, no heatmap is plotted while only the differential analysis is performed.

# code only for demonstration
tb = get_signature(res, k = ..., plot = FALSE)

An example of the output of tb is:

#>   which_row         fdr    mean_1    mean_2 scaled_mean_1 scaled_mean_2 km
#> 1        38 0.042760348  8.373488  9.131774    -0.5533452     0.5164555  1
#> 2        40 0.018707592  7.106213  8.469186    -0.6173731     0.5762149  1
#> 3        55 0.019134737 10.221463 11.207825    -0.6159697     0.5749050  1
#> 4        59 0.006059896  5.921854  7.869574    -0.6899429     0.6439467  1
#> 5        60 0.018055526  8.928898 10.211722    -0.6204761     0.5791110  1
#> 6        98 0.009384629 15.714769 14.887706     0.6635654    -0.6193277  2
...

The columns in tb are:

  1. which_row: row indices corresponding to the input matrix.
  2. fdr: FDR for the differential test.
  3. mean_x: The mean value in group x.
  4. scaled_mean_x: The mean value in group x after rows are scaled.
  5. km: Row groups if k-means clustering is applied to rows.

UMAP plot which shows how samples are separated.

dimension_reduction(res, k = 2, method = "UMAP")

plot of chunk tab-ATC-NMF-dimension-reduction-1

dimension_reduction(res, k = 3, method = "UMAP")

plot of chunk tab-ATC-NMF-dimension-reduction-2

dimension_reduction(res, k = 4, method = "UMAP")

plot of chunk tab-ATC-NMF-dimension-reduction-3

dimension_reduction(res, k = 5, method = "UMAP")

plot of chunk tab-ATC-NMF-dimension-reduction-4

dimension_reduction(res, k = 6, method = "UMAP")

plot of chunk tab-ATC-NMF-dimension-reduction-5

Following heatmap shows how subgroups are split when increasing k:

collect_classes(res)

plot of chunk ATC-NMF-collect-classes

Test correlation between subgroups and known annotations. If the known annotation is numeric, one-way ANOVA test is applied, and if the known annotation is discrete, chi-squared contingency table test is applied.

test_to_known_factors(res)
#>          n agent(p) k
#> ATC:NMF 51    0.648 2
#> ATC:NMF 51    0.642 3
#> ATC:NMF 51    0.642 4
#> ATC:NMF 44    0.474 5
#> ATC:NMF 42    0.479 6

If matrix rows can be associated to genes, consider to use functional_enrichment(res, ...) to perform function enrichment for the signature genes. See this vignette for more detailed explanations.

Session info

sessionInfo()
#> R version 3.6.0 (2019-04-26)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: CentOS Linux 7 (Core)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib64/libblas.so.3.4.2
#> LAPACK: /usr/lib64/liblapack.so.3.4.2
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
#>  [4] LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
#> [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] grid      stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] genefilter_1.66.0    ComplexHeatmap_2.3.1 markdown_1.1         knitr_1.26          
#> [5] GetoptLong_0.1.7     cola_1.3.2          
#> 
#> loaded via a namespace (and not attached):
#>  [1] circlize_0.4.8       shape_1.4.4          xfun_0.11            slam_0.1-46         
#>  [5] lattice_0.20-38      splines_3.6.0        colorspace_1.4-1     vctrs_0.2.0         
#>  [9] stats4_3.6.0         blob_1.2.0           XML_3.98-1.20        survival_2.44-1.1   
#> [13] rlang_0.4.2          pillar_1.4.2         DBI_1.0.0            BiocGenerics_0.30.0 
#> [17] bit64_0.9-7          RColorBrewer_1.1-2   matrixStats_0.55.0   stringr_1.4.0       
#> [21] GlobalOptions_0.1.1  evaluate_0.14        memoise_1.1.0        Biobase_2.44.0      
#> [25] IRanges_2.18.3       parallel_3.6.0       AnnotationDbi_1.46.1 highr_0.8           
#> [29] Rcpp_1.0.3           xtable_1.8-4         backports_1.1.5      S4Vectors_0.22.1    
#> [33] annotate_1.62.0      skmeans_0.2-11       bit_1.1-14           microbenchmark_1.4-7
#> [37] brew_1.0-6           impute_1.58.0        rjson_0.2.20         png_0.1-7           
#> [41] digest_0.6.23        stringi_1.4.3        polyclip_1.10-0      clue_0.3-57         
#> [45] tools_3.6.0          bitops_1.0-6         magrittr_1.5         eulerr_6.0.0        
#> [49] RCurl_1.95-4.12      RSQLite_2.1.4        tibble_2.1.3         cluster_2.1.0       
#> [53] crayon_1.3.4         pkgconfig_2.0.3      zeallot_0.1.0        Matrix_1.2-17       
#> [57] xml2_1.2.2           httr_1.4.1           R6_2.4.1             mclust_5.4.5        
#> [61] compiler_3.6.0