Clustering using the pam algorithm in R I´m using the pam() R function to perform clustering. As far as I know, the pamk() function serves as a wrapper to pam(), and evaluates the optimal number of clusters. However, using the same data and parameters I get different results.
For example, calling pamk() and pam() as follows returns 2 clusters with different medoids values:
pk <- pamk(dist, krange=2:10, criterion="ch", usepam=TRUE, diss=TRUE)

pk.2 <- pam(dist,2,diss=TRUE)

How can it be?
Thank you,
Anat
 A: First off, if you are using functions from a package, please mention it in your question (in this case, pamkis in package fpc). It will make it easier for people to help you.
Second, it also helps if you provide a reproducible example (that is, give us the data, or part of it, that gives you your problem).
Now, as to your problem. If you list the source of pamk, (you do this by typing the name of the function, without brackets, in the R prompt, and pressing enter), you'll see that indeed it runs pam for your set of k values, and then picks the best one based on your criterion of choice.
What it doesn't do, however, is run the algorithm several times for the same k and check the stability of the medioids: the pam algorithm is not completely deterministic, and can depend on the initial (typically randomly determined) starting points. In fact, if you run pam several times on your data, with the same k, I would expect (in your case) to see different results as well!
Normally, this is an indication that the clusters are not well defined in your data (or at least not in a form that can be picked up by pam). It is likely that, if you were to include 1 in your krange, this would give the best result: the best 'partitioning' is no partitioning.
Conclusion: if you get this type of result from pam, don't trust it!
Disclaimer: since I cannot see your data, and you don't mention how the 2 results are different, I'm sort of guessing what the problem is, here. If your problem is really that the return value of pamk is a list, of which the item pamobject is really the pam object (imagine that), the above is still true but less relevant to you (for now).
