-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvention_speech_sentiment_analysis.Rmd
525 lines (417 loc) · 27.2 KB
/
convention_speech_sentiment_analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
---
title: "Republican and Democratic National Convention Speech Sentiment Analysis"
author: Evan Eskew (eaeskew@ucdavis.edu) and Brian Todd (btodd@ucdavis.edu)
date: 09 August 2016
output: pdf_document
---
```{r, include = F}
library(dplyr)
library(tokenizers)
library(stringr)
library(readr)
library(syuzhet)
library(ggplot2)
library(lme4)
#==============================================================================
# Define functions used in downstream analysis
# Take a raw speech as a text file and import it into R, returning a
# character vector tokenized by word
process_speech <- function(rawspeech) {
read_file(rawspeech) %>%
tokenize_words() %>%
unlist()
}
# This function modified from Julia Silge
# Take text and process the sentiment using a given method
process_sentiment <- function(rawtext, mymethod) {
chunkedtext <- data_frame(x = rawtext) %>%
group_by(linenumber = ceiling(row_number() / 100)) %>%
summarize(text = str_c(x, collapse = " "))
mySentiment <-
data.frame(cbind(linenumber = chunkedtext$linenumber,
sentiment = get_sentiment(chunkedtext$text,
method = mymethod)))
}
# This function modified from Julia Silge
# Chunk the text
chunk_text <- function(rawtext) {
chunkedtext <- data_frame(x = rawtext) %>%
group_by(linenumber = ceiling(row_number() / 100)) %>%
summarize(text = str_c(x, collapse = " "))
}
# This function modified from Julia Silge
# Plot the text sentiment
plot_sentiment <- function(mySentiment) {
color.vec <- ifelse(mySentiment$sentiment >= 0,
"forestgreen", "firebrick3")
g <- ggplot(data = mySentiment, aes(x = linenumber, y = sentiment)) +
labs(y = "Sentiment", size = 2) +
geom_bar(stat = "identity", fill = color.vec) +
# geom_segment(data = myAnnotate, aes(x = x, y = y1, xend = x, yend = y2),
# arrow = arrow(length = unit(0.04, "npc")),
# inherit.aes = FALSE) +
theme_minimal() +
scale_x_discrete(expand=c(0.02,0)) +
coord_cartesian(ylim = c(-15, 15)) +
# theme(plot.caption=element_text(size=8)) +
theme(axis.text.y=element_text(margin=margin(r=-10))) +
theme(axis.title.x=element_blank()) +
theme(axis.ticks.x=element_blank()) +
theme(axis.text.x=element_blank())
}
#==============================================================================
# Analyze convention speechs from 1980-2016
# For every speech, I process the speech into R from .txt files, chunk the text
# into 100 word chunks, and perform the sentiment analysis using three
# different sentiment methods ('bing', 'afinn', and 'nrc')
# RNC 1980
reagan_80_speech <- process_speech("speeches/reagan_1980.txt")
reagan_80.chunked <- chunk_text(reagan_80_speech)
reagan_80.sentiment.bing <- process_sentiment(reagan_80_speech, "bing")
reagan_80.sentiment.afinn <- process_sentiment(reagan_80_speech, "afinn")
reagan_80.sentiment.nrc <- process_sentiment(reagan_80_speech, "nrc")
# DNC 1980
carter_80_speech <- process_speech("speeches/carter_1980.txt")
carter_80.chunked <- chunk_text(carter_80_speech)
carter_80.sentiment.bing <- process_sentiment(carter_80_speech, "bing")
carter_80.sentiment.afinn <- process_sentiment(carter_80_speech, "afinn")
carter_80.sentiment.nrc <- process_sentiment(carter_80_speech, "nrc")
# RNC 1984
reagan_84_speech <- process_speech("speeches/reagan_1984.txt")
reagan_84.chunked <- chunk_text(reagan_84_speech)
reagan_84.sentiment.bing <- process_sentiment(reagan_84_speech, "bing")
reagan_84.sentiment.afinn <- process_sentiment(reagan_84_speech, "afinn")
reagan_84.sentiment.nrc <- process_sentiment(reagan_84_speech, "nrc")
# DNC 1984
mondale_84_speech <- process_speech("speeches/mondale_1984.txt")
mondale_84.chunked <- chunk_text(mondale_84_speech)
mondale_84.sentiment.bing <- process_sentiment(mondale_84_speech, "bing")
mondale_84.sentiment.afinn <- process_sentiment(mondale_84_speech, "afinn")
mondale_84.sentiment.nrc <- process_sentiment(mondale_84_speech, "nrc")
# RNC 1988
bush_88_speech <- process_speech("speeches/bush_1988.txt")
bush_88.chunked <- chunk_text(bush_88_speech)
bush_88.sentiment.bing <- process_sentiment(bush_88_speech, "bing")
bush_88.sentiment.afinn <- process_sentiment(bush_88_speech, "afinn")
bush_88.sentiment.nrc <- process_sentiment(bush_88_speech, "nrc")
# DNC 1988
dukakis_88_speech <- process_speech("speeches/dukakis_1988.txt")
dukakis_88.chunked <- chunk_text(dukakis_88_speech)
dukakis_88.sentiment.bing <- process_sentiment(dukakis_88_speech, "bing")
dukakis_88.sentiment.afinn <- process_sentiment(dukakis_88_speech, "afinn")
dukakis_88.sentiment.nrc <- process_sentiment(dukakis_88_speech, "nrc")
# RNC 1992
bush_92_speech <- process_speech("speeches/bush_1992.txt")
bush_92.chunked <- chunk_text(bush_92_speech)
bush_92.sentiment.bing <- process_sentiment(bush_92_speech, "bing")
bush_92.sentiment.afinn <- process_sentiment(bush_92_speech, "afinn")
bush_92.sentiment.nrc <- process_sentiment(bush_92_speech, "nrc")
# DNC 1992
clinton_92_speech <- process_speech("speeches/clinton_1992.txt")
clinton_92.chunked <- chunk_text(clinton_92_speech)
clinton_92.sentiment.bing <- process_sentiment(clinton_92_speech, "bing")
clinton_92.sentiment.afinn <- process_sentiment(clinton_92_speech, "afinn")
clinton_92.sentiment.nrc <- process_sentiment(clinton_92_speech, "nrc")
# RNC 1996
dole_96_speech <- process_speech("speeches/dole_1996.txt")
dole_96.chunked <- chunk_text(dole_96_speech)
dole_96.sentiment.bing <- process_sentiment(dole_96_speech, "bing")
dole_96.sentiment.afinn <- process_sentiment(dole_96_speech, "afinn")
dole_96.sentiment.nrc <- process_sentiment(dole_96_speech, "nrc")
# DNC 1996
clinton_96_speech <- process_speech("speeches/clinton_1996.txt")
clinton_96.chunked <- chunk_text(clinton_96_speech)
clinton_96.sentiment.bing <- process_sentiment(clinton_96_speech, "bing")
clinton_96.sentiment.afinn <- process_sentiment(clinton_96_speech, "afinn")
clinton_96.sentiment.nrc <- process_sentiment(clinton_96_speech, "nrc")
# RNC 2000
bush_00_speech <- process_speech("speeches/bush_2000.txt")
bush_00.chunked <- chunk_text(bush_00_speech)
bush_00.sentiment.bing <- process_sentiment(bush_00_speech, "bing")
bush_00.sentiment.afinn <- process_sentiment(bush_00_speech, "afinn")
bush_00.sentiment.nrc <- process_sentiment(bush_00_speech, "nrc")
# DNC 2000
gore_00_speech <- process_speech("speeches/gore_2000.txt")
gore_00.chunked <- chunk_text(gore_00_speech)
gore_00.sentiment.bing <- process_sentiment(gore_00_speech, "bing")
gore_00.sentiment.afinn <- process_sentiment(gore_00_speech, "afinn")
gore_00.sentiment.nrc <- process_sentiment(gore_00_speech, "nrc")
# RNC 2004
bush_04_speech <- process_speech("speeches/bush_2004.txt")
bush_04.chunked <- chunk_text(bush_04_speech)
bush_04.sentiment.bing <- process_sentiment(bush_04_speech, "bing")
bush_04.sentiment.afinn <- process_sentiment(bush_04_speech, "afinn")
bush_04.sentiment.nrc <- process_sentiment(bush_04_speech, "nrc")
# DNC 2004
kerry_04_speech <- process_speech("speeches/kerry_2004.txt")
kerry_04.chunked <- chunk_text(kerry_04_speech)
kerry_04.sentiment.bing <- process_sentiment(kerry_04_speech, "bing")
kerry_04.sentiment.afinn <- process_sentiment(kerry_04_speech, "afinn")
kerry_04.sentiment.nrc <- process_sentiment(kerry_04_speech, "nrc")
# RNC 2008
mccain_08_speech <- process_speech("speeches/mccain_2008.txt")
mccain_08.chunked <- chunk_text(mccain_08_speech)
mccain_08.sentiment.bing <- process_sentiment(mccain_08_speech, "bing")
mccain_08.sentiment.afinn <- process_sentiment(mccain_08_speech, "afinn")
mccain_08.sentiment.nrc <- process_sentiment(mccain_08_speech, "nrc")
# DNC 2008
obama_08_speech <- process_speech("speeches/obama_2008.txt")
obama_08.chunked <- chunk_text(obama_08_speech)
obama_08.sentiment.bing <- process_sentiment(obama_08_speech, "bing")
obama_08.sentiment.afinn <- process_sentiment(obama_08_speech, "afinn")
obama_08.sentiment.nrc <- process_sentiment(obama_08_speech, "nrc")
# RNC 2012
romney_12_speech <- process_speech("speeches/romney_2012.txt")
romney_12.chunked <- chunk_text(romney_12_speech)
romney_12.sentiment.bing <- process_sentiment(romney_12_speech, "bing")
romney_12.sentiment.afinn <- process_sentiment(romney_12_speech, "afinn")
romney_12.sentiment.nrc <- process_sentiment(romney_12_speech, "nrc")
# DNC 2012
obama_12_speech <- process_speech("speeches/obama_2012.txt")
obama_12.chunked <- chunk_text(obama_12_speech)
obama_12.sentiment.bing <- process_sentiment(obama_12_speech, "bing")
obama_12.sentiment.afinn <- process_sentiment(obama_12_speech, "afinn")
obama_12.sentiment.nrc <- process_sentiment(obama_12_speech, "nrc")
```
Sentiment analysis is a method for quantifying the "feeling" of a text, specifically how positive or negative the sentiments are. For example, sentiment analysis has been used to evaluate the emotions in [Jane Austen's novels](http://juliasilge.com/blog/If-I-Loved-NLP-Less/) as well as the [lyrics from hip hop albums](https://cdn.rawgit.com/eveskew/rap_album_sentiment_analysis/38f1827942a307e4ca23a7f96390128bb9f1063e/rap_album_sentiment_analysis.html). The text in question can be any set of words, including political speeches. Typically, speeches are analyzed for the general public by being filtered through political pundits across various forms of media. While these opinions and perspectives can certainly be informative, they are rarely quantitative.
Here, we evaluate Republican and Democratic National Convention speeches using formal sentiment analysis methods, focusing on the recent speeches by Donald Trump and Hillary Clinton at the 2016 RNC and DNC.
# Sentiment of the Trump and Clinton Convention Speeches
To begin, we first collected the RNC and DNC speeches from this year's presidential nominees from an archive curated by [The American Presidency Project](http://www.presidency.ucsb.edu/nomination.php). After obtaining the speeches, we then divided them into 100 word segments and conducted a sentiment analysis to quantify the tone of those segments. Positive sentiment scores represent positive emotions; negative sentiment scores represent negative emotions. One way to visualize this sort of analysis is to graph the sentiment scores for each chunk of speech over time. The resulting plot shows the ebb and flow of emotional content throughout the speech's duration, each bar representing the sentiment for a 100 word chunk of the speech.
Here's that graph for Donald Trump's 2016 RNC speech:
```{r, echo = F, warning = F}
# RNC 2016
trump_16_speech <- process_speech("speeches/trump_2016.txt")
trump_16.chunked <- chunk_text(trump_16_speech)
trump_16.sentiment.bing <- process_sentiment(trump_16_speech, "bing")
trump_16.sentiment.afinn <- process_sentiment(trump_16_speech, "afinn")
trump_16.sentiment.nrc <- process_sentiment(trump_16_speech, "nrc")
p.trump_16 <- plot_sentiment(trump_16.sentiment.bing)
myAnnotate <-
data.frame(x = c(11, 46), y = rep(14, 2),
label = c('"death, destruction, terrorism, and weakness"',
"Mentions children, wife, father"),
y1 = rep(13, 2), y2 = c(0.2, 10.2))
p.trump_16 +
labs(title = "Sentiment in Trump's 2016 RNC Speech ('bing' Method)") +
geom_label(data = myAnnotate, aes(x, y, label = label), hjust = 0.5,
label.size = 0, size = 2.5, color="#2b2b2b",
inherit.aes = FALSE) +
geom_segment(data = myAnnotate, aes(x = x, y = y1, xend = x, yend = y2),
arrow = arrow(length = unit(0.04, "npc")), inherit.aes = FALSE)
```
Note that we've highlighted the context for the lowest and highest observed sentiment in Trump's speech. The most negative portion of Trump's speech came as he described Hillary Clinton's legacy in the State Department as one of "death, destruction, terrorism, and weakness." Moments later he claimed America faces "poverty and violence at home, war and destruction abroad." In contrast, his most positively scoring section occurred when he boasted of his children, his "greatest source of pride and joy" as well as his father, the "smartest and hardest working man." So, at least in broad strokes, it seems the sentiment analysis is indeed highlighting portions of the speech that a listener would identify as positive or negative.
For contrast, here's the same analysis for Hillary Clinton's 2016 DNC speech:
```{r, echo = F, warning = F}
# DNC 2016
clinton_h_16_speech <- process_speech("speeches/clinton_h_2016.txt")
clinton_h_16.chunked <- chunk_text(clinton_h_16_speech)
clinton_h_16.sentiment.bing <- process_sentiment(clinton_h_16_speech, "bing")
clinton_h_16.sentiment.afinn <- process_sentiment(clinton_h_16_speech, "afinn")
clinton_h_16.sentiment.nrc <- process_sentiment(clinton_h_16_speech, "nrc")
myAnnotate <-
data.frame(x = c(11, 15.5), y = c(14, 12),
label = c("Refuting Trump RNC claims",
'"love trumps hate"'),
y1 = c(13, 11), y2 = c(0.2, 9.2))
p.clinton_h_16 <- plot_sentiment(clinton_h_16.sentiment.bing)
p.clinton_h_16 +
labs(title = "Sentiment in Clinton's 2016 DNC Speech ('bing' Method)") +
geom_label(data = myAnnotate, aes(x, y, label = label), hjust = 0.5,
label.size = 0, size = 2.5, color="#2b2b2b",
inherit.aes = FALSE) +
geom_segment(data = myAnnotate, aes(x = c(11, 14), y = y1,
xend = c(11, 14), yend = y2),
arrow = arrow(length = unit(0.04, "npc")), inherit.aes = FALSE)
```
As you can see, the sentiment analysis indicates that Clinton struck a more consistent positive tone in her convention address. In this case, the quantitative analysis supports many of the [observations made by political commentators about the general atmosphere of the DNC](http://www.nbcnews.com/politics/first-read/first-read-democrats-seize-optimism-trump-surrendered-n618721). Indeed, Clinton's speech seems notably optimistic in comparison to Trump's, and in fact, one of the most negative portions of Hillary's speech was in the context of arguing *against* Trump's previous claims of a broken America that he "alone can fix."
# The 2016 Convention Speeches in a Historical Context
In addition to doing a one to one comparison of convention speeches from the 2016 election year, we can also put this year's speeches in a historical context. The American Presidency Project provides some texts of presidential nominee speeches stretching back to the 19th century. For our purposes, however, we decided to limit our search to more recent elections: those from 1980 on. If you need a reminder, here are all the presidential nominees from the two major parties since 1980, with the eventual winners **in bold**:
| Year | Republican Nominee | Democratic Nominee |
| --- | --- | --- |
| 1980 | **R. Reagan** | J. Carter |
| 1984 | **R. Reagan** | W. Mondale |
| 1988 | **G. H. W. Bush** | M. Dukakis |
| 1992 | G. H. W. Bush | **B. Clinton** |
| 1996 | B. Dole | **B. Clinton** |
| 2000 | **G. W. Bush** | A. Gore |
| 2004 | **G. W. Bush** | J. Kerry |
| 2008 | J. McCain | **B. Obama** |
| 2012 | M. Romney | **B. Obama** |
| 2016 | D. Trump | H. Clinton |
We collected the convention speeches for all of these candidates and analyzed them in the same way we did Trump and Clinton's. In order to get one overall sentiment score for a given speech, we simply looked at the sentiment scores for all the text chunks within a speech and took the average score. This data can be plotted over time to show the historical trends in the sentiment of presidential nominee speeches at national conventions. The following graph shows precisely that information. Red dots represent speeches of Republican candidates, blue dots represent Democratic candidates, and we've also labeled the highest and lowest observed sentiment scores for each political party:
```{r, echo = F, warning = F}
# Set up mean speech sentiment dataframes using the three different
# sentiment metrics
d.bing <- data.frame(
rep(c("Republican", "Democrat"), 10),
rep(c("red", "blue"), 10),
rep(c(1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016), each = 2),
c(mean(reagan_80.sentiment.bing$sentiment),
mean(carter_80.sentiment.bing$sentiment),
mean(reagan_84.sentiment.bing$sentiment),
mean(mondale_84.sentiment.bing$sentiment),
mean(bush_88.sentiment.bing$sentiment),
mean(dukakis_88.sentiment.bing$sentiment),
mean(bush_92.sentiment.bing$sentiment),
mean(clinton_92.sentiment.bing$sentiment),
mean(dole_96.sentiment.bing$sentiment),
mean(clinton_96.sentiment.bing$sentiment),
mean(bush_00.sentiment.bing$sentiment),
mean(gore_00.sentiment.bing$sentiment),
mean(bush_04.sentiment.bing$sentiment),
mean(kerry_04.sentiment.bing$sentiment),
mean(mccain_08.sentiment.bing$sentiment),
mean(obama_08.sentiment.bing$sentiment),
mean(romney_12.sentiment.bing$sentiment),
mean(obama_12.sentiment.bing$sentiment),
mean(trump_16.sentiment.bing$sentiment),
mean(clinton_h_16.sentiment.bing$sentiment)),
c(0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1),
c(1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, NA, NA))
colnames(d.bing) <-
c("Party", "Color", "Year", "Sentiment", "Incumbent", "Winner")
d.afinn <- data.frame(
rep(c("Republican", "Democrat"), 10),
rep(c("red", "blue"), 10),
rep(c(1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016), each = 2),
c(mean(reagan_80.sentiment.afinn$sentiment),
mean(carter_80.sentiment.afinn$sentiment),
mean(reagan_84.sentiment.afinn$sentiment),
mean(mondale_84.sentiment.afinn$sentiment),
mean(bush_88.sentiment.afinn$sentiment),
mean(dukakis_88.sentiment.afinn$sentiment),
mean(bush_92.sentiment.afinn$sentiment),
mean(clinton_92.sentiment.afinn$sentiment),
mean(dole_96.sentiment.afinn$sentiment),
mean(clinton_96.sentiment.afinn$sentiment),
mean(bush_00.sentiment.afinn$sentiment),
mean(gore_00.sentiment.afinn$sentiment),
mean(bush_04.sentiment.afinn$sentiment),
mean(kerry_04.sentiment.afinn$sentiment),
mean(mccain_08.sentiment.afinn$sentiment),
mean(obama_08.sentiment.afinn$sentiment),
mean(romney_12.sentiment.afinn$sentiment),
mean(obama_12.sentiment.afinn$sentiment),
mean(trump_16.sentiment.afinn$sentiment),
mean(clinton_h_16.sentiment.afinn$sentiment)),
c(0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1),
c(1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, NA, NA))
colnames(d.afinn) <-
c("Party", "Color", "Year", "Sentiment", "Incumbent", "Winner")
d.nrc <- data.frame(
rep(c("Republican", "Democrat"), 10),
rep(c("red", "blue"), 10),
rep(c(1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016), each = 2),
c(mean(reagan_80.sentiment.nrc$sentiment),
mean(carter_80.sentiment.nrc$sentiment),
mean(reagan_84.sentiment.nrc$sentiment),
mean(mondale_84.sentiment.nrc$sentiment),
mean(bush_88.sentiment.nrc$sentiment),
mean(dukakis_88.sentiment.nrc$sentiment),
mean(bush_92.sentiment.nrc$sentiment),
mean(clinton_92.sentiment.nrc$sentiment),
mean(dole_96.sentiment.nrc$sentiment),
mean(clinton_96.sentiment.nrc$sentiment),
mean(bush_00.sentiment.nrc$sentiment),
mean(gore_00.sentiment.nrc$sentiment),
mean(bush_04.sentiment.nrc$sentiment),
mean(kerry_04.sentiment.nrc$sentiment),
mean(mccain_08.sentiment.nrc$sentiment),
mean(obama_08.sentiment.nrc$sentiment),
mean(romney_12.sentiment.nrc$sentiment),
mean(obama_12.sentiment.nrc$sentiment),
mean(trump_16.sentiment.nrc$sentiment),
mean(clinton_h_16.sentiment.nrc$sentiment)),
c(0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1),
c(1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, NA, NA))
colnames(d.nrc) <-
c("Party", "Color", "Year", "Sentiment", "Incumbent", "Winner")
#==============================================================================
# Mean speech sentiment over time ('bing' method)
myAnnotate <-
data.frame(x = c(1988, 2012, 2012, 2015.5), y = c(3.35, 0.83, 3.6, 0.38),
label = c("M. Dukakis", "B. Obama", "M. Romney", "D. Trump"),
y1 = rep(13.5, 2), y2 = c(0.2, 8.2))
ggplot(data = d.bing, aes(x = Year, y = Sentiment)) +
geom_point(color = d.bing$Color, size = 4) +
geom_smooth(method = "lm", se = F, color = "black", size = 0.5) +
ggtitle("Sentiment of RNC and DNC Speeches ('bing' Method)") +
ylab("Mean Sentiment of the Convention Speech") +
scale_x_continuous(breaks = seq(from = 1980, to = 2016, by = 4)) +
theme_bw() +
coord_cartesian(ylim = c(0, 4)) +
geom_label(data = myAnnotate, aes(x, y, label = label), hjust = 0.5,
label.size = 0, size = 3.5, color="#2b2b2b",
inherit.aes = FALSE)
```
Just to double (and triple) check ourselves, we also repeated this analysis using two other methods to quantify the sentiment of the speeches (we've been using the 'bing' method throughout this article, but that's not too important). Essentially, using these two other methods (that have the names 'afinn' and 'nrc') provide us with a way to check for consistency: are the more negative speeches consistently ranked on the low end and vice versa? Recreating the same plot with these two other sentiment ranking methods, you get:
```{r, echo = F, warning = F}
# Mean speech sentiment over time ('afinn' method)
myAnnotate <-
data.frame(x = c(1984, 1988, 2012, 2015.5), y = c(1.5, 7.26, 6.3, 0),
label = c("W. Mondale", "M. Dukakis", "M. Romney", "D. Trump"),
y1 = rep(13.5, 2), y2 = c(0.2, 8.2))
ggplot(data = d.afinn, aes(x = Year, y = Sentiment)) +
geom_point(color = d.afinn$Color, size = 4) +
geom_smooth(method = "lm", se = F, color = "black", size = 0.5) +
ggtitle("Sentiment of RNC and DNC Speeches ('afinn' Method)") +
ylab("Mean Sentiment of the Convention Speech") +
scale_x_continuous(breaks = seq(from = 1980, to = 2016, by = 4)) +
theme_bw() +
coord_cartesian(ylim = c(0, 8)) +
geom_label(data = myAnnotate, aes(x, y, label = label), hjust = 0.5,
label.size = 0, size = 3.5, color="#2b2b2b",
inherit.aes = FALSE)
```
```{r, echo = F, warning = F}
# Mean speech sentiment over time ('nrc' method)
myAnnotate <-
data.frame(x = c(1988, 1992, 2004, 2008), y = c(5.29, 0.7, 5.57, 1.84),
label = c("M. Dukakis", "G. H. W. Bush",
"G. W. Bush", "B. Obama"),
y1 = rep(13.5, 2), y2 = c(0.2, 8.2))
ggplot(data = d.nrc, aes(x = Year, y = Sentiment)) +
geom_point(color = d.nrc$Color, size = 4) +
geom_smooth(method = "lm", se = F, color = "black", size = 0.5) +
ggtitle("Sentiment of RNC and DNC Speeches ('nrc' Method)") +
ylab("Mean Sentiment of the Convention Speech") +
scale_x_continuous(breaks = seq(from = 1980, to = 2016, by = 4)) +
theme_bw() +
coord_cartesian(ylim = c(0, 6)) +
geom_label(data = myAnnotate, aes(x, y, label = label), hjust = 0.5,
label.size = 0, size = 3.5, color="#2b2b2b",
inherit.aes = FALSE)
```
<!-- inserting extra blank line -->
Overall, our main takeaways from this historical analysis are:
- **Trump's 2016 convention speech appears to be historically negative**. Two of the three sentiment methods rank Donald Trump's speech as the most negative convention speech given by either party's presidential candidate since 1980.
- Despite his association with American exceptionalism, **these sentiment metrics rank Ronald Reagan's convention speeches in 1980 and 1984 as relatively negative**. All three metrics show his 1980 RNC speech as more negative than Jimmy Carter's offering at the 1980 DNC, and the sentiment rankings for the 1984 convention speeches (Reagan vs. Walter Mondale) are a wash across the different metric methods.
- All three sentiment metrics indicate that **Michael Dukakis gave the most positive DNC speech of any Democratic presidential nominee from 1980-2016**. And then he lost the election in a landslide.
- Based on these numbers, **from 2004-2012 the Republican presidential nominee gave a more positive national convention address than his Democratic counterpart**. Those elections were split: two wins for Bush, then two wins for Obama. Romney's 2012 RNC speech in particular was a historically positive Republican effort.
# Does It Matter?
Given this data and the fact that we're in the midst of election season, one natural question to ask might be: does the sentiment of a candidate's convention speech affect their chances of winning the presidency? Obviously, a tremendous number of other factors influence a presidential election, but maybe the convention speech is a reliable indicator of the general tone, and hence success, of a presidential campaign? Depending on your political leanings, this will be good or bad news, but the answer seems to be "no." The following plot shows the relationship between winning the presidency and the mean sentiment of a candidate's convention speech (dotted lines connect the two candidates who ran against each other in a given year):
```{r, echo = F, warning = F}
ggplot(data = d.bing, aes(x = Sentiment, y = Winner, group = Year)) +
geom_point(color = d.bing$Color, size = 4) +
geom_line(size = 0.5, linetype = 3) +
ylab("Winner in November?") +
xlab("Mean Sentiment of the Convention Speech") +
scale_y_continuous(breaks = c(0, 1), labels = c("No", "Yes")) +
theme_bw() +
coord_cartesian(xlim = c(0.5, 3.5))
```
There seems to be no real relationship here. Winning candidates have given some relatively negative and relatively positive speeches, as have losing candidates.
Instead of looking to see whether the convention speech is predictive of success in November, one might also wonder whether certain factors affect the tone of the convention speech itself. For example, maybe those candidates who are not incumbents find it more profitable to strike a negative tone in their convention speech as they attack the opposing party who has been in power for four (or more) years. According to the data, again the answer seems to be "no":
```{r, echo = F, warning = F}
ggplot(data = d.bing, aes(x = Incumbent, y = Sentiment, group = Year)) +
geom_point(color = d.bing$Color, size = 4) +
geom_line(size = 0.5, linetype = 3) +
ylab("Mean Sentiment of the Convention Speech") +
xlab("Candidate from the Incumbent Party?") +
scale_x_continuous(breaks = c(0, 1), labels = c("No", "Yes")) +
theme_bw() +
coord_cartesian(xlim = c(-0.25, 1.25), ylim = c(0.5, 3.5))
```
There's no trend here: incumbent status does not cleanly separate out convention speech sentiment scores. In fact, according to the 'bing' sentiment method (the one used here), both the most negative (Trump 2016) and most positive (Romney 2012) national convention speeches observed in the data set both came from the challenging party.
# Summary
While the sentiment of the convention speech seems far from a make or break issue for presidential hopefuls, this analysis does support many people's intuitions about the relative tones of the 2016 RNC and DNC. It also adds another layer to the wild and crazy ride that has been the Trump candidacy. Throughout his campaign, he has [famously flummoxed considered, well-informed expectations](http://fivethirtyeight.com/features/how-i-acted-like-a-pundit-and-screwed-up-on-donald-trump/) about what a presidential candidate does and does not do. And by most of the sentiment measures used here, **Donald Trump just gave the most negative convention speech by a major party presidential nominee since 1980**. Whether that will hurt or help him is anyone's guess...