tw_sentiment: Computes sentiment score

Description Usage Arguments Details Value See Also Examples

View source: R/sentiment.R

Description

Computes sentiment score by counting the number of positive and negative terms.

Usage

1
2
tw_sentiment(text, pos = NULL, neg = NULL, pos_s = NULL, neg_s = NULL,
  lan = "en", normalize = TRUE)

Arguments

text

Character vector with the text to be classified

pos

Positive words lexicon

neg

Negative words lexicon

pos_s

Numeric vector of scores for each word in the pos vec

neg_s

Numeric vector of scores for each word in the neg vec

lan

Languaje of the lexicon (can be either 'en' or 'es')

normalize

Whether or not to normalize the values of each words' score.

Details

By default uses an english lexicon downloaded from http://www.cs.uic.edu/~liub/FBS/sentiment-analysis.html. In particular if no list of words is provided, the function loads the dataset warriner_et_al_en() or warriner_et_al_es(), depending on the lang argument, both of which contains a vector of words with their respective valence (pleasantness of the stimulus).

The arguments pos_s and neg_s allow to provide with scores (valence) to each vector of words, so instead of adding 1 or -1 for every positive or negative word the function can add some other value specified by these arguments.

By default, when using the default lexicon, the function loads the english lexicon (lan='en'). Otherwise, if lan is set to 'es', it will load the spanish lexicon.

When normalize is set to TRUE (default), the function will normalize the scores values for each word such as all values are within -1 and 1. Note that this does not implies that the final sentiment score will be in that range as well since it is a result of the addition of the scores.

Value

Numeric Vector with scores

See Also

sentiment_lexicon_pos_en() sentiment_lexicon_neg_en()

Other statistics: plot.tw_Class_table, plot.tw_Class_ts

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 # Example data
 text <- c(
   "I'm feeling sad today",
   "This is terrible, bad",
   "I'm doing ok",
   "I'm feeling great",
   "I'm feeling nothing",
   "This is sick, but good at the same time")
 
 # Getting the scores
 tw_sentiment(text)
 tw_sentiment(text, normalize=FALSE)

gvegayon/twitterreport documentation built on May 17, 2019, 9:30 a.m.