wesly82 wesly82 - 1 month ago 20
R Question

Partition Around Medoids in R not using medoids input

I'm using the

pam
function in R, and I'm specifying the cases I want to use as my exemplars, but it doesn't seem to be using those cases and just skipping to the "build" phase. I even checked the example code given in the documentation, and it seems to be doing the same thing:

library(cluster)
## generate 25 objects, divided into 2 clusters.
x <- rbind(cbind(rnorm(10,0,0.5), rnorm(10,0,0.5)),
cbind(rnorm(15,5,0.5), rnorm(15,5,0.5)))

## use obs. 1 & 16 as starting medoids -- same result (typically)
(p2m <- pam(x, 2, medoids = c(1,16)))

p2m[1]


This shows that it used cases 1 and 24 for the medoids, not 1 and 16 as inputted. Is this some kind of bug? Or am I not doing something correctly?

Answer

If you do not want pam() to find the mediods for you, and instead use your specified mediods, you should set do.swap = FALSE in your call to pam:

(p2m <- pam(x, 2, medoids = c(1,16), do.swap = FALSE))
Comments