次元(50x752)のデータフレームでchisq.testを実行したいと思います。すべての列のすべての可能なペアワイズ比較のp値(多重検定によって調整)を取得したいと思います。最後に、行列(50x50)を取得して、調整されたカイ2乗p値のヒートマップを生成します。これが私が今していることですが、これははるかに理想的です。
ステップ1:ペアワイズ比較を行う
function(data,p.adjust.method="holm")
{
cor.mat <- cor(data)
x<-ncol(data)#nb of column in matrix here 50
y<-nrow(data)#nb of column in matrix here 758
index<-t(combn(x, 2)) #create the matrix position of output for all possible combination
nindex <- nrow(index)
pvals <- numeric(nindex)
for (i in 1:nindex)
{
pvals[i]<-chisq.test(data[, index[i, 1]], data[, index[i,2]])$p.value
}
pvals<-p.adjust(pvals,method = p.adjust.method)
out <- as.data.frame(cbind(index, pvals))
}
ステップ2:出力テーブルはを使用して行列に変換されます
dcast(df,V2~V1,fill=1) # thanx to Roland for this function!
しかし、これはうまく機能していません。最終的な行列のp値をミラーリングしておらず、1番目の関数の出力を操作して対角線を0で埋める必要があるためです(列をそれ自体と比較する場合)。あなたの助けは大歓迎です!