tv_sentiment_index {TextForecast}R Documentation

tv sentiment index function

Description

tv sentiment index function

Usage

tv_sentiment_index(x, w, y, alpha, lambda, newx, family, k)

Arguments

x

A matrix of variables to be selected by shrinkrage methods.

w

Optional Argument. A matrix of variables to be selected by shrinkrage methods.

y

the response variable.

alpha

the alpha required in glmnet.

lambda

the lambda required in glmnet.

newx

Matrix that selection will be applied. Useful for time series, when we need the observation at time t.

family

the glmnet family.

k

the highest positive and negative coefficients to be used.

Value

The time-varying sentiment index. The index is based on the word/term counting and is computed using: tv_index=(pos-neg)/(pos+neg).

Examples

suppressWarnings(RNGversion("3.5.0"))
set.seed(1)
data("stock_data")
data("news_data")
y=as.matrix(stock_data[,2])
w=as.matrix(stock_data[,3])
data("news_data")
X=news_data[,2:ncol(news_data)]
x=as.matrix(X)
grid_alphas=0.05
cont_folds=TRUE
t=length(y)
optimal_alphas=optimal_alphas(x[1:(t-1),],w[1:(t-1),],
y[2:t],grid_alphas,TRUE,"gaussian")
tv_index <- tv_sentiment_index(x[1:(t-1),],w[1:(t-1),],y[2:t],
optimal_alphas[[1]],optimal_alphas[[2]],x,"gaussian",2)


[Package TextForecast version 0.1.3 Index]