Description Usage Arguments Value References Examples
Estimates the optimal number of clusters for multiple samples using either Slope or Silhouette criterion. The optimal number of clusters will be verified in the range 2,..., maxClust. Takes the mean of all samples in order to perform the estimation.
1 2 | nClustMulti(dataDist, p = 1, maxClust = 20, clusteringFunction,
criterion = c("slope", "silhouette"))
|
dataDist |
An matrix with n subjects. Each subject has the size of NxN and represents the distances between the elements of the sample. |
p |
Slope adjust parameter. |
maxClust |
The maximum number of clusters to be tried. |
clusteringFunction |
The clustering function to be used. |
criterion |
The criterion that will be used for estimating the number of clusters. The options are "slope" or "silhouette". If not defined, "slope" will be used. |
The optimal number of clusters.
Fujita A, Takahashi DY, Patriota AG (2014b) A non-parametric method to estimate the number of clusters. Computational Statistics & Data Analysis 73:27–39
Rousseeuw PJ (1987) Sihouettes: a graphical aid to the interpretation and validation of cluster analysis. Journal of Computational and Applied Mathematics 20:53–65
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # Install packages if necessary
# install.packages('MASS')
# install.packages('cluster')
library(anocva)
library(MASS)
library(cluster)
set.seed(5000)
# A k-means function that returns cluster labels directly.
myKmeans = function(dist, k){
return(kmeans(dist, k, iter.max = 50, nstart = 5)$cluster)
}
# Number of subjects in each population
nsub = 25
# Number of items in each subject
nitem = 60
# Generate simulated data
data = array(NA, c(nsub, nitem*2, 2))
data.dist = array(NA, c(nsub, nitem*2, nitem*2))
meanx = 2
delta = 0.5
# Covariance matrix
sigma = matrix(c(0.03, 0, 0, 0.03), 2)
for (i in seq(nsub)){
sub = rbind(mvrnorm(nitem, mu = c(0, 0), Sigma = sigma ),
mvrnorm(nitem, mu = c(meanx,0), Sigma = sigma))
data[i,,] = sub
data.dist[i,,] = as.matrix(dist(data[i,,]))
}
# Estimate the optimal number of clusters
r = nClustMulti(dataDist = data.dist, p = 1, maxClust = 20,
clusteringFunction = myKmeans, criterion = "slope")
sprintf("The optimal number of clusters found was %d.", r)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.