2014-09-24 25 views
0

我工作的topicmodels R package,並試圖瞭解一個使用LDA功能和LDA對象下面的例子:R,在topicmodels包中,如何訪問類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

不知道這個包,但似乎'LDA'返回一個'S4'對象,因此你可以通過'@'操作符訪問它的插槽。嘗試'lda @ call'而不是'lda $ call'。 – nicola 2014-09-24 20:48:42

+0

@Nicola它的作品,謝謝! :-)如果你把它寫成答案,我會接受它 – 2014-09-24 22:01:18

回答

0

LDA函數返回的對象是一個S4對象,因此它由插槽組成。您可以通過@運營商訪問它們。在這種情況下,您需要[email protected]而不是lda$call來訪問對象的call插槽。

S4對象定義通過setClass獲得。 S4對象與簡單列表之間最大的不同之處在於,您可以根據需要修改列表的結構(添加或刪除元素),而當您定義其類並保持不變時,將確定對象的結構。例如,如果您嘗試[email protected]<-1:10,則會收到錯誤消息。