Structures specific performance data for a set of different sento_modelIter
objects as loss data.
Can then be used, for instance, as an input to create a model confidence set (Hansen, Lunde and Nason, 2011) with
the MCS package.
get_loss_data(models, loss = c("DA", "error", "errorSq", "AD", "accuracy"))
a named list
of sento_modelIter
objects. All models should be of the same family, being
either "gaussian"
, "binomial"
or "multinomial"
, and have performance data of the same dimensions.
a single character
vector, either "DA"
(directional inaccuracy), "error"
(predicted minus realized response variable), "errorSq"
(squared errors), "AD"
(absolute errors) or
"accuracy"
(inaccurate class predictions). This argument defines on what basis the model confidence set
is calculated. The first four options are available for "gaussian"
models, the last option applies only to
"binomial"
and "multinomial"
models.
A matrix
of loss data.
Hansen, Lunde and Nason (2011). The model confidence set. Econometrica 79, 453-497, doi:10.3982/ECTA5771 .
if (FALSE) { # \dontrun{
data("usnews", package = "sentometrics")
data("list_lexicons", package = "sentometrics")
data("list_valence_shifters", package = "sentometrics")
data("epu", package = "sentometrics")
set.seed(505)
# construct two sento_measures objects
corpusAll <- sento_corpus(corpusdf = usnews)
corpus <- quanteda::corpus_subset(corpusAll, date >= "1997-01-01" & date < "2014-10-01")
l <- sento_lexicons(list_lexicons[c("LM_en", "HENRY_en")], list_valence_shifters[["en"]])
ctrA <- ctr_agg(howWithin = "proportionalPol", howDocs = "proportional",
howTime = c("equal_weight", "linear"), by = "month", lag = 3)
sentMeas <- sento_measures(corpus, l, ctrA)
# prepare y and other x variables
y <- epu[epu$date %in% get_dates(sentMeas), "index"]
length(y) == nobs(sentMeas) # TRUE
x <- data.frame(runif(length(y)), rnorm(length(y))) # two other (random) x variables
colnames(x) <- c("x1", "x2")
# estimate different type of regressions
ctrM <- ctr_model(model = "gaussian", type = "AIC", do.iter = TRUE,
h = 0, nSample = 120, start = 50)
out1 <- sento_model(sentMeas, y, x = x, ctr = ctrM)
out2 <- sento_model(sentMeas, y, x = NULL, ctr = ctrM)
out3 <- sento_model(subset(sentMeas, select = "linear"), y, x = x, ctr = ctrM)
out4 <- sento_model(subset(sentMeas, select = "linear"), y, x = NULL, ctr = ctrM)
lossData <- get_loss_data(models = list(m1 = out1, m2 = out2, m3 = out3, m4 = out4),
loss = "errorSq")
mcs <- MCS::MCSprocedure(lossData)} # }