View source: R/amzn_review_sentiment.R
amzn_review_sentiment | R Documentation |
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.
amzn_review_sentiment(data)
data |
Data frame created by |
Tibble of original data with added sentiment information – ("word count", "sd", "avg sentiment"). ggplot scatterplot of the average sentiment of each review over time.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.