Skip to contents

This function calculates the stability of Seurat clustering at different resolutions for blood data.

Usage

stabilityBlood(t, df, vars_cont, normal_estimate, ndim)

Arguments

t

The seed number for reproducibility.

df

The data frame containing the data for testing.

vars_cont

Continuous variables for datathin.

normal_estimate

Estimates for normally distributed parameters for datathin.

ndim

Number of dimensions for Seurat.

Value

A named vector of stability values.

Examples

set.seed(1)
df <- data.frame(
    a = stats::rnorm(100, mean = 2, sd = 1),
    b = stats::rnorm(100, mean = 2, sd = 2),
    c = stats::rnorm(100, mean = 2, sd = 1),
    d = stats::rnorm(100, mean = 2, sd = 2),
    e = stats::rnorm(100, mean = 2, sd = 1)
)
vars_cont <- c("a", "b", "c", "d", "e")
normal_estimate <-
    matrix(c(0.5, 0.1, 0.7, 0.2, 0.3),
        nrow = nrow(df),
        ncol = length(vars_cont)
    )
ndim <- 2
stabilityBlood(
    t = 1,
    df = df,
    vars_cont = vars_cont,
    normal_estimate = normal_estimate,
    ndim = ndim
)
#> Registered S3 method overwritten by 'spatstat.geom':
#>   method       from     
#>   print.metric yardstick
#> 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.033995
#> Warning: radius  1.0129e-07
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: pseudoinverse used at -0.033995
#> Warning: neighborhood radius 0.00031826
#> Warning: reciprocal condition number  1
#> Warning: at  0.030293
#> Warning: radius  1.0129e-07
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: There are other near singularities as well. 1.0129e-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:  Feature3, Feature4 
#> Negative:  Feature2, Feature5 
#> PC_ 2 
#> Positive:  Feature5, Feature1 
#> Negative:  Feature4, Feature3 
#> PC_ 3 
#> Positive:  Feature2, Feature4 
#> Negative:  Feature1, Feature3 
#> PC_ 4 
#> Positive:  Feature3, Feature2 
#> Negative:  Feature5, 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.0027889
#> Warning: radius  1.7559e-08
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: pseudoinverse used at -0.0027889
#> Warning: neighborhood radius 0.00013251
#> Warning: reciprocal condition number  1
#> Warning: at  0.023978
#> Warning: radius  1.7559e-08
#> Warning: all data on boundary of neighborhood. make span bigger
#> Warning: There are other near singularities as well. 1.7559e-08
#> 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:  Feature4, Feature1 
#> Negative:  Feature2, Feature5 
#> PC_ 2 
#> Positive:  Feature1, Feature5 
#> Negative:  Feature3, Feature4 
#> PC_ 3 
#> Positive:  Feature4, Feature1 
#> Negative:  Feature2, Feature3 
#> PC_ 4 
#> Positive:  Feature4, Feature5 
#> Negative:  Feature3, Feature1 
#> 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: 2309
#> 
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.7103
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6573
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6239
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5906
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5572
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5238
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4905
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4571
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4238
#> 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: 2309
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.3904
#> 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: 2327
#> 
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.7000
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.6384
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5890
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5528
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.5166
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4804
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4492
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.4226
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.3962
#> 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: 2327
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.3703
#> 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.00000000      0.11392504      0.08479700      0.08479700 
#> 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.08479700      0.08479700      0.08642228      0.08642228      0.08118260 
#> RNA_snn_res.1.2 
#>      0.08118260