Aggregates sentiment measures by combining across provided lexicons, features, and time weighting
schemes dimensions. For do.global = FALSE
, the combination occurs by taking the mean of the relevant
measures. For do.global = TRUE
, this function aggregates all sentiment measures into a weighted global textual
sentiment measure for each of the dimensions.
# S3 method for sento_measures aggregate( x, features = NULL, lexicons = NULL, time = NULL, do.global = FALSE, do.keep = FALSE, ... )
x | a |
---|---|
features | a |
lexicons | a |
time | a |
do.global | a |
do.keep | a |
... | not used. |
If do.global = FALSE
, a modified sento_measures
object, with the aggregated sentiment
measures, including updated information and statistics, but the original sentiment scores data.table
untouched.
If do.global = TRUE
, a data.table
with the different types of weighted global sentiment measures,
named "globLex"
, "globFeat"
, "globTime"
and "global"
, with "date"
as the first
column. The last measure is an average of the the three other measures.
If do.global = TRUE
, the measures are constructed from weights that indicate the importance (and sign)
along each component from the lexicons
, features
, and time
dimensions. There is no restriction in
terms of allowed weights. For example, the global index based on the supplied lexicon weights ("globLex"
) is obtained
first by multiplying every sentiment measure with its corresponding weight (meaning, the weight given to the lexicon the
sentiment is computed with), then by taking the average per date.
Samuel Borms
data("usnews", package = "sentometrics") data("list_lexicons", package = "sentometrics") data("list_valence_shifters", package = "sentometrics") # construct a sento_measures object to start with corpus <- sento_corpus(corpusdf = usnews) corpusSample <- quanteda::corpus_sample(corpus, size = 500) l <- sento_lexicons(list_lexicons[c("LM_en", "HENRY_en")], list_valence_shifters[["en"]]) ctr <- ctr_agg(howTime = c("equal_weight", "linear"), by = "year", lag = 3) sento_measures <- sento_measures(corpusSample, l, ctr) # aggregation across specified components smAgg <- aggregate(sento_measures, time = list(W = c("equal_weight", "linear")), features = list(journals = c("wsj", "wapo")), do.keep = TRUE) # aggregation in full dims <- get_dimensions(sento_measures) smFull <- aggregate(sento_measures, lexicons = list(L = dims[["lexicons"]]), time = list(T = dims[["time"]]), features = list(F = dims[["features"]])) # "global" aggregation smGlobal <- aggregate(sento_measures, do.global = TRUE, lexicons = c(0.3, 0.1), features = c(1, -0.5, 0.3, 1.2), time = NULL) if (FALSE) { # aggregation won't work, but produces informative error message aggregate(sento_measures, time = list(W = c("equal_weight", "almon1")), lexicons = list(LEX = c("LM_en")), features = list(journals = c("notInHere", "wapo")))}