Session Ready
Exercise

Happy songs!

Of course just positive and negative words aren't enough. In this exercise you will learn about valence shifters which tell you about the author's emotional intent. Previously you applied polarity() to text without valence shifters. In this example you will see amplification and negation words in action.

Recall that an amplifying word adds 0.8 to a positive word in polarity() so the positive score becomes 1.8. For negative words 0.8 is subtracted so the total becomes -1.8. Then the score is divided by the square root of the total number of words.

Consider the following example from Frank Sinatra:

  • "It was a very good year"

"Good" equals 1 and "very" adds another 0.8. So, 1.8/sqrt(6) results in 0.73 polarity.

A negating word such as "not" will inverse the subjectivity score. Consider the following example from Bobby McFerrin:

  • "Don't worry Be Happy"

"worry is now 1 due to the negation "don't." Adding the "happy", +1, equals 2. With 4 total words, 2 / sqrt(4) equals a polarity score of 1.

Instructions
100 XP
  • Examine the conversation data frame,conversation. Note the valence shifters like "never" in the text column.
  • Apply polarity() to the text column of conversation to calculate polarity for the entire conversation.
  • Calculate the polarity scores by student, assigning the result to student_pol.
    • Call polarity() again, this time passing two columns of conversation.
    • The text variable is text and the grouping variable is student.
  • To see the student level results, use scores() on student_pol.
  • The counts() function applied to student_pol will print the sentence level polarity for the entire data frame along with lexicon words identified.
  • The polarity object, student_pol, can be plotted with plot().