安装包
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
options()$repos
options()$BioC_mirror
BiocManager::install('bladderbatch') # 把数据准备好,这是包里内置的数据集
BiocManager::install('sva')
library(sva)
library(bladderbatch)
data(bladderdata)
dat <- bladderEset[1:50,]
使用内置数据
pheno = pData(dat)
edata = exprs(dat)
batch = pheno$batch
使用Hierarchical clustering的方法去看一下聚类的情况
dist_mat <- dist(t(edata))
clustering <- hclust(dist_mat, method = "complete")
plot(clustering, labels = pheno$batch)
plot(clustering, labels = pheno$cancer)
校正批次效应,model可以有也可以没有,如果有,也就是告诉combat,有些分组本来就有差别,不要给我矫枉过正!
mod = model.matrix(~as.factor(cancer), data=pheno)
combat_edata <- ComBat(dat = edata, batch = pheno$batch, mod = mod)
dist_mat_combat <- dist(t(combat_edata))
clustering_combat <- hclust(dist_mat_combat, method = "complete")
plot(clustering_combat, labels = pheno$batch)
plot(clustering_combat, labels = pheno$cancer)