# NOT RUN {
# compare Trump speeches to other Presidents by chi^2
dfmat1 <- data_corpus_inaugural %>%
corpus_subset(Year > 1980) %>%
dfm(groups = "President", remove = stopwords("english"), remove_punct = TRUE)
tstat1 <- textstat_keyness(dfmat1, target = "Trump")
textplot_keyness(tstat1, margin = 0.2, n = 10)
# compare contemporary Democrats v. Republicans
corp <- data_corpus_inaugural %>%
corpus_subset(Year > 1960)
docvars(corp, "party") <-
ifelse(docvars(corp, "President") %in% c("Nixon", "Reagan", "Bush", "Trump"),
"Republican", "Democrat")
dfmat2 <- dfm(corp, groups = "party", remove = stopwords("english"),
remove_punct = TRUE)
tstat2 <- textstat_keyness(dfmat2, target = "Democrat", measure = "lr")
textplot_keyness(tstat2, color = c("blue", "red"), n = 10)
# }
Run the code above in your browser using DataLab