Open patrickjdanaher opened 1 year ago
@patrickjdanaher @lidanwu hey Patrick and Lidan, ran into this issue , (not sure it looks like might be the same dataset).
The issue was a single cell with celltype=="Unknown"
removing this one cell, was able to run calcSpatialCor
successfully.
I think there mgiht be a few ways to handle this in general, and maybe a tangential issue need to be addressed with the subsampling.
InSituCor::calcSpatialCor
## perform subsetting if needed:
use <- TRUE
if (nrow(counts) > max_cells) {
use <- sample(seq_len(nrow(counts)), max_cells, replace = FALSE)
}
cov_bb
is invertible
> InSituCor:::get_conditional_correlation
function(mat = NULL, condmat = NULL, outputtype = "cor") {
cov_aa <- Rfast::cova(mat)
cov_bb <- cov(condmat)
It looks like there are packages that claim to do this, but need to test, not sure how long the calculation is
matrixcalc::is.singular.matrix(mymatrix)
Other checks could include seeing whether cov(conditionon) off-diagonals are not '1' (one column completely correlated / singular with another column)
@patrickjdanaher with rare celltypes, the subsetting can elimnate all levels of that cell type, making the covariance matrix singular.
This doesn't necessarily happen every time.. sometimes it works if the Unknown cell was included in use
one solution: take the principal components of the conditionon matrix, and replace the original matrix with all PCs with eigenvalues < 1e-4.