Select the number of clusters by specified criteria.

selectModel(obj, criteria = 'MBIC', pen.const=1)
  # S3 method for drscObject
selectModel(obj, criteria = 'MBIC', pen.const=1)
  # S3 method for Seurat
selectModel(obj, criteria = 'MBIC', pen.const=1)

Arguments

S

obj

an object with class Seurat by DR.SC or class drscObject by DR.SC_fit.

criteria

a string, specify the criteria used for selecting the number of clusters, supporting "MBIC", "BIC" and "AIC".

pen.const

an optional positive value, the adjusted constant used in the MBIC criteria. It usually takes value between 0.1 to 1.

Value

For S3 method of Seurat, it return a revised "Seurat" object with updated Idents(seu), spatial.drsc.cluster in the metadata and DimReduc object named dr-sc in the slot reductions. For S3 method of drscObject, it returns a list with the following components:

bestK

the selected number of clusters.

cluster

inferred class labels

hZ

extracted latent features.

icMat

a numeric matrix including the criteria value for each number of clusters K.

Author

Wei Liu

Note

nothing

See also

Examples

seu <- gendata_RNAExp(height=10, width=10,p=50, K=4)
library(Seurat)
seu <- NormalizeData(seu, verbose=FALSE)
# or choose 40 spatailly variable features using FindSVGs in DR.SC
seu <- FindSVGs(seu, nfeatures = 40, verbose=FALSE)
# users define the adjacency matrix
Adj_sp <- getAdj(seu, platform = 'ST')
#> Neighbors were identified for 100 out of 100 spots.
var.features <- seu@assays$RNA@var.features
X <- Matrix::t(seu[["RNA"]]@data[var.features,])
# maxIter = 2 is only used for illustration, and user can use default.
drscList <- DR.SC_fit(X,Adj_sp=Adj_sp ,K=4, maxIter=2, verbose=TRUE)
#> Fit DR-SC model...
#> -------------------Calculate inital values-------------
#> Using accurate PCA to obtain initial values
#> -------------------Finish computing inital values------------- 
#> -------------------Starting  ICM-EM algortihm-------------
#> iter = 2, loglik= -981.827503, dloglik=1.000000 
#> -------------------Complete!-------------
#> elasped time is :0.04
#> Finish DR-SC model fitting
drsc1 <- selectModel(drscList)
str(drsc1)
#> List of 4
#>  $ bestK  : Named num 4
#>   ..- attr(*, "names")= chr "K"
#>  $ cluster: num [1:100] 1 1 1 2 3 3 3 1 1 1 ...
#>  $ hZ     : num [1:100, 1:15] -7.94 -6.66 -9.91 14.41 11.98 ...
#>  $ icMat  : num [1, 1:2] 4 10653
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr "K"
#>   .. ..$ : chr [1:2] "K" "IC"