Learn R Programming

sentometrics (version 0.2)

plot.sentomodeliter: Plot iterative predictions versus realized values

Description

Displays a plot of all predictions made through the iterative model computation as incorporated in the input sentomodeliter object, as well as the corresponding true values.

Usage

# S3 method for sentomodeliter
plot(x, ...)

Arguments

x

a sentomodeliter object created using sento_model.

...

not used.

Value

Returns a simple ggplot object, which can be added onto (or to alter its default elements) by using the + operator (see examples).

Examples

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

# construct a sentomeasures object to start with
corpusAll <- sento_corpus(corpusdf = usnews)
corpus <- quanteda::corpus_subset(corpusAll, date >= "2007-01-01" & date < "2014-10-01")
l <- setup_lexicons(lexicons[c("LM_eng", "HENRY_eng")], valence[["valence_eng"]])
ctr <- ctr_agg(howWithin = "tf-idf", howDocs = "proportional",
               howTime = c("equal_weight", "linear"),
               by = "month", lag = 3)
sentomeasures <- sento_measures(corpus, l, ctr)

# prepare y variable
y <- epu[epu$date >= sentomeasures$measures$date[1], ]$index
length(y) == nrow(sentomeasures$measures) # TRUE

# estimate regression iteratively based on a sample of 60, skipping first 25 iterations
ctr <- ctr_model(model = "gaussian", type = "AIC", do.iter = TRUE,
                 h = 0, nSample = 60, start = 26)
out <- sento_model(sentomeasures, y, ctr = ctr)
summary(out)

# plotting
p <- plot(out)
p <- p +
  ggthemes::theme_few()
p

# }

Run the code above in your browser using DataLab