sentopics_sentiment {sentopics} | R Documentation |
Internal sentiment
Description
Compute, extract or replace the internal sentiment of a
sentopicmodel
. The internal sentiment is used to create time series using
the functions sentiment_series()
or sentiment_topics()
. If the input
model contains a sentiment layer, sentiment can be computed directly from
the output of the model. Otherwise, sentiment obtained externally should be
added for each document.
Usage
sentopics_sentiment(
x,
method = c("proportional", "proportionalPol"),
override = FALSE,
quiet = FALSE,
include_docvars = FALSE
)
sentopics_sentiment(x) <- value
Arguments
x |
a |
method |
the method used to compute sentiment, see "Methods" below.
Ignored if an internal sentiment is already stored, unless |
override |
by default, the function computes sentiment only if no
internal sentiment is already stored within the |
quiet |
if |
include_docvars |
if |
value |
a numeric vector of sentiment to input into the model. |
Details
The computed sentiment varies depending on the model. For LDA, sentiment computation is not possible.
For JST, the sentiment is computed on a per-document basis according to the document-level sentiment mixtures.
For a rJST model, a sentiment is computed for each topic, resulting in
K
sentiment values per document. In that case, the .sentiment
column is
an average of the K
sentiment values, weighted by they respective topical
proportions.
Value
A data.frame with the stored sentiment per document.
Methods
The function accepts two methods of computing sentiment:
-
proportional computes the difference between the estimated positive and negative proportions for each document (and possibly each topic).
positive - negative
-
proportionalPol computes the difference between positive and negative proportions, divided by the sum of positive and negative proportions. As a result, the computed sentiment lies within the (-1;1) interval.
\frac{positive - negative}{positive + negative}
Both methods will lead to the same result for a JST model containing only negative and positive sentiments.
Note
The internal sentiment is stored internally in the docvars of the
topic model. This means that sentiment may also be accessed through the
docvars()
function, although this is discouraged.
Author(s)
Olivier Delmarcelle
See Also
Other sentopics helpers:
sentopics_date()
,
sentopics_labels()
Examples
# example dataset already contains ".sentiment" docvar
docvars(ECB_press_conferences_tokens)
# sentiment is automatically stored in the sentopicmodel object
lda <- LDA(ECB_press_conferences_tokens)
sentopics_sentiment(lda)
# sentiment can be removed or modified by the assignment operator
sentopics_sentiment(lda) <- NULL
sentopics_sentiment(lda) <- docvars(ECB_press_conferences_tokens, ".sentiment")
# for JST models, sentiment can be computed from the output of the model
jst <- JST(ECB_press_conferences_tokens, lexicon = LoughranMcDonald)
jst <- fit(jst, 100)
sentopics_sentiment(jst, override = TRUE) # replace existing sentiment
## for rJST models one sentiment value is computed by topic
rjst <- rJST(ECB_press_conferences_tokens, lexicon = LoughranMcDonald)
rjst <- fit(rjst, 100)
sentopics_sentiment(rjst, override = TRUE)