sentiment_series {sentopics} | R Documentation |
Compute a sentiment time series
Description
Compute a sentiment time series based on the internal sentiment
and dates of a sentopicmodel
. The time series computation supports
multiple sampling period and optionally allow computing a moving average.
Usage
sentiment_series(
x,
period = c("year", "quarter", "month", "day"),
rolling_window = 1,
scale = TRUE,
scaling_period = c("1900-01-01", "2099-12-31"),
as.xts = TRUE,
...
)
Arguments
x |
a |
period |
the sampling period within which the sentiment of documents
will be averaged. |
rolling_window |
if greater than 1, determines the rolling window to compute a moving average of sentiment. The rolling window is based on the period unit and rely on actual dates (i.e, is not affected by unequally spaced data points). |
scale |
if |
scaling_period |
the date range over which the scaling should be applied. Particularly useful to normalize only the beginning of the time series. |
as.xts |
if |
... |
other arguments passed on to |
Value
A time series of sentiment, stored as an xts::xts or data.frame.
See Also
sentopics_sentiment sentopics_date
Other series functions:
proportion_topics()
,
sentiment_breakdown()
,
sentiment_topics()
Examples
lda <- LDA(ECB_press_conferences_tokens)
series <- sentiment_series(lda, period = "month")
# JST and rJST models can use computed sentiment from the sentiment layer,
# but the model must be estimated first.
rjst <- rJST(ECB_press_conferences_tokens, lexicon = LoughranMcDonald)
sentiment_series(rjst)
sentopics_sentiment(rjst) <- NULL ## remove existing sentiment
rjst <- fit(rjst, 10) ## estimating the model is then needed
sentiment_series(rjst)
# note the presence of both raw and scaled sentiment values
# in the initial object
sentopics_sentiment(lda)
sentopics_sentiment(rjst)