Learn R Programming

sentometrics (version 0.5.6)

attributions: Retrieve top-down model sentiment attributions

Description

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.

Usage

attributions(model, sentomeasures, do.lags = TRUE,
  do.normalize = FALSE, refDates = NULL, factor = NULL)

Arguments

model

a sentomodel or a sentomodeliter object created with sento_model.

sentomeasures

the sentomeasures object, as created with sento_measures, used to estimate the model from the first argument (make sure this is the case!).

do.lags

a logical, TRUE also computes the attribution to each time lag. For large time lags, this is time-consuming.

do.normalize

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.

refDates

the dates (as "yyyy-mm-dd") 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 (that is, model$dates[1] if model is a sentomodel object). All dates should also be in get_dates(sentomeasures). 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.

factor

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.

Value

A list of class attributions, with "documents", "lags", "lexicons", "features" and "time" as dimensions for which aggregation is computed. The last four dimensions are data.tables 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.

Details

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. A NULL value for document-level attribution on a given date means no documents are directly implicated in the associated prediction.

See Also

sento_model