Skip to contents

Computes a PCA embedding of the marker-expression matrix and stores it in the reductions slot under the name "pca". PCA uses only base R and is always available; it is also the default input space for RunUMAP, RunTSNE, and RunSONG.

Usage

RunPCA(object, n_pcs = 30L, slot = "data", markers = NULL)

Arguments

object

A SpatialCellData-class object.

n_pcs

Integer. Number of principal components to keep. Capped at the rank of the data. Default 30.

slot

Character. "data" (default) or "counts".

markers

Character vector or NULL. Markers to use; NULL uses all.

Value

The object with a "pca" entry in its reductions slot.

Examples

counts <- matrix(rnorm(500), nrow = 50,
                 dimnames = list(NULL, paste0("M", 1:10)))
coords <- data.frame(x = runif(50), y = runif(50))
obj <- CreateSpatialObject(counts, coords)
obj <- RunPCA(obj, n_pcs = 5)
Embeddings(obj, "pca")[1:3, ]
#>            PC_1      PC_2        PC_3       PC_4       PC_5
#> [1,] -0.6317344 -1.075689  0.08886609  1.5880270  0.6946289
#> [2,] -1.8522907  1.020018 -0.40451205 -0.3801057  1.8177522
#> [3,]  0.4459276  1.697796  0.16265152 -0.7739793 -0.4787770