STM 结构主题模型中加入协变量。
这是运行STM和estimateEffect 的代码, 因为我想要加入rating, gender,app,date总共4个协变量,并且需要看ratinggender和 apprating的调节变量的结果,所以在prevalence里面全部都加上了。
dating_model <- stm(documents = dating_dfm_stm$documents,
vocab = dating_dfm_stm$vocab,
data = dating_dfm_stm$meta,
prevalence = ~rating + gender + app + rating*gender + app*rating + s(date),
K = 9,
init.type = "Spectral",
max.em.its = 75,seed = 1234,
verbose = TRUE)
dating_estimateEffect <- estimateEffect(formula = 1:9 ~rating + gender + app + (rating*gender) + (app*rating) + s(date),
dating_model,
meta = dating_dfm_stm$meta,
uncertainty = "Global")
summary(dating_estimateEffect)
plot(dating_estimateEffect,
covariate = "rating", #the covariate of interest.
topics = 1:9,
model = dating_model,
method = "difference",
cov.value1 = "1", cov.value2 = "0", #two different values of the covariate
ci.level = .95, # Confidence level for confidence intervals.
xlim = c(-.3, .3),
labeltype = "custom", # The default: "number",
# option: "custom", "prob", "frex", "score", "lift".
custom.labels = paste0("Topic", seq(1:11)),
xlab = "More Negative ...... More Positive",
main = "Effect of rating")
能够运行,但是这样plot(dating_estimateEffect)之后得出来的图的结果,和summary(dating_estimateEffect)得出来的结果是不一样的!
我在prevalence协变量中只放rating + gender + app +s(date)的话结果就是一样的,但是只要加了ratinggender或者apprating的话,结果就不一样了
看了下说明应该是需要分开建立两个模型,但是这样做的依据是什么?
如果x一个固定数组值,多次summary(x)会返回同一结果。如果x包含运算,可能会改变返回结果。
你可以试试:
summary(dating_estimateEffect)
plot(dating_estimateEffect, 。。。
改为
summary(dating_estimateEffect)
summary(dating_estimateEffect)
两次的输出是否结果一致。还有2次 summary(dating_estimateEffect,dating_model)的结果。