#' @title rSentiment Statistics
#' @description Blank Description.
#' @param s NRC Sentiment Data
#' @param n Name
#' @keywords package
#' @return NULL
#' @export
#' @examples sentiment.compare()
#' sentiment.anova(nk.sentiment, "1way", filter.emotion)
#' sentiment.anova(nk.sentiment, "tukey", "anger")
#' sentiment.anova(nk.sentiment, "2way")
sentiment.anova <- function(s, test, e) {
if('dplyr' %in% rownames(installed.packages()) == TRUE) {
require(dplyr)} else {
install.packages("dplyr", repos = "http://cran.us.r-project.org")
require(dplyr)}
if('reshape' %in% rownames(installed.packages()) == TRUE) {
require(reshape)} else {
install.packages("reshape", repos = "http://cran.us.r-project.org")
require(reshape)}
nk.sentiment <- s
one.way <- "1way"
tukey <- "tukey"
two.way <- "2way"
if (test == one.way) {
filter.emotion <- e
filter.emotion <- tolower(filter.emotion)
# One-Way ANOVA
nk.reshape <- reshape2::melt(nk.sentiment,
variable.name = "emotion",
value.name = "sentiment",
id.vars = c("created_at", "favorite_count", "retweet_count","text"))
nk.reshape <- mutate(nk.reshape, query = paste(nk.name))
cbo.reshape <- reshape2::melt(cbo.sentiment,
variable.name = "emotion",
value.name = "sentiment",
id.vars = c("created_at", "favorite_count", "retweet_count","text"))
cbo.reshape <- mutate(cbo.reshape, query = paste(cbo.name))
sentiment.combined <- rbind(nk.reshape, cbo.reshape)
sentiment.sort <- sentiment.combined %>% filter(emotion == paste0(filter.emotion))
sentiment.anova1way <- aov(sentiment ~ query, data = sentiment.sort)
return(summary(sentiment.anova1way))
} else if (test == tukey) {
filter.emotion <- e
filter.emotion <- tolower(filter.emotion)
nk.reshape <- reshape2::melt(nk.sentiment,
variable.name = "emotion",
value.name = "sentiment",
id.vars = c("created_at", "favorite_count", "retweet_count","text"))
nk.reshape <- mutate(nk.reshape, query = paste(nk.name))
cbo.reshape <- reshape2::melt(cbo.sentiment,
variable.name = "emotion",
value.name = "sentiment",
id.vars = c("created_at", "favorite_count", "retweet_count","text"))
cbo.reshape <- mutate(cbo.reshape, query = paste(cbo.name))
sentiment.combined <- rbind(nk.reshape, cbo.reshape)
sentiment.sort <- sentiment.combined %>% filter(emotion == paste0(filter.emotion))
sentiment.anova1way <- aov(sentiment ~ query, data = sentiment.sort)
return(TukeyHSD(sentiment.anova1way))
} else if (test == two.way) {
nk.reshape <- reshape2::melt(nk.sentiment,
variable.name = "emotion",
value.name = "sentiment",
id.vars = c("created_at", "favorite_count", "retweet_count","text"))
nk.reshape <- mutate(nk.reshape, query = paste(nk.name))
cbo.reshape <- reshape2::melt(cbo.sentiment,
variable.name = "emotion",
value.name = "sentiment",
id.vars = c("created_at", "favorite_count", "retweet_count","text"))
cbo.reshape <- mutate(cbo.reshape, query = paste(cbo.name))
sentiment.combined <- rbind(nk.reshape, cbo.reshape)
# Two-Way ANOVA
sentiment.anova2way <- aov(sentiment ~ query + emotion, data = sentiment.combined)
summary(sentiment.anova2way)
} else {
print("No ANOVA Test Selected")
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.