This function calculates the stability of Seurat clustering at different resolutions.
Arguments
- t
The seed number for reproducibility.
- df
The data frame containing the data for testing.
- vars_cont
Continuous variables for datathin.
- vars_cat
Categorical variables for datathin.
- normal_estimate
Estimates for normally distributed parameters for datathin.
- weibull_estimate
Estimates for weibull distributed parameters for datathin.
- ndim
Number of dimensions for Seurat
Examples
set.seed(1)
df <- data.frame(
a = rnorm(100, mean = 2, sd = 1),
b = rnorm(100, mean = 2, sd = 1),
x = rpois(100, lambda = 2),
y = rpois(100, lambda = 2),
z = rpois(100, lambda = 2)
)
vars_cont <- c("a", "b")
vars_cat <- c("x", "y", "z")
normal_estimate <-
matrix(c(0.5, 0.2),
nrow = nrow(df),
ncol = length(vars_cont)
)
weibull_estimate <-
matrix(c(0.5, 0.2, 0.7),
nrow = nrow(df),
ncol = length(vars_cat)
)
ndim <- 2
stabilityCSF(
t = 1,
df = df,
vars_cont = vars_cont,
vars_cat = vars_cat,
normal_estimate = normal_estimate,
weibull_estimate = weibull_estimate,
ndim = ndim
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Finding variable features for layer counts
#> Warning: span too small. fewer data values than degrees of freedom.
#> Warning: at -0.094261
#> Warning: radius 3.5942e-07
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: pseudoinverse used at -0.094261
#> Warning: neighborhood radius 0.00059952
#> Warning: reciprocal condition number 1
#> Warning: at 0.026841
#> Warning: radius 3.5942e-07
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: There are other near singularities as well. 3.5942e-07
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Centering and scaling data matrix
#> Warning: You're computing too large a percentage of total singular values, use a standard svd instead.
#> Warning: Only 4 dimensions have been computed.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> PC_ 1
#> Positive: Feature1, Feature4
#> Negative: Feature5, Feature2
#> PC_ 2
#> Positive: Feature3, Feature1
#> Negative: Feature4, Feature2
#> PC_ 3
#> Positive: Feature5, Feature4
#> Negative: Feature2, Feature1
#> PC_ 4
#> Positive: Feature1, Feature5
#> Negative: Feature3, Feature4
#> Computing nearest neighbor graph
#> Computing SNN
#> Finding variable features for layer counts
#> Warning: span too small. fewer data values than degrees of freedom.
#> Warning: at -0.10188
#> Warning: radius 3.6636e-07
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: pseudoinverse used at -0.10188
#> Warning: neighborhood radius 0.00060528
#> Warning: reciprocal condition number 1
#> Warning: at 0.020386
#> Warning: radius 3.6636e-07
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: There are other near singularities as well. 3.6636e-07
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Warning: zero-width neighborhood. make span bigger
#> Centering and scaling data matrix
#> Warning: You're computing too large a percentage of total singular values, use a standard svd instead.
#> Warning: Only 4 dimensions have been computed.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> Warning: Requested number is larger than the number of available items (5). Setting to 5.
#> PC_ 1
#> Positive: Feature5, Feature1
#> Negative: Feature2, Feature4
#> PC_ 2
#> Positive: Feature3, Feature2
#> Negative: Feature5, Feature1
#> PC_ 3
#> Positive: Feature1, Feature2
#> Negative: Feature5, Feature4
#> PC_ 4
#> Positive: Feature2, Feature5
#> Negative: Feature4, Feature3
#> Computing nearest neighbor graph
#> Computing SNN
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8000
#> Number of communities: 1
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.7310
#> Number of communities: 2
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6837
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6497
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6156
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5816
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5476
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5184
#> Number of communities: 4
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4923
#> Number of communities: 4
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4662
#> Number of communities: 4
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2235
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4401
#> Number of communities: 4
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8000
#> Number of communities: 1
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.7341
#> Number of communities: 2
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6808
#> Number of communities: 2
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6446
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6111
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5775
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5440
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5105
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4770
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4434
#> Number of communities: 3
#> Elapsed time: 0 seconds
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#>
#> Number of nodes: 100
#> Number of edges: 2333
#>
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4107
#> Number of communities: 4
#> Elapsed time: 0 seconds
#> RNA_snn_res.0.2 RNA_snn_res.0.3 RNA_snn_res.0.4 RNA_snn_res.0.5 RNA_snn_res.0.6
#> 1.00000000 -0.02221258 0.01853562 0.07671761 0.07671761
#> RNA_snn_res.0.7 RNA_snn_res.0.8 RNA_snn_res.0.9 RNA_snn_res.1 RNA_snn_res.1.1
#> 0.07671761 0.07671761 0.07267415 0.07267415 0.07267415
#> RNA_snn_res.1.2
#> 0.07516240