findAssocs()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

findAssocs()

hindiogine
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: [hidden email]
Skype: hindiogine
Website: http://people.cehd.tamu.edu/~sindiogine

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: findAssocs()

Rolf Turner-3
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: findAssocs()

rtw30606
In reply to this post by hindiogine
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)
> frame
                           data
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