簡體   English   中英

使用數據矩陣的特定列進行Pearson相關(cor.test)

[英]Pearson correlation (cor.test) using specific columns of a data matrix

我正在嘗試確定兩組每6列之間的成對的皮爾遜相關系數和顯着性(p值)。

表

我正在使用以下腳本:

output <- matrix(dim(data2)[1]*4,dim(data2)[1],4)
for (i in dim(data)[1]){
    r<-cor.test(data[i,c(2:7)],data[i,c(9:14)],method="pearson")
    output[i,3]<-r$p.value
    output[i,4]<-r$estimate
    output[i,1]<-data[,1] # target geneID
    output[i,2]<-data[i,8] # miRNAID
}
colnames(output) <- c("geneID","miRNAID","p-val","corr")
head(output)

但是我對數據矩陣中的向量類型有疑問

在此處輸入圖片說明

非常感謝您對此問題的投入。

謝謝V

我想知道您是否要這樣做:

gene<-c("gene.17472635","gene.17436226","gene.17424189")
gene.C1<-c(216.22244180,0.04166939,29.58526377)
gene.C2<-c(210.4407513,0.6071574,24.684428)
gene.C3<-c(153.9317645,0.8830194,19.8798697)
gene.S1<-c(156.23494974,2.308891,23.345456)
gene.S2<-c(128.602680,4.568860,12.725349)
gene.S3<-c(52.928491,6.04392,7.174450)

data<-as.matrix(cbind(gene.C1,gene.C2,gene.C3,gene.S1,gene.S2,gene.S3))
cols<-t(combn(1:6,2))

gene_data_pval<-apply( cols , 1 , function(x) cor.test( data[,x[1]] , data[,x[2]],method="pearson")$p.value )
gene_data_estimate<-apply( cols , 1 , function(x) cor.test( data[,x[1]] , data[,x[2]],method="pearson")$estimate)
result1<-cbind(as.matrix(gene_data_pval),as.matrix(gene_data_estimate))
colnames(result1)<-c("p-val","est")

我不確定您是否想要這個或其他東西,因此只知道基因數據,但是代碼可以很容易地用於mri一個。

備注:您可以根據組合制作一個id向量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM