ccs-amsterdam / r-course-material

A collection of R tutorials
Other
180 stars 82 forks source link

posterior #3

Open reddyakilesh22 opened 3 years ago

reddyakilesh22 commented 3 years ago

words = posterior(m)$terms[topic, ] Error in UseMethod("posterior") : no applicable method for 'posterior' applied to an object of class "c('LDA_Gibbs', 'LDA', 'Gibbs', 'TopicModel')"

I'm getting an error like this. what to do? Do I have to load any more libraries?

kasperwelbers commented 3 years ago

That's pretty weird, because the posterior method is in the topicmodels package (see here), and you should have loaded that already to create m (LDA is also in the topicmodels packages).

Maybe your R session reset for some reason. Could you try running library(topicmodels) again?

reddyakilesh22 commented 3 years ago

Nope, still not working. I cleared my environment and console and tried again but same error

vanatteveldt commented 3 years ago

It works for me:

> m = c("a text", "another text", "not very useful") %>% quanteda::dfm() %>% quanteda::convert(to="topicmodels") %>% LDA(k=2, method = "Gibbs")
Warning message:
'dfm.character()' is deprecated. Use 'tokens()' first. 
> m
A LDA_Gibbs topic model with 2 topics.
> class(m)
[1] "LDA_Gibbs"
attr(,"package")
[1] "topicmodels"
> posterior(m)
$terms
           a       text    another        not       very     useful
1 0.19642857 0.37500000 0.19642857 0.01785714 0.19642857 0.01785714
2 0.03846154 0.03846154 0.03846154 0.42307692 0.03846154 0.42307692

$topics
              1         2
text1 0.5192308 0.4807692
text2 0.5192308 0.4807692
text3 0.4905660 0.5094340

can you paste the output of sessionInfo(), the output of class(m), and the exact code you are running that produces an error?

reddyakilesh22 commented 3 years ago

m = c("a text", "another text", "not very useful") %>% quanteda::dfm() %>% quanteda::convert(to="topicmodels") %>% LDA(k=2, method = "Gibbs") m A LDA_Gibbs topic model with 2 topics. class(m) [1] "LDA_Gibbs" attr(,"package") [1] "topicmodels" posterior(m) Error in UseMethod("posterior") : no applicable method for 'posterior' applied to an object of class "c('LDA_Gibbs', 'LDA', 'Gibbs', 'TopicModel')"

This is the output of the above code

vanatteveldt commented 3 years ago

can you paste the output of sessionInfo()?

also, can you try reinstalling topicmodels?