Calculate sentiment indicators from TextBlob and vaderSentiment.

sentiment_scores_r(x)

Arguments

x

Data frame. The text to run sentiment analysis on.

Value

Data frame. All indicators produced by TextBlob (polarity and subjectivity) and vaderSentiment (positive, negative and neutral sentiments, and compound score).

Details

This function complements existing sentiment analysis packages in R (e.g. tidytextor quanteda.sentiment) with the popular Python sentiment analysis libraries TextBlob and vaderSentiment.

TextBlob calculates two indicators, namely polarity and subjectivity. The polarity score is a float within the range [-1, 1], where -1 is for very negative sentiment, +1 is for very positive sentiment, and 0 is for neutral sentiment. The subjectivity is a float within the range [0, 1], where 0 is very objective and 1 is very subjective.

vaderSentiment assigns to the given text three sentiment proportions (positive, negative and neutral) whose scores sum to 1. It also calculates a compound score that is a float in [-1, 1], similar to TextBlob's polarity.

Examples

sentiments <- pxtextmineR::text_data %>% dplyr::select(feedback) %>% pxtextmineR::sentiment_scores_r() head(sentiments)
#> text_blob_polarity text_blob_subjectivity vader_neg vader_neu vader_pos #> 1 0.00000 0.0000000 0.000 1.000 0.000 #> 2 -0.09375 0.4000000 0.265 0.735 0.000 #> 3 0.20000 0.2625000 0.000 1.000 0.000 #> 4 0.23125 0.4669643 0.199 0.625 0.176 #> 5 0.02500 0.3250000 0.029 0.913 0.058 #> 6 -0.27500 0.5750000 0.091 0.813 0.096 #> vader_compound #> 1 0.0000 #> 2 -0.2040 #> 3 0.0000 #> 4 0.0490 #> 5 0.3400 #> 6 0.2967
apply(sentiments, 2, range)
#> text_blob_polarity text_blob_subjectivity vader_neg vader_neu vader_pos #> [1,] -1 0 0 0 0 #> [2,] 1 1 1 1 1 #> vader_compound #> [1,] -0.9916 #> [2,] 0.9971