An R package for performing k-means consensus clustering with bootstrap resampling.
You can install the package directly from this repository using devtools:
# Install devtools if you haven't already
install.packages("devtools")
# Install ConsensusCluster
devtools::install_github("skelly001/ConsensusCluster")Or install locally:
devtools::install("path/to/ConsensusCluster")library(ConsensusCluster)
# Create sample data
set.seed(123)
data_matrix <- matrix(rnorm(1000), nrow = 100, ncol = 10)
rownames(data_matrix) <- paste0("Feature", 1:100)
# Run consensus clustering
clusters <- kmeansCC(
data = data_matrix,
k = 4,
reps = 100,
ncores = 4,
seed = 0
)
# View cluster assignments
table(clusters)Performs consensus clustering using k-means algorithm with bootstrap resampling.
data: A numeric matrix or data frame with features in rows and samples in columnsk: Integer. The number of clusters to identifyreps: Integer. The number of bootstrap iterations to perform (default: 100)ncores: Integer. The number of CPU cores to use for parallel processing (default: 1)seed: Integer. Random seed for reproducibility (default: 0)
A named integer vector of cluster assignments for each feature.
- Generate all unique pairs of features (including self-pairs)
- For each bootstrap iteration:
- Resample samples with replacement
- Perform k-means clustering
- Record which features cluster together
- Calculate consensus proportions: how often each pair of features co-clustered
- Build a symmetric co-clustering matrix
- Perform hierarchical clustering on 1 - consensus matrix
- Cut tree to obtain k final clusters
MIT License