[Corpora-List] Software to find correlations in table

Stefan Th. Gries stgries at gmail.com
Thu Jul 17 22:01:50 UTC 2008


Just define or load a data frame xx as you did and paste the following
into R, which will give you Cramer's V correlations for all pairwise
column comparisons:

########
correlations<-function(qq) {
   cramers.v<-function(zz) { sqrt(chisq.test(zz,
correct=F)$statistic/(sum(zz)*(min(dim(zz))-1))) }
   counter<-0; pairwise.correlations<-vector()
   for (i in 1:(dim(qq)[2]-1)) {
      for (j in 2:(dim(qq)[2])) {
         counter<-counter+1
         pairwise.correlations[counter]<-cramers.v(table(qq[,i], qq[,j]))
         names(pairwise.correlations)[counter]<-paste(names(qq)[i],
names(qq)[j], sep="_&_")
      }
   }
   return(pairwise.correlations)
}
correlations(xx)
########

You can try it with this data frame, too:

aa<-sample(letters[1:4], 100, replace=T)
bb<-sample(letters[2:5], 100, replace=T)
cc<-sample(letters[3:6], 100, replace=T)
dd<-sample(letters[1:6], 100, replace=T)
xx<-data.frame(aa,bb,cc,dd)
correlations(xx)

HTH,
STG
--
Stefan Th. Gries
-----------------------------------------------
University of California, Santa Barbara
http://www.linguistics.ucsb.edu/faculty/stgries
-----------------------------------------------

_______________________________________________
Corpora mailing list
Corpora at uib.no
http://mailman.uib.no/listinfo/corpora



More information about the Corpora mailing list