我正在研究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
不起作用。
我怎么能这样做? 我怎么能读他们的内容?
答案 0 :(得分:0)
LDA
函数返回的对象是S4
对象,因此它由 slots 组成。您可以通过@
运算符访问它们。在这种情况下,您需要lda@call
而不是lda$call
来访问对象的call
位置。
通过S4
获取setClass
对象定义。 S4
对象和简单列表之间的最大区别在于,您可以根据需要修改列表的结构(添加或删除元素),而S4
对象的结构在您确定时定义它的类并保持不变。例如,如果您尝试lda@mynewslot<-1:10
,则会收到错误。