cor2adj<-function(corMat,n,fine=F){ if(any(abs(corMat)>1)){ stop("Input values must be between -1 and 1") } adj<-1e-15 pckg = try(require(EbayesThresh)) if(!pckg) { cat("Installing 'EbayesThresh' from CRAN\n") install.packages("EbayesThresh", repos = "http://cran.r-project.org") require(EbayesThresh) } corMat<-corMat*(1-adj) zMat<-(log(1+corMat)-log(1-corMat))*sqrt(n-3)/2 rm(list="corMat") diag(zMat)<-0 threshZmat<-zMat[lower.tri(zMat)] if(fine){ eBayesFit<-ebayesthresh(threshZmat,prior="laplace",a=NA,bayesfac=T,sdev=1,verbose=T,threshrule="median") }else{ eBayesFit<-ebayesthresh(threshZmat,prior="laplace",a=0.5,bayesfac=T,sdev=1,verbose=T,threshrule="median") } eBayesThresh<-eBayesFit[["threshold.origscale"]] adjMat<-abs(zMat)>eBayesThresh diag(adjMat)<-0 mode(adjMat)<-"integer" dimnames(adjMat)<-dimnames(zMat) return(adjMat) }