Learn R Programming

sentometrics (version 0.5.6)

peakdates: Extract dates related to sentiment time series peaks

Description

This function extracts the dates for which aggregated sentiment is most extreme (lowest, highest or both in absolute terms). The extracted dates are unique, even when, for example, all most extreme sentiment values (for different sentiment measures) occur on only one date.

Usage

peakdates(sentomeasures, n = 10, type = "both", do.average = FALSE)

Arguments

sentomeasures

a sentomeasures object created using sento_measures.

n

a positive numeric value to indicate the number of dates associated to sentiment peaks to extract. If n < 1, it is interpreted as a quantile (for example, 0.07 would mean the 7% most extreme dates).

type

a character value, either "pos", "neg" or "both", respectively to look for the n dates related to the most positive, most negative or most extreme (in absolute terms) sentiment occurrences.

do.average

a logical to indicate whether peaks should be selected based on the average sentiment value per date.

Value

A vector of type "Date" corresponding to the n extracted sentiment peak dates.

Examples

Run this code
# NOT RUN {
set.seed(505)

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 = "month", lag = 3)
sentomeasures <- sento_measures(corpusSample, l, ctr)

# extract the peaks
peaksAbs <- peakdates(sentomeasures, n = 5)
peaksAbsQuantile <- peakdates(sentomeasures, n = 0.50)
peaksPos <- peakdates(sentomeasures, n = 5, type = "pos")
peaksNeg <- peakdates(sentomeasures, n = 5, type = "neg")

# }

Run the code above in your browser using DataLab