Learn R Programming

sentometrics (version 0.5.6)

measures_global: Merge sentiment measures into multiple weighted global sentiment indices

Description

Merges all sentiment measures into a weighted global textual sentiment measure for each of the lexicons, features, and time dimensions.

Usage

measures_global(sentomeasures, lexicons = 1, features = 1, time = 1)

Arguments

sentomeasures

a sentomeasures object created using sento_measures.

lexicons

a numeric vector of weights, of size length(sentomeasures$lexicons), in the same order. By default set to 1, which means equally weighted.

features

a numeric vector of weights, of size length(sentomeasures$features), in the same order. By default set to 1, which means equally weighted.

time

a numeric vector of weights, of size length(sentomeasures$time), in the same order. By default set to 1, which means equally weighted.

Value

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.

Details

In contrast to other measures_xyz functions, this particular function returns no new sentomeasures object. 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.

See Also

sento_model

Examples

Run this code
# NOT RUN {
data("usnews", package = "sentometrics")
data("list_lexicons", package = "sentometrics")
data("list_valence_shifters", package = "sentometrics")

# construct a sentomeasures 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)
sentomeasures <- sento_measures(corpusSample, l, ctr)

# merge into one global sentiment measure, with specified weighting for lexicons and features
global <- measures_global(sentomeasures,
                          lexicons = c(0.40, 0.60),
                          features = c(0.10, -0.20, 0.30, -1),
                          time = 1)

# }

Run the code above in your browser using DataLab