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.
attributions(
model,
sento_measures,
do.lags = TRUE,
do.normalize = FALSE,
refDates = NULL,
factor = NULL
)
a sento_model
or a sento_modelIter
object created with sento_model
.
the sento_measures
object, as created with sento_measures
, used to estimate
the model from the first argument (make sure this is the case!).
a logical
, TRUE
also computes the attribution to each time lag. For large time lags,
this is time-consuming.
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 (as "yyyy-mm-dd"
) at which attribution is to be performed. These should be between the latest
date available in the input sento_measures
object and the first estimation sample date (that is, model$dates[1]
if model
is a sento_model
object). All dates should also be in get_dates(sento_measures)
. If
NULL
(default), attribution is calculated for all in-sample dates. Ignored if model
is a sento_modelIter
object, for which attribution is calculated for all out-of-sample prediction dates.
the factor level as a single character
vector to calculate attribution
for in case of (a) multinomial model(s). Ignored for linear and binomial models.
A list
of class attributions
, with "documents"
, "lags"
, "lexicons"
,
"features"
and "time"
as attribution dimensions. The last four 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. If do.lags = FALSE
, the "lags"
element is set
to NULL
.
See sento_model
for an elaborate modeling 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. A NULL
value for document-level attribution
on a given date means no documents are directly implicated in the associated prediction.