pca_from_topics {fastTopics} | R Documentation |
Low-dimensional Embeddings from Poisson NMF or Multinomial Topic Model
Description
Lightweight interface for rapidly producing low-dimensional embeddings from matrix factorizations or multinomial topic models. The defaults used are more suitable for producing embeddings from matrix factorizations or topic models.
Usage
pca_from_topics(fit, dims = 2, center = TRUE, scale. = FALSE, ...)
tsne_from_topics(
fit,
dims = 2,
pca = FALSE,
normalize = FALSE,
perplexity = 100,
theta = 0.1,
max_iter = 1000,
eta = 200,
check_duplicates = FALSE,
verbose = TRUE,
...
)
umap_from_topics(
fit,
dims = 2,
n_neighbors = 30,
metric = "euclidean",
scale = "none",
pca = NULL,
verbose = TRUE,
...
)
Arguments
fit |
An object of class “poisson_nmf_fit” or “multinom_topic_model_fit”. |
dims |
The number of dimensions in the embedding. In
|
center |
A logical value indicating whether columns of
|
scale. |
A logical value indicating whether columns of
|
... |
|
pca |
Whether to perform a PCA processing step in t-SNE or
UMAP; passed as argument “pca” to |
normalize |
Whether to normalize the data prior to running
t-SNE; passed as argument “normalize” to
|
perplexity |
t-SNE perplexity parameter, passed as argument
“perplexity” to |
theta |
t-SNE speed/accuracy trade-off parameter; passed as
argument “theta” to |
max_iter |
Maximum number of t-SNE iterations; passed as
argument “max_iter” to |
eta |
t-SNE learning rate parameter; passed as argument
“eta” to |
check_duplicates |
When |
verbose |
If |
n_neighbors |
Number of nearest neighbours in manifold
approximation; passed as argument “n_neighbors” to
|
metric |
Distance matrix used to find nearest neighbors;
passed as argument “metric” to
|
scale |
Scaling to apply to |
Details
Note that since tsne_from_topics
and
umap_from_topics
use nonlinear transformations of the data,
distances between points are generally less interpretable than a
linear transformation obtained by, say, PCA.
Value
An n x d matrix containing the embedding, where n is the
number of rows of fit$L
, and d = dims
.
References
Kobak, D. and Berens, P. (2019). The art of using t-SNE for single-cell transcriptomics. Nature Communications 10, 5416. doi:10.1038/s41467-019-13056-x
See Also
pca_plot
, tsne_plot
,
umap_plot
, prcomp
,
Rtsne
, umap
Examples
library(ggplot2)
library(cowplot)
set.seed(1)
data(pbmc_facs)
# Get the Poisson NMF and multinomial topic model fit to the PBMC data.
fit1 <- multinom2poisson(pbmc_facs$fit)
fit2 <- pbmc_facs$fit
fit2 <- poisson2multinom(fit1)
# Compute the first two PCs of the loadings matrix (for the topic
# model, fit2, the loadings are the topic proportions).
Y1 <- pca_from_topics(fit1)
Y2 <- pca_from_topics(fit2)
subpop <- pbmc_facs$samples$subpop
quickplot(Y1[,1],Y1[,2],color = subpop) + theme_cowplot()
quickplot(Y2[,1],Y2[,2],color = subpop) + theme_cowplot()
# Compute a 2-d embedding of the loadings using t-SNE.
Y1 <- tsne_from_topics(fit1)
Y2 <- tsne_from_topics(fit2)
quickplot(Y1[,1],Y1[,2],color = subpop) + theme_cowplot()
quickplot(Y2[,1],Y2[,2],color = subpop) + theme_cowplot()
# Compute a 2-d embedding of the loadings using UMAP.
Y1 <- umap_from_topics(fit1)
Y2 <- umap_from_topics(fit2)
quickplot(Y1[,1],Y1[,2],color = subpop) + theme_cowplot()
quickplot(Y2[,1],Y2[,2],color = subpop) + theme_cowplot()