[R] many correlations
William Revelle
lists at revelle.net
Wed Sep 10 19:30:57 CEST 2008
Stephen and Jorge,
Perhaps a simpler solution is to use the which function
test.data <- Harman74.cor$cov #a test data set
td <- test.data * lower.tri(test.data) #this will examine only the
lower off diagonal elements
td.1 <- which(abs(td)>.6,arr.ind=TRUE) # the critical pairs
td.2 <- td[which(abs(td)>.6)] # the values
td.row <- colnames(test.data)[td.1[,1]] #get the row names
td.col <- colnames(test.data)[td.1[,2]] #and the column names
td.df <- data.frame(td.row,td.col,correl = td.2) #put it all together
Bill
At 12:57 PM -0400 9/3/08, Jorge Ivan Velez wrote:
>Dear Stephen,
>Perhaps
>this<http://www.nabble.com/Re:-applying-cor.test-to-a-(m,-n)-matrix---SUMMARY-to17150239.html#a17150239>post
>could helps. In general:
>
>
># Function
>correl.stats=function(X, method = "pearson", use = "complete" , conf.level =
>0.95){
>require(forward)
>combs=t(fwd.combn(colnames(X), 2))
>temp=t(apply(combs,1, function(x){
>Y=X[,as.character(x)]
>res=cor.test(Y[,1],Y[,2], use = use, method = method, conf.level =
>conf.level)
>temp2=c(res$estimate, res$statistic, res$p.value, res$conf.int[1:2])
>names(temp2)=c('rho','statistic','pvalue','lower','upper')
>rm(res)
>temp2
>}
>)
>)
>rownames(temp)=paste(combs[,1],combs[,2],sep="")
>temp
>}
>
># Data set
>set.seed(123)
>m <- matrix(rnorm(10*5), ncol=5); colnames(m)=paste("m",1:ncol(m),sep="")
>
># Correlations
>res=correl.stats(m)
>res
>rho statistic pvalue lower upper
>m1m2 0.57761512 2.00137666 0.08034470 -0.08173768 0.88528096
>m1m3 -0.40595930 -1.25641472 0.24441138 -0.82477175 0.30046722
>m1m4 0.67301956 2.57371995 0.03293644 0.07530295 0.91493950
>m1m5 -0.34863673 -1.05210481 0.32348990 -0.80217657 0.36001727
>m2m3 -0.56734869 -1.94869211 0.08716815 -0.88193296 0.09688755
>m2m4 0.27131880 0.79731302 0.44828479 -0.43212763 0.76949303
>m2m5 -0.25201740 -0.73658790 0.48241166 -0.76090564 0.44882739
>m3m4 -0.43726491 -1.37521060 0.20634394 -0.83657173 0.26544083
>m3m5 0.02265933 0.06410673 0.95045815 -0.61575185 0.64311043
>m4m5 0.07453706 0.21141075 0.83785303 -0.58242262 0.67259801
>
>
># Filtering
>res[res[,'rho']>0.6,]
> rho statistic pvalue lower upper
>0.67301956 2.57371995 0.03293644 0.07530295 0.91493950
>
>
>HTH,
>
>Jorge
>
>
>On Wed, Sep 3, 2008 at 11:04 AM, stephen sefick <ssefick at gmail.com> wrote:
>
>> I have one hundred and six independent variable that I would like to
>> preform a correlation analysis on. Is there anyway to only get the
>> values that are abolute value 0.6 or greater.
>> thanks
>>
>>
>> --
>> Stephen Sefick
>> Research Scientist
>> Southeastern Natural Sciences Academy
>>
>> Let's not spend our time and resources thinking about things that are
>> so little or so large that all they really do for us is puff us up and
>> make us feel like gods. We are mammals, and have not exhausted the
>> annoying little problems of being mammals.
>>
>> -K. Mullis
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
William Revelle http://personality-project.org/revelle.html
Professor http://personality-project.org/personality.html
Department of Psychology http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Attend ISSID/ARP:2009 http://issid.org/issid.2009/
More information about the R-help
mailing list