library(UniversalCVI)
# The data is from Wiroonsri (2024).
x = R1_data[,1:2]
# ---- Kmeans ----
# Compute all the indices by Wvalid
K.NC = Wvalid(scale(x), kmax = 15, kmin=2, method = 'kmeans',
corr='pearson', nstart=100, NCstart = TRUE)
print(K.NC)
# The optimal number of cluster
K.NC$NCI[which.max(K.NC$NCI$NCI),]
# ---- Hierarchical ----
# Average linkage
# Compute all the indices by Wvalid
H.NC = Wvalid(scale(x), kmax = 15, kmin=2, method = 'hclust_average',
corr='pearson', nstart=100, NCstart = TRUE)
print(H.NC)
# The optimal number of cluster
H.NC$NCI[which.max(H.NC$NCI$NCI),]
Run the code above in your browser using DataLab