-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.R
53 lines (41 loc) · 3.45 KB
/
analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 03 run stm ----
cat("Estimating stm model:\n")
cat("Using Lee and Mimno (2014) algorithm to define no. of topics")
# stm.mod.spec.LeeMimno <- stm(docs, vocab, K=0, prevalence = ~ journal + s(year), content = NULL,
# data = meta, init.type = c("Spectral"), seed = 48613, max.em.its = 500,
# emtol = 1e-05, verbose = TRUE, reportevery = 5, LDAbeta = TRUE,
# interactions = TRUE, ngroups = 1, model = NULL, gamma.prior = "Pooled",
# sigma.prior = 0, kappa.prior = "L1", control = list(maxV=5000))
#
# stm.mod.spec.LeeMimno.cont <- stm(docs, vocab, K=0, prevalence = ~ journal + s(year),
# content = ~ AEorERE, data = meta, init.type = c("Spectral"),
# seed = 48613, max.em.its = 500, emtol = 1e-05, verbose = TRUE,
# reportevery = 5, LDAbeta = FALSE, interactions = TRUE, ngroups = 1,
# model = NULL, gamma.prior = "Pooled", sigma.prior = 0,
# kappa.prior = "L1", control = list(maxV=1000))
# stm.mod.spec.LeeMimno.cont.int <- stm(docs, vocab, K=0, prevalence = ~ journal * s(year),
# content = ~ AEorERE, data = meta, init.type = c("Spectral"),
# seed = 48613, max.em.its = 500, emtol = 1e-05, verbose = TRUE,
# reportevery = 5, LDAbeta = FALSE, interactions = TRUE, ngroups = 1,
# model = NULL, gamma.prior = "Pooled", sigma.prior = 1,
# kappa.prior = "L1", control = list(maxV=1000))
stm.mod.spec.LeeMimno.cont.int.alt <- stm(docs, vocab, K=0, prevalence = ~ AEorERE * s(year),
content = ~ journal , data = meta, init.type = c("Spectral"),
seed = 48613, max.em.its = 500, emtol = 1e-05, verbose = TRUE,
reportevery = 5, LDAbeta = FALSE, interactions = TRUE, ngroups = 1,
model = NULL, gamma.prior = "Pooled", sigma.prior = 1,
kappa.prior = "L1", control = list(maxV=1000))
# options gamma.prior = "Pooled", sigma.prior > 0
# calculate uncertainty
cat("Estimating effects, calculating uncertainty...\n")
# prep.LeeMimno <- estimateEffect(1:stm.mod.spec.LeeMimno$settings$dim$K ~ journal + s(year),
# stm.mod.spec.LeeMimno, meta = meta, uncertainty = "Global")
# prep.LeeMimno.cont <- estimateEffect(1:stm.mod.spec.LeeMimno.cont$settings$dim$K ~ journal + s(year),
# stm.mod.spec.LeeMimno.cont, meta = meta, uncertainty = "Global")
# prep.LeeMimno.cont.int <- estimateEffect(1:stm.mod.spec.LeeMimno.cont.int$settings$dim$K ~ journal * s(year), stm.mod.spec.LeeMimno.cont.int, meta = meta, uncertainty = "Global")
prep.LeeMimno.cont.int.alt <- estimateEffect(1:stm.mod.spec.LeeMimno.cont.int.alt$settings$dim$K ~ AEorERE * s(year), stm.mod.spec.LeeMimno.cont.int.alt, meta = meta, uncertainty = "Global")
# write output for stminsights
cat("Writing stminsights output.\n")
# save(stm.mod.spec.LeeMimno.cont.int,prep.LeeMimno.cont.int,out,file="stminsights.RData",compress = "xz")
save(stm.mod.spec.LeeMimno.cont.int.alt,prep.LeeMimno.cont.int.alt,out,file="stminsights_alt.RData",compress = "xz")
# stminsights::run_stminsights()