Learn R Programming

sharp (version 1.4.7)

PAMClustering: (Weighted) Partitioning Around Medoids

Description

Runs Partitioning Around Medoids (PAM) clustering using implementation from pam. This is also known as the k-medoids algorithm. If Lambda is provided, clustering is applied on the weighted distance matrix calculated using the COSA algorithm as implemented in cosa2. Otherwise, distances are calculated using dist. This function is not using stability.

Usage

PAMClustering(xdata, nc = NULL, Lambda = NULL, distance = "euclidean", ...)

Value

A list with:

comembership

an array of binary and symmetric co-membership matrices.

weights

a matrix of median weights by feature.

Arguments

xdata

data matrix with observations as rows and variables as columns.

nc

matrix of parameters controlling the number of clusters in the underlying algorithm specified in implementation. If nc is not provided, it is set to seq(1, tau*nrow(xdata)).

Lambda

vector of penalty parameters (see argument lambda in cosa2). Unweighted distance matrices are used if Lambda=NULL.

distance

character string indicating the type of distance to use. If Lambda=NULL, possible values include "euclidean", "maximum", "canberra", "binary", and "minkowski" (see argument method in dist). Otherwise, possible values include "euclidean" (pwr=2) or "absolute" (pwr=1) (see argument pwr in cosa2).

...

additional parameters passed to pam, dist, or cosa2. If weighted=TRUE, parameters niter (default to 1) and noit (default to 100) correspond to the number of iterations in cosa2 to calculate weights and may need to be modified.

References

rCOSAsharp

COSAsharp

See Also

Other clustering algorithms: DBSCANClustering(), GMMClustering(), HierarchicalClustering(), KMeansClustering()

Examples

Run this code
if (requireNamespace("cluster", quietly = TRUE)) {
  # Data simulation
  set.seed(1)
  simul <- SimulateClustering(n = c(10, 10), pk = 50)

  # PAM clustering
  myclust <- PAMClustering(
    xdata = simul$data,
    nc = seq_len(20)
  )

  # Weighted PAM clustering (using COSA)
  if (requireNamespace("rCOSA", quietly = TRUE)) {
    myclust <- PAMClustering(
      xdata = simul$data,
      nc = seq_len(20),
      Lambda = c(0.2, 0.5)
    )
  }
}

Run the code above in your browser using DataLab