Skip to contents

Assess clustering stability by resampling cells and varying resolution.

Usage

VisClusterStability(
  object,
  resolution_range = seq(0.2, 1.2, by = 0.2),
  dims = 1:10,
  reps = 5,
  prop = 0.8,
  palette = "C"
)

Arguments

object

A Seurat object. PCA is computed when absent.

resolution_range

Numeric vector of resolutions. Default: seq(0.2, 1.2, by = 0.2).

dims

Integer vector of PCA dimensions used. Default: 1:10.

reps

Number of resampling repetitions. Default: 5.

prop

Proportion of cells sampled per repetition. Default: 0.8.

palette

Viridis palette option for color/fill. Default: "C".

Value

A list with summary (data.frame) and plot (ggplot) for stability.

Author

benben-miao

Examples

obj <- SeuratVisProExample(
    n_cells = 300,
    n_genes = 1000,
    n_clusters = 10,
    seed = 123,
    genes_mt = "^MT-",
    neighbor_dims = 10,
    cluster_res = 0.5,
    umap_dims = 10,
    spatial = FALSE)
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9485
#> Number of communities: 10
#> Elapsed time: 0 seconds

res <- VisClusterStability(
  obj,
  resolution_range = seq(0.2, 1.2, by = 0.2),
  dims = 1:10,
  reps = 5,
  prop = 0.8,
  palette = "C")
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9794
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9588
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9381
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9175
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8969
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8763
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9794
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9794
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2868
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9788
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9795
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 3115
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9699
#> Number of communities: 9
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2920
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9768
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9588
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9589
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2868
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9578
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9590
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 3115
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9473
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2920
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9556
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9381
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9383
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2868
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9368
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9384
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 3115
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9249
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2920
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9343
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9175
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9178
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2868
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9157
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9179
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 3115
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9026
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2920
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.9130
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8969
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8972
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2868
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8947
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8974
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 3115
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8802
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2920
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8917
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 300
#> Number of edges: 4508
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8763
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8767
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2868
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8737
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2831
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8769
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 3115
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8578
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 240
#> Number of edges: 2920
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8704
#> Number of communities: 10
#> Elapsed time: 0 seconds
#> Scale for colour is already present.
#> Adding another scale for colour, which will replace the existing scale.

res$plot

head(res$summary)
#> # A tibble: 6 × 2
#>   resolution agreement
#>        <dbl>     <dbl>
#> 1        0.2     0.402
#> 2        0.4     0.422
#> 3        0.6     0.422
#> 4        0.8     0.441
#> 5        1       0.422
#> 6        1.2     0.441