Text Analytics Part VII – Sentiment Analysis using R

In my last 6 posts on Text Analytics, I have discussed analysis of reviews and ratings given by customers seperately. Let us now compare the reviews written and ratings given by each customer. How many reviews matches with the ratings given.

But before starting with the analysis work, lets have a look on the meaning of these words:-

Sentiment analysis and polarity:

Sentiment analysis aims to determine the attitude of a speaker or a writer with respect to some topic or the overall contextual polarity of a document.

A basic task in sentiment analysis is classifying the polarity of a given text at the document, sentence, or feature/aspect level — whether the expressed opinion in a document, a sentence or an entity feature/aspect is positive, negative, or neutral. Advanced, “beyond polarity” sentiment classification looks, for instance, at emotional states such as “angry,” “sad,” and “happy.”

On the basis of polarity value (group stan.mean.polarity value field which will give this value), we have tried segregating the customer’s review into three categories:

  1. who are highly Impressed with this phone
  2. who are Satisfied with this phone
  3. who are not at all satisfied

But first, we need to find the threshold value of polarity:


Considering 0.1324276 as threshold, got below table:

This table seems to be matching with the counts that we have got from ratings. Here 54% customers seem to be impressed by the use of MOTO-G. Most of the people have given ratings according to the views that they have expressed.

R Code to do this:

#package required:- qdap
for(i in 1:100)



This is a chunk of code for creating contingency table of ratings with 3 categories of satisfaction, find full codes in R here.

With this post, I ends up this “Text Analysis” series. I hope this would have helped you in learning.

Don’t forget to comment so that I can improve my post.
Good Bye!
Take Care!

Leave a Reply

Your email address will not be published. Required fields are marked *