View source: R/tv_sentiment_index_all_coefs.R
tv_sentiment_index_all_coefs | R Documentation |
TV sentiment index using all positive and negative coefficients.
tv_sentiment_index_all_coefs( x, w, y, alpha, lambda, newx, family, scaled, k_mov_avg, type_mov_avg )
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. |
scaled |
Set TRUE for scale and FALSE for no scale. |
k_mov_avg |
The moving average order. |
type_mov_avg |
The type of moving average. See movavg. |
A list with the net, postive and negative sentiment index. The net time-varying sentiment index. The index is based on the word/term counting and is computed using: tv_index=(pos-neg)/(pos+neg). The postive sentiment index is computed using: tv_index_pos=pos/(pos+neg) and the negative tv_index_neg=neg/(pos+neg).
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=x[1:(t-1),], y=y[2:t],grid_alphas=grid_alphas,cont_folds=TRUE,family="gaussian") tv_idx=tv_sentiment_index_all_coefs(x=x[1:(t-1),],y=y[2:t],alpha = optimal_alphas[1], lambda = optimal_alphas[2],newx=x, scaled = TRUE,k_mov_avg = 4,type_mov_avg = "s")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.