kmeans_join_DT: Join K-means clustering results into a reference (long)...

View source: R/kmeans_join_DT.R

kmeans_join_DTR Documentation

Join K-means clustering results into a reference (long) data.table

Description

Takes the results of K-means clustering performed by kmeans and joins them into a reference data table including the same samples.

Usage

kmeans_join_DT(refTab, sampCol = "SAMPLE", kFit)

Arguments

refTab

Data.table: the reference data.table with a column of sample names, see param sampCol.

sampCol

Character: a column in refTab where sample names are stored. These sample names must match those in names(kFit$cluster), see param kFit. Default is SAMPLE.

kFit

Kmeans: an object produced by the function kmeans. The cluster predictions in kFit$cluster will be aligned against samples in refTab[[sampCol]]. It is therefore necessary that the names in this object match those expected in refTab.

Details

It is important that all the samples in refTab match the names of samples in kFit. The function will throw a warning if this is not the case, but will force the join regardless.

Examples

library(genomalicious)

data(data_Genos)
data_Genos

# Perform PCA.
PCA <- pca_genos(data_Genos)

# Get a table of PC axes
pcTable <- pca2DT(PCA)

# K-means clustering
K4 <- kmeans(PCA$x[,1:4], centers=4, nstart=10)

K4$cluster

# Add in inferred populations.
pcTable2 <- kmeans_join_DT(pcTable, 'SAMPLE', K4)
pcTable2

# Plot
(ggplot(pcTable2, aes(x=PC1, y=PC2, colour=CLUSTER))
   + geom_point()
)


j-a-thia/genomalicious documentation built on Oct. 19, 2024, 7:51 p.m.