cluster_solutions: Cluster CTS solutions by source contribution similarity

View source: R/cluster_solutions.R

cluster_solutionsR Documentation

Cluster CTS solutions by source contribution similarity

Description

Takes the output of CTS_n_sources and groups the tracer combinations into clusters of similar source contributions (w1, w2, ...). This helps identify the dominant apportionment solutions and how many individual tracers support each one.

Usage

cluster_solutions(
  cts_result,
  top_n = 50L,
  k = NULL,
  max_k = 6L,
  interactive = FALSE,
  seed = NULL
)

Arguments

cts_result

Data frame returned by CTS_n_sources or any of the CTS_*_sources functions.

top_n

Integer. Number of top rows to use for clustering. Default 50.

k

Integer or NULL. Number of clusters. If NULL (default), chosen automatically via silhouette width.

max_k

Integer. Maximum k to evaluate when k = NULL. Default 6.

interactive

Boolean. If TRUE and n_sources == 3, produces an interactive 3D plotly scatter. Ignored for 2 or 4+ sources. Default FALSE.

seed

Integer or NULL. Random seed for reproducibility.

Details

Hierarchical clustering with Ward.D2 linkage is used because contribution clusters are rarely spherical or equal-sized. The optimal number of clusters is selected automatically via the average silhouette width criterion, but can be overridden with the k argument.

Visualisation adapts to the number of sources:

  • 2 sources: single 2D panel (w1 vs w2).

  • 3 sources: two 2D panels (w1~w2, w1~w3) plus optional interactive 3D plotly scatter.

  • 4+ sources: all pairwise 2D panels as a grid. Interactive 3D is not available (dimensionality reduction would obscure interpretation).

Value

A named list:

summary

Data frame: one row per cluster with mean/SD of each contribution, n_pairs, n_unique_tracers, avg_silhouette.

tracers

Named list. Each element has $pairs (character vector) and $individual_tracers (data frame ranked by frequency).

plot

ggplot2 or plotly visualisation.


OceanTracer documentation built on Oct. 15, 2026, 5:09 p.m.