Given an \(n x m\) matrix of centroids, where \(m\) are the prototypic centroids with \(n\) features, classify new samples according to the distance to the centroids.

cluster_classify(data, centroid, method = "pearson")

Arguments

data

a data.frame of dimensions \(n x p\) with the samples to classify, were \(n\) are the same set of features as in the centroids

centroid

a data.frame of dimensions \(n x m\), where each column is a prototypic centroid to classify the samples

method

Character string indicating which method to use to calculate distance to centroid. Options are "pearson" (default), "kendall", or "spearman"

Value

Returns a numeric vector of length \(p\) with the class assigned to each sample according to the shortest distance to centroid

Examples

# load example dataset require(iC10TrainingData) require(pamr) data(train.Exp) data(IntClustMemb) TrainData <- list(x = train.Exp, y = IntClustMemb) # Create prototypic centroids pam <- pamr.train(TrainData)
#> 123456789101112131415161718192021222324252627282930
centroids <- pam$centroids Class <- cluster_classify(train.Exp, centroids) table(Class, IntClustMemb)
#> IntClustMemb #> Class 1 2 3 4 5 6 7 8 9 10 #> 1 69 0 5 7 1 0 4 0 0 1 #> 2 0 40 2 2 0 0 0 0 1 0 #> 3 1 1 114 5 1 1 0 10 0 1 #> 4 0 1 2 110 1 0 1 0 0 0 #> 5 1 1 0 8 84 0 1 0 1 0 #> 6 0 0 1 3 0 42 3 0 0 0 #> 7 1 1 0 12 0 0 95 2 3 0 #> 8 0 0 27 0 1 0 1 129 1 0 #> 9 0 1 2 5 2 1 3 1 56 0 #> 10 4 0 3 15 4 0 1 1 5 94