2022-11-05

Sentiment analysis with tidy data

When human readers approach a text, we use our understanding of the emotional intent of words to infer whether a section of text is positive or negative, or perhaps characterized by some other more nuanced emotion like surprise or disgust. One way to analyze the sentiment of a text is to consider the text as a combination of its individual words and the sentiment content of the whole text as the sum of the sentiment content of the individual words. This isn’t the only way to approach sentiment analysis, but it is an often-used approach, and an approach that naturally takes advantage of the tidy tool ecosystem.

Retrieved from: https://www.tidytextmining.com/sentiment.html

Negative Thoughts

Negative thoughts are ideas that make us weak, lose hope, or get in the way of better health. A negative thought is usually a criticism of oneself.

negative thoughts

Assigment Sentiment Analysis

  • Text Mining with R: A Tidy Approach** by Julia Silge and David Robinson

  • The following section is code from Chapter2

Number of words according to sentiment

## # A tibble: 301 × 2
##    word          n
##    <chr>     <int>
##  1 good        359
##  2 friend      166
##  3 hope        143
##  4 happy       125
##  5 love        117
##  6 deal         92
##  7 found        92
##  8 present      89
##  9 kind         82
## 10 happiness    76
## # … with 291 more rows

Sentiment

Sentiment negative vs positive

## Selecting by n

## # A tibble: 1,150 × 2
##    word        lexicon
##    <chr>       <chr>  
##  1 miss        custom 
##  2 a           SMART  
##  3 a's         SMART  
##  4 able        SMART  
##  5 about       SMART  
##  6 above       SMART  
##  7 according   SMART  
##  8 accordingly SMART  
##  9 across      SMART  
## 10 actually    SMART  
## # … with 1,140 more rows
## Warning in wordcloud(word, n, max.words = 100): miss could not be fit on page.
## It will not be plotted.

Sentiment Words negative vs positive

## Joining, by = "word"

## [1] "by jane austen"
## # A tibble: 6 × 2
##   book                chapters
##   <fct>                  <int>
## 1 Sense & Sensibility       51
## 2 Pride & Prejudice         62
## 3 Mansfield Park            49
## 4 Emma                      56
## 5 Northanger Abbey          32
## 6 Persuasion                25
## # A tibble: 6 × 5
##   book                chapter negativewords words  ratio
##   <fct>                 <int>         <int> <int>  <dbl>
## 1 Sense & Sensibility      43           161  3405 0.0473
## 2 Pride & Prejudice        34           111  2104 0.0528
## 3 Mansfield Park           46           173  3685 0.0469
## 4 Emma                     15           151  3340 0.0452
## 5 Northanger Abbey         21           149  2982 0.0500
## 6 Persuasion                4            62  1807 0.0343

Conclusion

Sentiment analysis allows us to understand the emotional content of a text. Perform a sentiment analysis on the text. Determine the use of positive and negative words by performing a sentiment analysis. The text has more negative than positive sentiments.