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 tsne_from_topics, this is passed as argument “dims” to Rtsne. In umap_from_topics, this is passed as argument “n_components” to umap.

center

A logical value indicating whether columns of fit$L should be zero-centered before performing PCA; passed as argument “center” to prcomp.

scale.

A logical value indicating whether columns of fit$L should be scaled to have unit variance prior to performing PCA; passed as argument “scale.” to prcomp.

...

Additional arguments passed to prcomp, Rtsne or umap.

pca

Whether to perform a PCA processing step in t-SNE or UMAP; passed as argument “pca” to Rtsne or umap.

normalize

Whether to normalize the data prior to running t-SNE; passed as argument “normalize” to Rtsne.

perplexity

t-SNE perplexity parameter, passed as argument “perplexity” to Rtsne. The perplexity is automatically revised if it is too large; see Rtsne for more information.

theta

t-SNE speed/accuracy trade-off parameter; passed as argument “theta” to Rtsne.

max_iter

Maximum number of t-SNE iterations; passed as argument “max_iter” to Rtsne.

eta

t-SNE learning rate parameter; passed as argument “eta” to Rtsne.

check_duplicates

When check_duplicates = TRUE, checks whether there are duplicate rows in fit$L; passed as argument “check_duplicates” to Rtsne.

verbose

If verbose = TRUE, progress updates are printed; passed as argument “verbose” to Rtsne or umap.

n_neighbors

Number of nearest neighbours in manifold approximation; passed as argument “n_neighbors” to umap.

metric

Distance matrix used to find nearest neighbors; passed as argument “metric” to umap.

scale

Scaling to apply to fit$L; passed as argument “scale” to umap.

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()



[Package fastTopics version 0.6-163 Index]