I am trying to find the math behind the "tm" package findAssocs() ?findAssocs does not say anything besides "association" and "correlate" Usually entering "findAssocs" at the CLI gives the code for a R function, but in this case I obtain: function (x, term, corlimit) UseMethod("findAssocs", x) <environment: namespace:tm> Any ideas? Thanks, Henri-Paul -- Henri-Paul Indiogine Curriculum & Instruction Texas A&M University TutorFind Learning Centre Email: hindiogine at gmail.com Skype: hindiogine Website: http://people.cehd.tamu.edu/~sindiogine
On 27/09/11 12:56, Henri-Paul Indiogine wrote:> I am trying to find the math behind the "tm" package findAssocs() > > ?findAssocs does not say anything besides "association" and "correlate" > > Usually entering "findAssocs" at the CLI gives the code for a R > function, but in this case I obtain: > > function (x, term, corlimit) > UseMethod("findAssocs", x) > <environment: namespace:tm> > > Any ideas?Yes. Apparently the findAssocs() function is *generic* and there is at least one *method* for it. Type methods(findAssocs) to find the list of all available methods. Then type the name of a particular method to see the code for that method. E.g. if there is a method "findAssocs.melvin" (which is the method "dispatched" when you invoke findAssocs(x) where "x" is an object of class "melvin") then typing findAssocs.melvin will show the code for this method. You should probably read up a bit on S3 methods and objects. ?S3Methods will give you a start. HTH cheers, Rolf Turner
Hi Here is some code to illustrate how the correlations are calculated.> data <- c("word1", "word1 word2","word1 word2 word3","word1 word2 word3 > word4","word1 word2 word3 word4 word5") > frame <- data.frame(data) > framedata 1 word1 2 word1 word2 3 word1 word2 word3 4 word1 word2 word3 word4 5 word1 word2 word3 word4 word5> test <- Corpus(DataframeSource(frame, encoding = "UTF-8")) > dtm <- DocumentTermMatrix(test) > as.matrix(dtm)Terms Docs word1 word2 word3 word4 word5 1 1 0 0 0 0 2 1 1 0 0 0 3 1 1 1 0 0 4 1 1 1 1 0 5 1 1 1 1 1> > findAssocs(dtm, "word2", 0.1)word2 word3 word4 word5 1.00 0.61 0.41 0.25> # Correlation word2 with word3 > cor(c(0,1,1,1,1),c(0,0,1,1,1))[1] 0.6123724> # Correlation word2 with word4 > cor(c(0,1,1,1,1),c(0,0,0,1,1))[1] 0.4082483> # Correlation word2 with word5 > cor(c(0,1,1,1,1),c(0,0,0,0,1))[1] 0.25 Cheers Rick -- View this message in context: http://r.789695.n4.nabble.com/findAssocs-tp3845751p4637248.html Sent from the R help mailing list archive at Nabble.com.