Have a snickers

With all the work around sentiment analysis of Trump’s Tweets, I thought that I would add my observation to the discipline. And with vague memories of an analysis of favourability of judges rulings by time of day


I thought I would check Trump’s tweets for negativity by time of day. This code is essentially that used in the blog piece


then tweaked by me to get the hour of the UTC tweet and subtract 5 for East Coast U.S. Time (as a quick and dirty time zone adjustment)

api_key = "you_need_to_use_your_own"
api_secret = "you_need_to_use_your_own"
access_token = "you_need_to_use_your_own"
access_token_secret = "you_need_to_use_your_own"
trump <- userTimeline("realDonaldTrump",
 n = 3100,
 includeRts = TRUE,
 excludeReplies = FALSE) %>% twListToDF()

words <- trump %>%
 select(id, statusSource, retweetCount, favoriteCount, created, isRetweet, text) %>%
 unnest_tokens(word, text) %>% 
 mutate(android = stringr::str_detect(statusSource, "Android"), tweethour = hour(created) - 5) %>%
 select(- statusSource) %>%

trumphrs <- words %>% filter(android)

boxplot(trumphrs$score ~ trumphrs$tweethour, varwidth=TRUE)

As indicated in the code, you would need to user your own Twitter developer details to get the code to run.

Which makes a boxplot like:


Which suggests the most negative tweets are at about 8am, 10am, 1pm, and 4pm East Coast U.S. time. I will speculate there is a food related pattern, but there is a lot of overlap in the box plots, which is not to surprising given the range of the sentiment index and the range of peoples vocabulary.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s