LR
- 对于每个基因:利用逻辑回归,使用这个基因的表达来预测分组(属于(1) 或 不属于(0)这个细胞类型),如果有隐变量,就也作为自变量加到回归模型里。
- 函数:Seurat:::LRDETest
function (data.use, cells.1, cells.2, latent.vars = NULL, verbose = TRUE)
{
group.info <- data.frame(row.names = c(cells.1, cells.2))
group.info[cells.1, "group"] <- "Group1"
group.info[cells.2, "group"] <- "Group2"
group.info[, "group"] <- factor(x = group.info[, "group"])
data.use <- data.use[, rownames(group.info), drop = FALSE]
latent.vars <- latent.vars[rownames(group.info), , drop = FALSE]
my.sapply <- ifelse(test = verbose && nbrOfWorkers() == 1,
yes = pbsapply, no = future_sapply)
p_val <- my.sapply(X = 1:nrow(x = data.use), FUN = function(x) {
if (is.null(x = latent.vars)) {
model.data <- cbind(GENE = data.use[x, ], group.info)
fmla <- as.formula(object = "group ~ GENE")
fmla2 <- as.formula(object = "group ~ 1")
}
else {
model.data <- cbind(GENE = data.use[x, ], group.info,
latent.vars)
fmla <- as.formula(object = paste("group ~ GENE +",
paste(colnames(x = latent.vars), collapse = "+")))
fmla2 <- as.formula(object = paste("group ~", paste(colnames(x = latent.vars),
collapse = "+")))
}
model1 <- glm(formula = fmla, data = model.data, family = "binomial")
model2 <- glm(formula = fmla2, data = model.data, family = "binomial")
lrtest <- lrtest(model1, model2)
return(lrtest$Pr[2])
})
to.return <- data.frame(p_val, row.names = rownames(data.use))
return(to.return)
}
未完待续