% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-selection.r
\name{SelectnrClusters}
\alias{SelectnrClusters}
\title{Select the number of clusters via silhouette widths}
\usage{
SelectnrClusters(
  List,
  type = c("data", "dist", "pam"),
  distmeasure = c("tanimoto", "tanimoto"),
  normalize = c(FALSE, FALSE),
  method = c(NULL, NULL),
  nrclusters = seq(5, 25, 1),
  names = NULL,
  StopRange = FALSE,
  plottype = "none",
  location = NULL
)
}
\arguments{
\item{List}{A list of data matrices (objects in rows), distance matrices, or
\code{cluster::pam} outputs, depending on \code{type}.}

\item{type}{One of \code{"data"} (compute a distance first via
\code{\link{Distance}}), \code{"dist"} (elements are dissimilarity
matrices) or \code{"pam"} (elements are \code{pam} objects).}

\item{distmeasure}{Distance measure(s) used when \code{type = "data"}.}

\item{normalize, method}{Normalisation controls passed to \code{\link{Distance}}.}

\item{nrclusters}{Sequence of cluster numbers to evaluate.}

\item{names}{Optional names for the sources; used in output labels.}

\item{StopRange}{Logical; if \code{FALSE} and dissimilarities fall outside
\code{[0, 1]} they are range-normalised for comparability.}

\item{plottype}{One of \code{"none"} (default; no plot, safe for headless
runs), \code{"new"}, \code{"pdf"} or \code{"sweave"}. Any value other than
\code{"none"} attempts to draw the silhouette curve; drawing is guarded so
that a missing graphics device does not abort the computation.}

\item{location}{File location (without extension) used when
\code{plottype = "pdf"}. Default \code{NULL}.}
}
\value{
A list with two elements: \code{Silhoutte_Widths} (a matrix of
average silhouette widths per source and their mean) and
\code{Optimal_Nr_of_CLusters} (a one-row data frame with the silhouette
optimal number of clusters per source and overall).
}
\description{
For each element of \code{List}, partitions around medoids
(\code{cluster::pam}) are computed over a range of cluster numbers and the
average silhouette width is recorded. The number of clusters maximising the
average silhouette width is reported per source and for the across-source
average. The analytical result (the silhouette table and the chosen number
of clusters) is returned and is testable without producing any plot.
}
\examples{
\dontrun{
data(mosaic_toy)
sel <- SelectnrClusters(mosaic_toy$List, type = "data",
                        distmeasure = c("euclidean", "euclidean"),
                        nrclusters = seq(2, 5), plottype = "none")
sel$Optimal_Nr_of_CLusters
}
}
\references{
Kaufman, L. and Rousseeuw, P. J. (1990). Finding Groups in Data: An
Introduction to Cluster Analysis. Wiley, New York.
}
