Skip to contents

Perform Uniform Manifold Approximation and Projection on the matrix, adding UMAP coordinates to metadata and optionally storing the full umap object.

Usage

compute_umap(
  x,
  name = NULL,
  n_components = 2,
  store = TRUE,
  n_neighbors = 15,
  min_dist = 0.1,
  metric = "euclidean",
  random_state = NULL,
  ...
)

Arguments

x

A tidymatrix object

name

Name for this analysis. Default is "row_umap" or "column_umap" depending on active component.

n_components

Number of dimensions for UMAP embedding. Default is 2.

store

If TRUE, stores the full umap object for later retrieval with get_analysis(). Default is TRUE.

n_neighbors

Size of local neighborhood (default 15). Larger values preserve more global structure, smaller values preserve more local structure.

min_dist

Minimum distance between points in low-dimensional space (default 0.1). Smaller values create tighter, more separated clusters.

metric

Distance metric to use (default "euclidean"). Options include "manhattan", "cosine", "correlation", etc.

random_state

Seed for reproducibility (default NULL). Set to an integer for reproducible results.

...

Additional configuration passed via umap.defaults

Value

A tidymatrix object with UMAP coordinates added to metadata

Details

This function wraps umap::umap() and passes additional parameters through the config parameter. UMAP is generally faster than t-SNE and better preserves global structure.

Examples

if (requireNamespace("umap", quietly = TRUE)) {
mat <- matrix(rnorm(500), nrow = 50, ncol = 10)
row_data <- data.frame(id = 1:50)
tm <- tidymatrix(mat, row_data)

# UMAP on rows
tm <- tm |>
  activate(rows) |>
  compute_umap(n_components = 2, random_state = 42)

# Now row_data has row_umap_1, row_umap_2 columns

# Get full umap object
umap_obj <- get_analysis(tm, "row_umap")
}