Learn R Programming

sentometrics (version 0.2)

to_global: Merge sentiment measures into one global sentiment measure

Description

Merges all sentiment measures into one global textual sentiment measure based on a set of weights to indicate the importance of each component in the lexicons, features, and time vectors as specified in the input sentomeasures object. Every measure receives a weight in the global measure equal to the multiplication of the supplied weights of the components it is contained of. The global sentiment measure then corresponds to a weighted average of these weights times the sentiment scores, per date.

Usage

to_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 and summing to one. By default set to 1, which means equally weighted.

features

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

time

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

Value

A data.frame with the values for the global sentiment measure under the global column and dates as row names.

Details

This function returns no sentomeasures object, however the global sentiment measure as outputted can be added to regressions as an additional variable using the x argument in the sento_model function.

See Also

sento_model

Examples

Run this code
# NOT RUN {
data("usnews")
data("lexicons")
data("valence")

# construct a sentomeasures object to start with
corpus <- sento_corpus(corpusdf = usnews)
corpusSample <- quanteda::corpus_sample(corpus, size = 1250)
l <- setup_lexicons(lexicons[c("LM_eng", "HENRY_eng")], valence[["valence_eng"]])
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 <- to_global(sentomeasures, lexicons = c(0.40, 0.60),
                                   features = c(0.10, 0.20, 0.30, 0.40),
                                   time = 1)

# }

Run the code above in your browser using DataLab