scviva.tools.vision.apply_permutation_wpca#
- scviva.tools.vision.apply_permutation_wpca(X, max_components=50, p_threshold=0.05, n_repeats=20)[source]#
PCA with permutation significance test for automatic PC selection.
Based on the method of Buja & Eyuboglu (1992). Each gene’s expression is independently permuted across cells
n_repeatstimes; the resulting variance-explained values form a null distribution. A z-score is computed for each real PC against the null, and PCs are retained while their p-value (from the normal survival function) is below p_threshold. A minimum of 5 PCs is always kept.- Parameters:
- Return type:
- Returns:
- pca_coordsndarray of shape (n_cells, n_sig)
Cell scores for the retained PCs.
- variance_explainedndarray of shape (n_sig,)
Proportion of variance explained by each retained PC.
- gene_loadingsndarray of shape (n_genes, n_sig)
Gene loadings for each retained PC.
Notes
The R implementation slices
evec[1:k, ](rows) when it should sliceevec[, 1:k](columns) to subset PCs from the loading matrix. This is a bug in the R source; the Python implementation applies the correct column slice ongene_loadings.