<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/package-sentimentanalysis-released-on-cran/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.rblog.uni-freiburg.de/2017/06/06/package-sentimentanalysis-released-on-cran/"> R Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><em>Authors: Stefan Feuerriegel, Nicolas Pröllochs</em></p>
<p>This report introduces sentiment analysis in R and shows how to use our package “SentimentAnalysis”.</p>
<p><strong>What is sentiment analysis?</strong></p>
<p>Sentiment analysis is a research branch located at the heart of natural language processing (NLP), computational linguistics and text mining. It refers to any measures by which subjective information is extracted from textual documents. In other words, it extracts the polarity of the expressed opinion in a range spanning from positive to negative. As a result, one may also refer to sentiment analysis as opinion mining.</p>
<p><strong>What is the the package “SentimentAnalysis” about?</strong></p>
<p>Our package “SentimentAnalysis” performs a sentiment analysis of textual contents in R. This implementation utilizes various existing dictionaries, such as QDAP or Loughran-McDonald. Furthermore, it can also create customized dictionaries. The latter uses LASSO regularization as a statistical approach to select relevant terms based on an exogenous response variable.</p>
<p><strong>How to use the package “SentimentAnalysis”?</strong></p>
<p>This simple example shows how to perform a sentiment analysis of a single string. The result is a two-level factor with levels “positive” and “negative.”</p>
<div>
<pre><code><span>
# Analyze a single string to obtain a binary response (positive / negative) </span>
sentiment <span></span><span>-</span> analyzeSentiment(<span>&quot;Yeah, this was a great soccer game of the German team!&quot;</span>)
convertToBinaryResponse(sentiment)<span>$</span>SentimentGI
<span>#> [1] positive
#> Levels: negative positive
</span></code></pre>
</div>
<p>The following shows a larger example:</p>
<div>
<pre><code><span>
# Create a vector of strings</span>
documents <span></span><span>-</span> c(<span>&quot;Wow, I really like the new light sabers!&quot;,
&quot;That book was excellent.&quot;,
&quot;R is a fantastic language.&quot;,
&quot;The service in this restaurant was miserable.&quot;,
&quot;This is neither positive or negative.&quot;,
&quot;The waiter forget about my a dessert -- what a poor service!&quot;</span>)

<span># Analyze sentiment</span>
sentiment <span></span><span>-</span> analyzeSentiment(documents)

<span># Extract dictionary-based sentiment according to the Harvard-IV dictionary</span>
sentiment<span>$</span>SentimentGI
<span>#> [1] 0.3333333 0.5000000 0.5000000 -0.6666667 0.0000000 -0.6000000</span>

<span># View sentiment direction (i.e. positive, neutral and negative)</span>
convertToDirection(sentiment$SentimentGI)
<span>#> [1] positive positive positive negative neutral negative
#> Levels: negative neutral positive</span>

response <span></span><span>-</span> c(<span>+</span><span>1</span>, <span>+</span><span>1</span>, <span>+</span><span>1</span>, <span>-</span><span>1</span>, <span>0</span>, <span>-</span><span>1</span>)

compareToResponse(sentiment, response)
</code></pre>
</div>
<p>For more information, check out the following resources.</p>
<p><strong>Download</strong>: https://cran.r-project.org/package=SentimentAnalysis<br>
<strong>Vignette</strong>: https://cran.r-project.org/web/packages/SentimentAnalysis/vignettes/SentimentAnalysis.html</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.rblog.uni-freiburg.de/2017/06/06/package-sentimentanalysis-released-on-cran/"> R Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...

	<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/cIcY6-9yOWk" height="1"></a></div>