wesly82 wesly82 - 1 year ago 173
R Question

Partition Around Medoids in R not using medoids input

I'm using the

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:

## 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)))


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 Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download