Skip to contents

For each feature, computes the sample-by-sample cosine similarity between its embedding vectors in the different samples. One minus this matrix is the feature-specific sample distance \(D_f\) whose lower triangle forms the feature's stratification profile in unsupervised subgroup detection; the matrices can also be passed to plot_mds_cluster to visualize how a feature's embedding varies across samples.

Usage

compute_feature_similarity(mosaic_embed_list, feature_idx = NULL)

Arguments

mosaic_embed_list

Named list of per-sample embedding matrices (features x latent dimensions), as returned by run_MOSAIC()$mosaic_embed_list.

feature_idx

Optional integer vector of features (row indices). By default all features are used.

Value

A list with one symmetric n_samples x n_samples cosine similarity matrix per feature, named by feature. A zero embedding vector has similarity 0 to every other sample.

Examples

if (FALSE) { # \dontrun{
sim_list <- compute_feature_similarity(result$mosaic_embed_list)

# Stratification profiles and feature-feature Spearman correlation
strat <- sapply(sim_list, function(m) m[lower.tri(m)])
feature_corr <- cor(strat, method = "spearman")
} # }