Computes the attributions to predictions for a (given) number of dates at all possible sentiment dimensions, based on the coefficients associated to each sentiment measure, as estimated in the provided model object.
retrieve_attributions(model, sentomeasures, do.normalize = FALSE,
refDates = NULL, factor = NULL)
a sentomodel
or sentomodeliter
object created with sento_model
.
the sentomeasures
object, as created with sento_measures
, used to estimate
the model from the first argument.
a logical
, TRUE
divides each element of every attribution vector at a given date by its
L2-norm at that date, normalizing the values between -1 and 1. The document attributions are not normalized.
the dates at which attribution is to be performed. These should be between the latest date available in the
input sentomeasures
object and the first estimation sample date, i.e. model$dates[1]
if model
is
a sentomodel
object. All dates should also be present in sentomeasures$measures$date
. If NULL
(default), attribution is calculated for all in-sample dates. Ignored if model
is a
sentomodeliter
object, for which attribution is calculated for all out-of-sample prediction dates.
the factor level as a single character
vector for which attribution has to be calculated in
case of (a) multinomial model(s). Ignored for linear and binomial models.
A list
with all dimensions for which aggregation is computed, being "documents"
, "lexicons"
,
"features"
and "time"
. The last three dimensions are data.table
s having a "date"
column and the other columns the different components of the dimension, with the attributions as values. Document-level
attribution is further decomposed into a data.table
per date, with "id"
, "date"
and
"attrib"
columns.
See sento_model
for an elaborate modelling example including the calculation and plotting of
attributions. The attribution for logistic models is represented in terms of log odds. For binomial models, it is
calculated with respect to the last factor level or factor column.