% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functional_distances.R
\name{functional_distances}
\alias{functional_distances}
\title{Compute pairwise functional distances and cluster curves}
\usage{
functional_distances(
  object,
  cluster_k = 4,
  hc_method = "ward.D2",
  test_factor = NULL,
  n_perm = 999,
  test_mode = c("auto", "none", "global", "global_pairwise"),
  min_strata_for_pairwise = 6,
  perm_unit = NULL,
  perm_strata = NULL,
  bootstrap = FALSE,
  boot_B = 399,
  boot_seed = 1,
  boot_ci = c(0.025, 0.975),
  show_progress = TRUE,
  curve_level = NULL,
  ...
)
}
\arguments{
\item{object}{An object of class \code{functional_curves}.}

\item{cluster_k}{Number of clusters used to cut the hierarchical tree.}

\item{hc_method}{Clustering linkage method passed to \code{stats::hclust()}.}

\item{test_factor}{Optional a priori grouping used for a distance-based permutation test.}

\item{n_perm}{Number of permutations for the distance-based test.}

\item{test_mode}{Character; permutation test mode.}

\item{min_strata_for_pairwise}{Minimum number of strata levels required for pairwise tests.}

\item{perm_unit}{Optional character naming the unit at which group labels are permuted.}

\item{perm_strata}{Optional character naming a factor defining restricted permutation strata.}

\item{bootstrap}{Logical; if \code{TRUE}, compute bootstrap envelopes and distance summaries.}

\item{boot_B}{Integer number of bootstrap replicates.}

\item{boot_seed}{Integer seed for bootstrap resampling.}

\item{boot_ci}{Length-2 numeric vector of quantiles for bootstrap intervals.}

\item{show_progress}{Logical; whether to show progress.}

\item{curve_level}{Logical; whether to compute curve-level distance matrix.}

\item{...}{Additional arguments.}
}
\value{
An object of class \code{"functional_distances"} containing:
\itemize{
\item \code{distance}: treatment-by-treatment functional distance matrix;
\item \code{distance_table}: pairwise distances as a data frame;
\item \code{hc}: \code{hclust} object;
\item \code{clusters}: treatment cluster assignments;
\item \code{curve_distance}: curve-by-curve distance matrix;
\item \code{test}: permutation test results;
\item \code{bootstrap}: bootstrap results if requested.
}
}
\description{
Computes L2 functional distances among treatment mean trajectories evaluated on a
common time grid from a \code{functional_curves} object. Also computes curve-level
distances, performs hierarchical clustering, and optionally performs permutation testing.
}
\examples{
\dontrun{
fd <- functional_distances(fc, cluster_k = 4)
print(fd)
plot_dendrogram(fd)
plot_curves(fd)
}
}
