Learn R Programming

sentopics (version 0.7.4)

proportion_topics: Compute the topic or sentiment proportion time series

Description

Aggregate the topical or sentiment proportions at the document level into time series.

Usage

proportion_topics(
  x,
  period = c("year", "quarter", "month", "day", "identity"),
  rolling_window = 1,
  complete = TRUE,
  plot = c(FALSE, TRUE, "silent"),
  plot_ridgelines = TRUE,
  as.xts = TRUE,
  ...
)

plot_proportion_topics( x, period = c("year", "quarter", "month", "day"), rolling_window = 1, complete = TRUE, plot_ridgelines = TRUE, ... )

Value

A time series of proportions, stored as an xts::xts object or as a data.frame.

Arguments

x

a LDA(), JST() or rJST() model populated with internal dates and/or internal sentiment.

period

the sampling period within which the sentiment of documents will be averaged. period = "identity" is a special case that will return document-level variables before the aggregation happens. Useful to rapidly compute topical sentiment at the document level.

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).

complete

if FALSE, only compute proportions at the upper level of the topic model hierarchy (topics for rJST and sentiment for JST). No effect on LDA models.

plot

if TRUE, prints a plot of the time series and attaches it as an attribute to the returned object. If 'silent', do not print the plot but still attaches it as an attribute.

plot_ridgelines

if TRUE, time series are plotted as ridgelines. Requires ggridges package installed. If FALSE, the plot will use only standards ggplot2 functions. If the argument is missing and the package ggridges is not installed, this will quietly switch to a ggplot2 output.

as.xts

if TRUE, returns an xts::xts object. Otherwise, returns a data.frame.

...

other arguments passed on to zoo::rollapply() or mean() and sd().

See Also

sentopics_sentiment sentopics_date

Other series functions: sentiment_breakdown(), sentiment_series(), sentiment_topics()

Examples

Run this code
lda <- LDA(ECB_press_conferences_tokens)
lda <- fit(lda, 100)
proportion_topics(lda)

# plot shortcut
plot_proportion_topics(lda, period = "month", rolling_window = 3)
# with or without ridgelines
plot_proportion_topics(lda, period = "month", plot_ridgelines = FALSE)

# also available for rJST and JST models
jst <- JST(ECB_press_conferences_tokens, lexicon = LoughranMcDonald)
jst <- fit(jst, 100)
# including both layers
proportion_topics(jst)
# or not
proportion_topics(jst, complete = FALSE)

Run the code above in your browser using DataLab