-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkmediods.R
More file actions
39 lines (26 loc) · 923 Bytes
/
kmediods.R
File metadata and controls
39 lines (26 loc) · 923 Bytes
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
39
#Old Results
#Kmediod Results
#n=85,p=300,cont.5, binary d.25, binary ind.25 |||.03364 ||| 0.07
#n=85,p=300,cont.5, binary true .5 |||.02331 ||| 0.014
#n=85,p=300,cont.5, binary dep .5 |||.0132 ||| 0.013 (nearly the same)
#Comparison Code
#Scenario cases
#d=0,0.2,0.4,0.6,0.8
data <- SimulateExample(n= 85,p = 299, prop.data.type =c(0.1,0.5,0,0.2,0.2))
#K-mediods
library(cluster)
dist <- daisy(t(data$X$data$X),metric="gower")
#Select K
sil_width <- c(NA)
for(i in 1:49 ){
pam_fit <- pam(dist,diss = TRUE, k = 5*i)
sil_width[i] <- pam_fit$silinfo$avg.width
}
plot(1:49, sil_width, xlab="Number of Clusters",ylab ="Silhoutte Width")
lines(1:49,sil_width)
pam_fit <- pam(dist, diss = TRUE, k =5*49)
mat.pam <- matrix(0,299,299)
for(i in 1:299){
mat.pam[which(pam_fit$clustering == pam_fit$clustering[i] ),i ] <- 1
}
mean(mat.pam != data$parm$clust$nbhd.matrix)