amzn_review_sentiment: Review Sentiment

View source: R/amzn_review_sentiment.R

amzn_review_sentimentR Documentation

Review Sentiment

Description

Estimating the sentiment for each review of a product. The function leverages the sentimentr package for estimation at the level of each review text.

sentimentr accounts for "valence shifters" within texts - the terms that can negate or amplify the sentiment of nearby terms, (e.g., "better not" or "not a lie") - by using weights to account for a positive or negative shift.

Usage

amzn_review_sentiment(data)

Arguments

data

Data frame created by GSPtext::get_reviews() or in the same format

Value

Tibble of original data with added sentiment information – ("word count", "sd", "avg sentiment"). ggplot scatterplot of the average sentiment of each review over time.

Examples

## Not run: 
sentiment <- amzn_review_sentiment(data)

# what's the strength of the relationship b/n sentiment and rating
summary(lm(ave_sentiment ~ stars + word_count, data = sentiment$data)) %>% broom::tidy()

# find review with max or min sentiment
sentiment$data[which.max(sentiment$data$ave_sentiment),]
sentiment$data[which.min(sentiment$data$ave_sentiment),]

# summarize sentiment by review rating
sentiment <- amzn_review_sentiment(data)
sentiment %>% dplyr::group_by(stars) %>%
dplyr::summarise(avg_sentiment = mean(ave_sentiment),
sd = mean(sd, na.rm = TRUE), reviews = dplyr::n())

# aggregate to monthly level and plot average sentiment
sentiment <- amzn_review_sentiment(data)
sentiment$data %>%
  dplyr::mutate(month = lubridate::floor_date(date, "month")) %>%
  dplyr::group_by(month) %>%
  dplyr::summarise(monthly_sentiment = mean(ave_sentiment)) %>%
  ggplot2::ggplot(aes(x = month, y = monthly_sentiment)) +
  ggplot2::geom_line()
## End(Not run)

taylorgrant/GSPtext documentation built on April 15, 2023, 10:56 p.m.