Perform t-distributed Stochastic Neighbor Embedding on the matrix, adding t-SNE coordinates to metadata and optionally storing the full Rtsne object.
Arguments
- x
A tidymatrix object
- name
Name for this analysis. Default is "row_tsne" or "column_tsne" depending on active component.
- dims
Number of dimensions for t-SNE embedding. Default is 2.
- store
If TRUE, stores the full Rtsne object for later retrieval with
get_analysis(). Default is TRUE.- perplexity
Perplexity parameter (default 30). Should be less than the number of samples. Typical values are between 5 and 50.
- ...
Additional arguments passed to
Rtsne::Rtsne(), such astheta,max_iter,verbose, etc.
Details
This function wraps Rtsne::Rtsne() and passes all additional
parameters directly to it. Note that t-SNE is stochastic, so use
set.seed() before calling for reproducible results.
Examples
if (requireNamespace("Rtsne", quietly = TRUE)) {
mat <- matrix(rnorm(500), nrow = 50, ncol = 10)
row_data <- data.frame(id = 1:50)
tm <- tidymatrix(mat, row_data)
# t-SNE on rows
set.seed(42) # For reproducibility
tm <- tm |>
activate(rows) |>
compute_tsne(dims = 2, perplexity = 10)
# Now row_data has row_tsne_1, row_tsne_2 columns
# Get full Rtsne object
tsne_obj <- get_analysis(tm, "row_tsne")
}