This function computes low-dimensional cell embeddings from a gene-by-cell matrix. The method initializes cell embeddings using approximate PCA and refines them through a linear factor model nested a intrinsical conditional autoregressive model.

cellembedding_matrix(X, adjm, q = 50, reduction.name = "caesar", ...)

Arguments

X

A gene-by-cell matrix (e.g., the `data` slot from a Seurat object) that serves as the input data for dimensional reduction.

adjm

A spatial adjacency matrix representing the relationships between cells or spots in spatial transcriptomic data.

q

An integer specifying the number of dimensions to reduce to. Default is 50.

reduction.name

A character string specifying the name of the dimensional reduction method. Default is 'caesar'.

...

Additional parameters passed to `ProFAST::FAST_run`.

Value

A matrix containing the computed cell embeddings. The number of rows corresponds to the number of cells, and the number of columns corresponds to the specified number of dimensions (`q`).

See also

FAST_run for the main FAST dimensionality reduction algorithm.

Examples

data(toydata)

seu <- toydata$seu
pos <- toydata$pos

adjm <- ProFAST::AddAdj(as.matrix(pos), radius.upper = 200)
#> The spatial cooridnates are 2 dimensions
#> Find the adjacency matrix by bisection method...
#> Current radius is 100.5
#> Median of neighborhoods is 0
#> Current radius is 50.75
#> Median of neighborhoods is 17
#> Current radius is 50.75
#> Median of neighborhoods is 4
X <- Seurat::GetAssayData(object = seu, slot = "data", assay = "RNA")
cellembedding <- cellembedding_matrix(
    X = X,
    adjm = adjm
)
#> Finish variable intialization 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 2, loglik= -597713.932765, dloglik=0.999722 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 3, loglik= -572981.633443, dloglik=0.041378 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 4, loglik= -568540.760390, dloglik=0.007750 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 5, loglik= -565577.203830, dloglik=0.005213 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 6, loglik= -563808.620547, dloglik=0.003127 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 7, loglik= -562445.787433, dloglik=0.002417 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 8, loglik= -561479.215323, dloglik=0.001719 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 9, loglik= -560721.438599, dloglik=0.001350 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 10, loglik= -560111.513183, dloglik=0.001088 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 11, loglik= -559583.251469, dloglik=0.000943 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 12, loglik= -559112.175571, dloglik=0.000842 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 13, loglik= -558672.733365, dloglik=0.000786 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 14, loglik= -558253.012300, dloglik=0.000751 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 15, loglik= -557843.814583, dloglik=0.000733 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 16, loglik= -557444.260607, dloglik=0.000716 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 17, loglik= -557056.241772, dloglik=0.000696 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 18, loglik= -556685.140174, dloglik=0.000666 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 19, loglik= -556336.124902, dloglik=0.000627 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 20, loglik= -556014.108493, dloglik=0.000579 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 21, loglik= -555721.816223, dloglik=0.000526 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 22, loglik= -555459.782139, dloglik=0.000472 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 23, loglik= -555225.898188, dloglik=0.000421 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 24, loglik= -555016.558071, dloglik=0.000377 
#> Satrt ICM and E-step! 
#> Finish ICM and E-step! 
#> iter = 25, loglik= -554827.351177, dloglik=0.000341 
print(cellembedding[1:3, 1:3])
#>        caesar_1  caesar_2   caesar_3
#> 24387 -5.975308  8.496165  6.2566729
#> 4049  -7.061217 -3.932074 -0.6449155
#> 11570 -8.719022 -6.024967 -1.9306196