啓動時運行基於Quanteda的STM模型後估計元/主題關係DFM,我想估計對某些專題我的協變量的影響。STM:從DFM
運行STM模型運行正常,產生預期的主題,但是當使用estimateEffect
(在下面的腳本的最後一步)時,R會話被中止,通知有一個'致命錯誤'。
我如何估計我的協變量的影響,從DFM啓動時? STM手冊提供了從dfm運行STM模型的建議,但是我無法在此階段後找到如何處理協變量。
下面的代碼:
# Read texts with Quanteda
texts <- (readtext("C:/Users/renswilderom/Documents/Stuff Im working on at the moment/Newspaper articles DJ/test data/*.txt",
docvarsfrom = "filenames", dvsep = "_",
docvarnames = c("Date of Publication", "Length LexisNexis", "source"),
encoding = "UTF-8-BOM"))
mycorpus <- corpus(texts)
tokens <- tokens(mycorpus, remove_punct = TRUE, remove_numbers = TRUE, ngrams = 1)
mydfm <- dfm(tokens, remove = stopwords("english"), stem = TRUE)
# Run the STM model - Metadata is called with 'data = docvars(mycorpus)'
stm_from_dfm <- stm(mydfm, K = 10, prevalence =~ Date.of.Publication + source, gamma.prior='L1', data = docvars(mycorpus))
# Estimate effects
prep <- estimateEffect(1:10 ~ Date.of.Publication + source, stm_from_dfm,
meta = docvars(mycorpus), uncertainty = "Global")
另外,我從我的DFM文集作出了STM語料庫,利用STMcorpus <- asSTMCorpus(mydfm)
。但後來我無法運行STM模型,因爲它沒有識別我的元數據。遵循這種替代策略會更好嗎? (所以我需要在運行STMcorpus <- asSTMCorpus(mydfm)
後以某種方式將元數據與STMcorpus相關聯)。
這是很難沒有重現的示例 - 你能提供一個診斷?另外,我認爲當你做'asstMCorpus(mydfm)'時,quanteda包含了數據。元數據只是在一個名爲'data' – bstewart
肯定列表中的對象,這裏是我使用的實際報紙文章的一個樣本:https://wetransfer.com/downloads/a50d8b8fd524359751e8aa68bac3256c20171016160720/3f3bb29e40362434594f44aeee1e67f720171016160720/b425d8 I'dd喜歡從'stm_from_dfm'工作,但如果需要的話,我當然也可以從'asSTMCorpus(mydfm)工作'。我只是試着通過list數據來訪問元數據。 – Rens
我無法用你給我的數據樣本複製你的錯誤。如果你想分享你打電話之前工作區的副本'estimateEffect()'我可以嘗試從那裏 - 複製但除此之外沒有太多而不能重現問題,我可以做的。 – bstewart