Skip to contents

This implementation uses the RSpectra package to efficiently compute a small subset of eigenvalues and eigenvectors, as a small subset is typically used. Hence it's much faster and memory efficient than the original implementation in adespatial. However, this implementation here does not support row and column weighting other than the standard ones for PCA., so the adespatial implementation is more general.

Usage

multispati_rsp(x, listw, nfposi = 30L, nfnega = 30L, scale = TRUE)

Arguments

x

A matrix whose columns are features and rows are cells.

listw

A listw object, a spatial neighborhood graph for the cells in x. The length must be equal to the number of row of x.

nfposi

Number of positive eigenvalues and their eigenvectors to compute.

nfnega

Number of nega eigenvalues and their eigenvectors to compute. These indicate negative spatial autocorrelation.

scale

Logical, whether to scale the data.

Value

A matrix for the cell embeddings in each spatial PC, with attribute

loading for the eigenvectors or gene loadings, and attribute

eig for the eigenvalues.

Note

Eigen decomposition will fail if any feature has variance zero leading to NaN in the scaled matrix.

References

Dray, S., Said, S. and Debias, F. (2008) Spatial ordination of vegetation data using a generalization of Wartenberg's multivariate spatial correlation. Journal of vegetation science, 19, 45-56.

Examples

library(SFEData)
library(scater)
sfe <- McKellarMuscleData("small")
#> see ?SFEData and browseVignettes('SFEData') for documentation
#> loading from cache
sfe <- sfe[,sfe$in_tissue]
sfe <- logNormCounts(sfe)
inds <- order(rowSums(logcounts(sfe)), decreasing = TRUE)[1:50]
mat <- logcounts(sfe)[inds,]
g <- findVisiumGraph(sfe)
out <- multispati_rsp(t(mat), listw = g, nfposi = 10, nfnega = 10)