Finally, we can apply pivotal relabelling and inspect the new posterior
estimates with the functions piv_rel and piv_plot, respectively:

rel<- piv_rel(mcmc=res, nMC=nMC)
piv_plot(y, res, rel, "chains")

piv_plot(y, res, rel, "hist")

Example 2. K-means clustering using MUS and other pivotal algorithms

Sometimes K-means algorithm does not provide an optimal clustering
solution. Suppose to generate some clustered data and to detect one
pivotal unit for each group with the MUS (Maxima Units Search
algorithm) function:

In such situations, we may need a more robust version of the classical
K-means. The pivots may be used as initial seeds for a classical K-means
algorithm. The function piv_KMeans works as the classical kmeans
function, with some optional arguments (in the figure below, the colored
triangles represent the pivots).