R,在topicmodels包中,如何访问类LDA的对象?

时间:2014-09-24 19:47:39

标签: r

我正在研究topicmodels R package,并尝试理解以下使用LDA函数和lda对象的示例:

data("AssociatedPress", package = "topicmodels")
control = list(alpha = 0.1)
lda <- LDA(AssociatedPress[1:20,], k = 2, method=”VEM”, control)
lda_inf <- posterior(lda, AssociatedPress[21:30,])

我想了解lda实例中的内容。 从包instruction document,我读到有以下对象:

call: Object of class "call".
Dim: Object of class "integer"; number of documents and terms.
control: Object of class "TopicModelcontrol"; options used for estimating the topic model.
k: Object of class "integer"; number of topics.
terms: Vector containing the term names.
....

问题在于我无法访问它们。 lda$call不起作用。

我怎么能这样做? 我怎么能读他们的内容?

1 个答案:

答案 0 :(得分:0)

LDA函数返回的对象是S4对象,因此它由 slots 组成。您可以通过@运算符访问它们。在这种情况下,您需要lda@call而不是lda$call来访问对象的call位置。

通过S4获取setClass对象定义。 S4对象和简单列表之间的最大区别在于,您可以根据需要修改列表的结构(添加或删除元素),而S4对象的结构在您确定时定义它的类并保持不变。例如,如果您尝试lda@mynewslot<-1:10,则会收到错误。