% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/allocate.distance.R
\name{allocate.distance}
\alias{allocate.distance}
\title{Allocation of Entries to be Selected from Clusters/Groups based on
Distance-based Diversity Metrics for Core Collection Development}
\usage{
allocate.distance(
  data,
  names,
  group,
  dist.mat,
  method = c("dist", "dist.prop", "dist.log", "dist.sqrt"),
  metric = c("mean", "median", "max", "range", "mnnd", "mdc", "mdm", "mstl", "nclust"),
  clust.fun = NULL,
  log.base = exp(1),
  size
)
}
\arguments{
\item{data}{The data as a data frame object. The data frame should possess
one row per individual and columns with the individual names and multiple
trait/character data.}

\item{names}{Name of column with the accession names as a character string.}

\item{group}{Name of column with the accession group/cluster names as a
character string.}

\item{dist.mat}{A precomputed distance matrix of distance measures between the
accessions in \code{data}.}

\item{method}{The allocation method. Either \code{"dist"} for constant or
\code{"dist.prop"} for proportional or \code{"dist.log"} for logarithmic or
\code{"dist.sqrt"} for square root allocation. See \strong{Methods}.}

\item{metric}{The metric to be computed from the distance matrix. Either
\code{"mean"}, \code{"median"}, \code{"max"}, \code{"range"},
\code{"mnnd"}, \code{"mdc"}, \code{"mdm"}, \code{"mstl"}, or
\code{"nclust"}. See \strong{Metrics}.}

\item{clust.fun}{A function to generate clusters from a distance matrix and
return the number of clusters.}

\item{log.base}{The logarithm base to be used for logarithmic method of
sampling. Default is \code{exp(1)}.}

\item{size}{The desired core set size proportion.}
}
\value{
A named numeric vector specifying the number of entries to be
  selected from each cluster/group. The vector names correspond to the levels
  of the "\code{"group"} column, and values indicate the number of elements
  to be selected from each level.
}
\description{
Estimate the number of entries to be allocated from each cluster/group in
the entire collection to construct a core collection on the basis of
different metrics computed from within cluster/group distances. The following
strategies are implemented. \loadmathjax
\itemize{
\item{Diversity (Distance based)}
\item{Diversity (Distance based) & Proportional}
\item{Diversity (Distance based) & Logarithmic}
\item{Diversity (Distance based) & Square root}}
}
\section{Details}{


  The number of entries to be chosen from each cluster is estimated either on
  the basis of diversity of entries within that cluster/group alone or in
  combination with the size of the cluster/group (See \strong{Methods}).

  The within-cluster/group diversity is estimated as several metrics from the
  within cluster/group genetic distances between accessions (See
  \strong{Metrics}).

  \insertCite{franco_sampling_2005;textual}{SampleCore} proposed a method
  based on mean Gower's distance \insertCite{gower_general_1971}{SampleCore}
  which was also extended to other distance measure averages named D
  Allocation strategy \insertCite{franco_sampling_2006}{SampleCore}. These
  methods were also combined with the proportional and logarithmic methods.
  For example, the GP and GL strategy of
  \insertCite{bisht_assessment_1999;textual}{SampleCore} and
  \insertCite{mahajan_sampling_1999;textual}{SampleCore} as well as the NY
  and LD allocation methods of
  \insertCite{franco_sampling_2005;textual}{SampleCore}.
}

\section{Methods}{


  \subsection{Diversity method}{From an entire collection of size \mjseqn{N},
  to construct a core set of sample size \mjseqn{n}, the number of entries to
  be selected from the \mjseqn{i}th group among \mjseqn{1 \cdots g} groups
  (\mjseqn{n_{i}}) is estimated as below.

   \mjsdeqn{n_{i} = n \times \frac{D_{i}}{\sum_{i=1}^{g}D_{i}}}

   Where, \mjseqn{D_{i}} is a measure of the extent of diversity present in
   the \mjseqn{i}th cluster.

   }

   \subsection{Diversity and proportional method}{Here the number of entries
   to be selected is proportional to the diversity of the cluster/group
   (\mjseqn{D_{i}}) weighted by the the cluster/group size (\mjseqn{N_{i}}).

    \mjsdeqn{n_{i} = n \times \frac{N_{i}D_{i}}{\sum_{i=1}^{g}N_{i}D_{i}}}

   }

   \subsection{Diversity and logarithmic method}{Here the number of entries
   to be selected is proportional to the diversity of the cluster/group
   (\mjseqn{D_{i}}) weighted by the logarithm of the cluster/group size
   (\mjseqn{N_{i}}).

   \mjsdeqn{n_{i} = n \times
   \frac{\log(N_{i})D_{i}}{\sum_{i=1}^{g}\log(N_{i})D_{i}}}

   }

   \subsection{Diversity and square root method}{Here the number of entries
   to be selected is proportional to the diversity of the cluster/group
   (\mjseqn{D_{i}}) weighted by the square root of the cluster/group size
   (\mjseqn{N_{i}}).

   \mjsdeqn{n_{i} = n \times
   \frac{\sqrt{N_{i}}D_{i}}{\sum_{i=1}^{g}\sqrt{N_{i}}D_{i}}}

   }
}

\section{Metrics}{


  \subsection{Summary/Decriptive statistics}{These include mean, median,
  maximum and range of genetic distances between entries in a cluster.}

  \subsection{Mean nearest-neighbour distance (\mjseqn{MNND})}{It is the
  average, across all entries, of the distance to each entry’s
  closest other entry (\mjseqn{d_{g_{min}}}), based on a genetic given
  distance matrix \insertCite{clark_distance_1954}{SampleCore}.

  For each entry, the nearest-neighbour distance (\mjseqn{d_{g_{min}}})
  is the smallest non-zero distance with any other entry.

  \mjsdeqn{d_{g_{min}} = \min_{h \ne g} d_{gh}}

  The Mean nearest-neighbour distance (\mjseqn{MNND}) can then be computed
  as:

  \mjsdeqn{\textrm{MNND} = \frac{1}{G} \sum_{g=1}^{G} d_g}

  Where, (\mjseqn{g}) is the index of an entry in a genetic distance
  matrix, \mjseqn{h} is the index of all other genotypes and \mjseqn{G} is
  the total number of genotypes in a cluster/group.

  }

  \subsection{Minimum spanning tree length (\mjseqn{MSTL})}{It is defined as
  the sum of edge weights in the minimum spanning tree constructed from the
  genetic distance matrix of entries within a cluster/group.  A minimum
  spanning tree (MST) connects all entries such that the total distance
  is minimized and no cycles are formed. It represents the most efficient
  way to connect all entries based on pairwise genetic distances
  \insertCite{gower_minimum_1969}{SampleCore}.

  For genetic distance \mjseqn{d_{gh}} between entries \mjseqn{g} and
  \mjseqn{h}, the MST is a subset of edges that connects all
  \mjseqn{G} entries with exactly \mjseqn{G - 1} edges and minimum total
  weight. The MST length (\mjseqn{MSTL}) can then be computed as:

  \mjsdeqn{\textrm{MSTL} = \sum_{(g,h) \in \mathcal{T}} d_{gh}}

  Where \mjseqn{\mathcal{T}} denotes the set of edges in the MST.

  }

  \subsection{Mean distance to centroid and median (\mjseqn{MDC},
  \mjseqn{MDM})}{These quantify the average dispersion of entries within a
  cluster/group relative to a central point in multivariate space derived
  from the genetic distance matrix.

  The centroid represents the multivariate mean position of all entries
  in a cluster
  \insertCite{sokal_principles_1963,sneath_numerical_1973}{SampleCore}.,
  whereas the median (spatial median) provides a robust central location
  that is less influenced by extreme values
  \insertCite{bradley_constrained_1999}{SampleCore}.

  For \mjseqn{d_{gC}} and \mjseqn{d_{gM}} distances of entry
  \mjseqn{g} from the centroid \mjseqn{C} and median \mjseqn{M},
  respectively. These measures are computed as:

  \mjsdeqn{\textrm{MDC} = \frac{1}{G} \sum_{g=1}^{G} d_{gC}}

  \mjsdeqn{\textrm{MDM} = \frac{1}{G} \sum_{g=1}^{G} d_{gM}}

  Where \mjseqn{G} is the total number of entries in the cluster/group.

  }

  \subsection{Number of clusters}{\insertCite{diwan_core_1994}{SampleCore}
  proposed the number of clusters produced by a multivariate cluster
  analysis at a specific distance threshold as an estimate of the diversity.

  }
}

\examples{
\dontshow{if (requireNamespace("cluster", quietly = TRUE) & requireNamespace("fastcluster", quietly = TRUE) & requireNamespace("dbscan", quietly = TRUE) & requireNamespace("biotools", quietly = TRUE)) withAutoprint(\{ # examplesIf}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Prepare example data
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

library(cluster)

# Get distance matrix
data("cassava_EC_gp")

set.seed(123)
cassava_EC_gp <- cassava_EC_gp[sample(1:nrow(cassava_EC_gp), 500), ]

quant <- c("NMSR", "TTRN", "TFWSR", "TTRW", "TFWSS", "TTSW", "TTPW",
           "AVPW", "ARSR", "SRDM")
qual <- c("CUAL", "LNGS", "PTLC", "DSTA", "LFRT", "LBTEF", "CBTR", "NMLB",
          "ANGB", "CUAL9M", "LVC9M", "TNPR9M", "PL9M", "STRP", "STRC",
          "PSTR")

data <- cassava_EC_gp

# Convert qualitative data columns to factor
data[, qual] <- lapply(data[, qual], as.factor)

# Standardise quantitative data column
data[, quant] <- lapply(data[, quant], function(x) {
  scale(x)[, 1]
})

# Get the Gower's distance matrix
dist_matrix <- daisy(x = data[, c(qual, quant)],
                     metric = "gower")

# Get data
data <- cassava_EC_gp
data <- cbind(genotypes = rownames(cassava_EC_gp), cassava_EC_gp)
row.names(data) <- NULL

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Custom clustering functions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# UPGMA with hclust
clust_fun_upgma <- function(x) {
  # Tree
  tree_out <- hclust(x, method = "average")
  # Clusters
  cutree(tree_out, h = 0.2)
}

if (requireNamespace('fastcluster', quietly = TRUE)) {
  # Ward's minimum variance with fastcluster
  clust_fun_ward <- function(x) {
    # Tree
    tree_out <- fastcluster::hclust(x, method = "ward.D2")
    # Clusters
    cutree(tree_out, h = 0.2)
  }
}

if (requireNamespace('dbscan', quietly = TRUE)) {
  # Density-based clustering with dbscan
  clust_fun_dbscan <- function(x) {
    clust_out <- dbscan::dbscan(x, eps = 0.25)
    # remove noise: TODO
    setNames(clust_out$cluster, labels(x))
  }
}

if (requireNamespace('biotools', quietly = TRUE)) {
  # Tocher's sequential clustering
  clust_fun_tocher <- function(x) {
    clust_out <- biotools::tocher(x, algorithm = "sequential")
    setNames(clust_out$class, labels(x))
  }
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Diversity (Distance based) allocation
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

## Mean
dist_out_mean <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "mean",
                    size = 0.2)
dist_out_mean

## Median
dist_out_median <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "median",
                    size = 0.2)
dist_out_median

## Maximum
dist_out_max <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "max",
                    size = 0.2)
dist_out_max

## Range
dist_out_range <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "range",
                    size = 0.2)
dist_out_range

## Mean nearest-neighbour distance
dist_out_mnnd <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "mnnd",
                    size = 0.2)
dist_out_mnnd

## Minimum spanning tree length
dist_out_mstl <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "mstl",
                    size = 0.2)
dist_out_mstl

\donttest{
  ## Mean distance to centroid
  dist_out_mdc <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist",
                      dist.mat = dist_matrix, metric = "mdc",
                      size = 0.2)
  dist_out_mdc

  ## Mean distance to median
  dist_out_mdm <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist",
                      dist.mat = dist_matrix, metric = "mdm",
                      size = 0.2)
  dist_out_mdm
}

## Number of clusters

### UPGMA with hclust
dist_out_nclust1 <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist",
                    dist.mat = dist_matrix, metric = "nclust",
                    clust.fun = clust_fun_upgma,
                    size = 0.2)
dist_out_nclust1

# Ward's minimum variance with fastcluster
if (requireNamespace('fastcluster', quietly = TRUE)) {
  dist_out_nclust2 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_ward,
                      size = 0.2)
  dist_out_nclust2
}


# Density-based clustering with dbscan
if (requireNamespace('dbscan', quietly = TRUE)) {
  dist_out_nclust3 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_dbscan,
                      size = 0.2)
  dist_out_nclust3
}

\donttest{
  if (requireNamespace('biotools', quietly = TRUE)) {
    # Tocher's sequential clustering
    dist_out_nclust4 <-
      allocate.distance(data = data, names = "genotypes",
                        group = "Cluster", method = "dist",
                        dist.mat = dist_matrix, metric = "nclust",
                        clust.fun = clust_fun_tocher,
                        size = 0.2)
    dist_out_nclust4
  }
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Diversity (Distance based) & Proportional
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

## Mean
dist_prop_out_mean <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "mean",
                    size = 0.2)
dist_prop_out_mean

## Median
dist_prop_out_median <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "median",
                    size = 0.2)
dist_prop_out_median

## Maximum
dist_prop_out_max <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "max",
                    size = 0.2)
dist_prop_out_max

## Range
dist_prop_out_range <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "range",
                    size = 0.2)
dist_prop_out_range

## Mean nearest-neighbour distance
dist_prop_out_mnnd <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "mnnd",
                    size = 0.2)
dist_prop_out_mnnd

## Minimum spanning tree length
dist_prop_out_mstl <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "mstl",
                    size = 0.2)
dist_prop_out_mstl

\donttest{
  ## Mean distance to centroid
  dist_prop_out_mdc <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.prop",
                      dist.mat = dist_matrix, metric = "mdc",
                      size = 0.2)
  dist_prop_out_mdc

  ## Mean distance to median
  dist_prop_out_mdm <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.prop",
                      dist.mat = dist_matrix, metric = "mdm",
                      size = 0.2)
  dist_prop_out_mdm
}

## Number of clusters

### UPGMA with hclust
dist_prop_out_nclust1 <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.prop",
                    dist.mat = dist_matrix, metric = "nclust",
                    clust.fun = clust_fun_upgma,
                    size = 0.2)
dist_prop_out_nclust1

# Ward's minimum variance with fastcluster
if (requireNamespace('fastcluster', quietly = TRUE)) {
  dist_prop_out_nclust2 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.prop",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_ward,
                      size = 0.2)
  dist_prop_out_nclust2
}

# Density-based clustering with dbscan
if (requireNamespace('dbscan', quietly = TRUE)) {
  dist_prop_out_nclust3 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.prop",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_dbscan,
                      size = 0.2)
  dist_prop_out_nclust3
}

\donttest{
  if (requireNamespace('biotools', quietly = TRUE)) {
    # Tocher's sequential clustering
    dist_prop_out_nclust4 <-
      allocate.distance(data = data, names = "genotypes",
                        group = "Cluster", method = "dist.prop",
                        dist.mat = dist_matrix, metric = "nclust",
                        clust.fun = clust_fun_tocher,
                        size = 0.2)
    dist_prop_out_nclust4
  }
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Diversity (Distance based) & Logarithmic
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

## Mean
dist_log_out_mean <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "mean",
                    size = 0.2)
dist_log_out_mean

## Median
dist_log_out_median <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "median",
                    size = 0.2)
dist_log_out_median

## Maximum
dist_log_out_max <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "max",
                    size = 0.2)
dist_log_out_max

## Range
dist_log_out_range <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "range",
                    size = 0.2)
dist_log_out_range

## Mean nearest-neighbour distance
dist_log_out_mnnd <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "mnnd",
                    size = 0.2)
dist_log_out_mnnd

## Minimum spanning tree length
dist_log_out_mstl <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "mstl",
                    size = 0.2)
dist_log_out_mstl

\donttest{
  ## Mean distance to centroid
  dist_log_out_mdc <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.log",
                      dist.mat = dist_matrix, metric = "mdc",
                      size = 0.2)
  dist_log_out_mdc

  ## Mean distance to median
  dist_log_out_mdm <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.log",
                      dist.mat = dist_matrix, metric = "mdm",
                      size = 0.2)
  dist_log_out_mdm
}

## Number of clusters

### UPGMA with hclust
dist_log_out_nclust1 <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.log",
                    dist.mat = dist_matrix, metric = "nclust",
                    clust.fun = clust_fun_upgma,
                    size = 0.2)
dist_log_out_nclust1

# Ward's minimum variance with fastcluster
if (requireNamespace('fastcluster', quietly = TRUE)) {
  dist_log_out_nclust2 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.log",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_ward,
                      size = 0.2)
  dist_log_out_nclust2
}

if (requireNamespace('dbscan', quietly = TRUE)) {
  # Density-based clustering with dbscan
  dist_log_out_nclust3 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.log",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_dbscan,
                      size = 0.2)
  dist_log_out_nclust3
}

\donttest{
  if (requireNamespace('biotools', quietly = TRUE)) {
    # Tocher's sequential clustering
    dist_log_out_nclust4 <-
      allocate.distance(data = data, names = "genotypes",
                        group = "Cluster", method = "dist.log",
                        dist.mat = dist_matrix, metric = "nclust",
                        clust.fun = clust_fun_tocher,
                        size = 0.2)
    dist_log_out_nclust4
  }
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Diversity (Distance based) & Square root
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

## Mean
dist_sqrt_out_mean <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "mean",
                    size = 0.2)
dist_sqrt_out_mean

## Median
dist_sqrt_out_median <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "median",
                    size = 0.2)
dist_sqrt_out_median

## Maximum
dist_sqrt_out_max <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "max",
                    size = 0.2)
dist_sqrt_out_max

## Range
dist_sqrt_out_range <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "range",
                    size = 0.2)
dist_sqrt_out_range

## Mean nearest-neighbour distance
dist_sqrt_out_mnnd <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "mnnd",
                    size = 0.2)
dist_sqrt_out_mnnd

## Minimum spanning tree length
dist_sqrt_out_mstl <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "mstl",
                    size = 0.2)
dist_sqrt_out_mstl

\donttest{
  ## Mean distance to centroid
  dist_sqrt_out_mdc <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.sqrt",
                      dist.mat = dist_matrix, metric = "mdc",
                      size = 0.2)
  dist_sqrt_out_mdc

  ## Mean distance to median
  dist_sqrt_out_mdm <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.sqrt",
                      dist.mat = dist_matrix, metric = "mdm",
                      size = 0.2)
  dist_sqrt_out_mdm
}

## Number of clusters

### UPGMA with hclust
dist_sqrt_out_nclust1 <-
  allocate.distance(data = data, names = "genotypes",
                    group = "Cluster", method = "dist.sqrt",
                    dist.mat = dist_matrix, metric = "nclust",
                    clust.fun = clust_fun_upgma,
                    size = 0.2)
dist_sqrt_out_nclust1

# Ward's minimum variance with fastcluster
if (requireNamespace('fastcluster', quietly = TRUE)) {
  dist_sqrt_out_nclust2 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.sqrt",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_ward,
                      size = 0.2)
  dist_sqrt_out_nclust2
}

if (requireNamespace('dbscan', quietly = TRUE)) {
  # Density-based clustering with dbscan
  dist_sqrt_out_nclust3 <-
    allocate.distance(data = data, names = "genotypes",
                      group = "Cluster", method = "dist.sqrt",
                      dist.mat = dist_matrix, metric = "nclust",
                      clust.fun = clust_fun_dbscan,
                      size = 0.2)
  dist_sqrt_out_nclust3
}

\donttest{
  if (requireNamespace('biotools', quietly = TRUE)) {
    # Tocher's sequential clustering
    dist_sqrt_out_nclust4 <-
      allocate.distance(data = data, names = "genotypes",
                        group = "Cluster", method = "dist.sqrt",
                        dist.mat = dist_matrix, metric = "nclust",
                        clust.fun = clust_fun_tocher,
                        size = 0.2)
    dist_sqrt_out_nclust4
  }
}
\dontshow{\}) # examplesIf}
}
\references{
\insertAllCited
}
\seealso{
\code{\link[SampleCore]{allocate.basic}},
  \code{\link[SampleCore]{allocate.diversity}}
}
