2014-01-21 28 views
0

我不知道我應該把像corrplot的代碼method=」spearman」看到sperman相關Corrplot意義

cor.mtest <- function(mat, conf.level = 0.95){ 
mat <- as.matrix(mat) 
n <- ncol(mat) 
p.mat <- lowCI.mat <- uppCI.mat <- matrix(NA, n, n) 
diag(p.mat) <- 0 
diag(lowCI.mat) <- diag(uppCI.mat) <- 1 
for(i in 1:(n-1)){ 
for(j in (i+1):n){ 
tmp <- cor.test(mat[,i], mat[,j], conf.level = conf.level) 
p.mat[i,j] <- p.mat[j,i] <- tmp$p.value 
lowCI.mat[i,j] <- lowCI.mat[j,i] <- tmp$conf.int[1] 
uppCI.mat[i,j] <- uppCI.mat[j,i] <- tmp$conf.int[2] 
} 
} 
return(list(p.mat, lowCI.mat, uppCI.mat)) 
} 
res1 <- cor.mtest(mtcars,0.95) 
+0

將'method ='spearman''添加到'cor.mtest'函數中的參數中,以便它成爲默認值(如果需要,用戶可以稍後更改它)。您還需要在'tmp < - cor.test'這行中添加'method = method' – rawr

+0

這不是一個非常有效的實現。但是,主要問題是它不會調整多個測試的p.values。 – Roland

回答

0

的論點method=」spearman」將被傳遞到cor.test功能的意義:

cor.test(mat[,i], mat[,j], conf.level = conf.level, method = 」spearman」) 

有關更多詳細信息,請參閱?cor.test的幫助頁面。