textmodel_affinity
implements the maximum likelihood supervised text
scaling method described in Perry and Benoit (2017).
textmodel_affinity(x, y, exclude = NULL, smooth = 0.5, ref_smooth = 0.5,
verbose = TRUE)
the dfm or bootstrap_dfm object on which the model will be fit. Does not need to contain only the training documents, since the index of these will be matched automatically.
vector of training classes/scores associated with each document
identified in data
a set of words to exclude from the model
a smoothing parameter for class affinities; defaults to 0.5 (Jeffreys prior). A plausible alternative would be 1.0 (Laplace prior).
a smoothing parameter for token distributions; defaults to 0.5
logical; if TRUE
print diagnostic information during
fitting.
Perry, Patrick O. and Kenneth Benoit. (2017) "Scaling Text with the Class Affinity Model". arXiv:1710.08963 [stat.ML].
predict.textmodel_affinity
for methods of applying a
fitted textmodel_affinity model object to predict quantities from
(other) documents.
# NOT RUN {
(af <- textmodel_affinity(data_dfm_lbgexample, y = c("L", NA, NA, NA, "R", NA)))
predict(af)
predict(af, newdata = data_dfm_lbgexample[6, ])
# }
# NOT RUN {
# compute bootstrapped SEs
bs_dfm <- bootstrap_dfm(data_corpus_dailnoconf1991, n = 10, remove_punct = TRUE)
textmodel_affinity(bs_dfm, y = c("Govt", "Opp", "Opp", rep(NA, 55)))
# }
Run the code above in your browser using DataLab