Learn R Programming

SentimentAnalysis (version 1.3-4)

compareToResponse: Compare sentiment values to existing response variable

Description

This function compares the calculated sentiment values with an external response variable. Examples of such an exogenous response are stock market movements or IMDb move rating. Both usually reflect a "true" value that the sentiment should match.

Usage

compareToResponse(sentiment, response)

# S3 method for logical compareToResponse(sentiment, response)

# S3 method for factor compareToResponse(sentiment, response)

# S3 method for integer compareToResponse(sentiment, response)

# S3 method for data.frame compareToResponse(sentiment, response)

# S3 method for numeric compareToResponse(sentiment, response)

Value

Matrix with different performance metrics for all given sentiment rules

Arguments

sentiment

Matrix with sentiment scores for each document across several sentiment rules

response

Vector with "true" response. This vector can either be of a continuous numeric or binary values. In case of the latter, FALSE is matched to a negative sentiment value, while TRUE is matched to a non-negative one.

Examples

Run this code
sentiment <- matrix(c(5.5, 2.9, 0.9, -1), 
                    dimnames=list(c("A", "B", "C", "D"), c("Sentiment")))

# continuous numeric response variable
response <- c(5, 3, 1, -1)
compareToResponse(sentiment, response)

# binary response variable
response <- c(TRUE, TRUE, FALSE, FALSE)
compareToResponse(sentiment, response)

Run the code above in your browser using DataLab