0

Upon performing NbClust on my data, I found that 5 clusters were determined to be the optimal number according to the majority rule. However, how do I find out which indices produced those 5 clusters?

Also how do I plot this new data and color/group with elipsis? In the past I have used fviz_cluster from the facto package, but usually with a kmeans object. I tried to input my nb but that is a list and hence results in an error. I know I can plot a histogram with the optimal number of clusters, but I am not trying to plot that.

Reproducible Example with iris as an example

library("NbClust")
data(iris)
iris.scaled <- scale(iris[, -5])
set.seed(123)
res.nb <- NbClust(iris.scaled, distance = "euclidean",
                  min.nc = 2, max.nc = 10, 
                  method = "complete", index ="gap") 
res.nb # print the results
fviz_nbclust(res.nb) + theme_minimal()
Jack Armstrong
  • 1,182
  • 4
  • 26
  • 59
  • It's hard to answer without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – camille Nov 07 '18 at 15:04
  • tough to insert over 400 lines of code. I put in the iris data base – Jack Armstrong Nov 07 '18 at 15:34
  • You're still missing how you made `iris.scaled` (I'm guessing just calling `scale` on `iris`, but don't want to assume what's in your code) and `nb` (I'm guessing that should be `res.nb`). But looking at the help docs, your results list contains an item `Best.nc` which is a matrix of the best number of clusters for each index. Also you refer to an optimal 5 clusters but that's probably for your real data, not the `iris` example. – camille Nov 07 '18 at 15:44
  • editted. My issue is still how should I plot the results from Nbclust from the `Best.partition` – Jack Armstrong Nov 07 '18 at 16:33

1 Answers1

2

The argument index should be all. However it is possible to let the package itself do this by neglecting to fill in this argument.

res.nb <- NbClust(iris.scaled, distance = "euclidean",
                  min.nc = 2, max.nc = 10, 
                  method = "complete")

res.nb <- NbClust(iris.scaled, distance = "euclidean",
                  min.nc = 2, max.nc = 10, 
                  method = "complete", 
                  index ="all") 
library(factoextra)
fviz_nbclust(res.nb)

enter image description here

bbiasi
  • 1,549
  • 2
  • 15
  • 31