Skip to contents

Applies the centred log-ratio (clr) transformation to the concatenated count tables, performs PCA on the sample covariance of the transformed data, and returns the smallest number of components whose eigenvalues explain at least prop of the total variance. This is the data-driven rule for setting K described in the paper.

Usage

choose_K(Y, prop = 0.95, pseudocount = 0.01, plot = FALSE)

Arguments

Y

A list of count matrices or a single concatenated count matrix, as accepted by spbgfm.

prop

Proportion of variance to explain. Default 0.95.

pseudocount

Added before the log transform. Default 0.01.

plot

Logical; draw a scree plot. Default FALSE.

Value

An integer, the suggested K, with the full eigenvalue vector attached as attribute "eigenvalues".

Examples

sim <- simulate_spbgfm(n = 20, J = c(30, 10), seed = 1)
choose_K(sim$Y)
#> [1] 15
#> attr(,"eigenvalues")
#>  [1] 1.816438e+02 1.688922e+02 1.476907e+02 1.239483e+02 1.034501e+02
#>  [6] 9.869789e+01 9.322948e+01 7.902583e+01 6.848777e+01 6.399509e+01
#> [11] 5.035996e+01 4.660711e+01 4.083188e+01 3.736084e+01 2.738740e+01
#> [16] 2.278891e+01 1.599022e+01 1.035264e+01 9.034334e+00 7.510382e-14
#> [21] 4.410055e-14 3.836352e-14 2.579396e-14 2.083141e-14 1.891188e-14
#> [26] 1.422415e-14 1.064261e-14 7.729605e-15 5.174082e-15 3.393038e-15
#> [31] 7.174809e-17 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
#> [36] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00