Trump and Twitter

Donald Trump likes to tweet a lot. Some tweets have an angry sentiment or contain insults, and some are not. Several journalists have claimed that Trump sends tweets from a Samsung Galaxy when he is insulting people, places, and things, and from other devices, such as an iPhone, when he is not. It seems plausible that Trump’s staff members, like many politicians, post tweets to his account. Do tweets that Trump write have an angry sentiment compared to tweets written by his staff?

This analysis is based on David Robinson’s post Trump’s Android and iPhone tweets, one year later.

Data

Data Source

Trump’s last tweet from an Android was on March 25, 2017.

The data source used for this report was curated by Brendan Brown archive of Trump’s twitter posts..

All Trump’s tweets from Browns’s archive of Trump’s twitter posts. were downloaded on September 28, 2017. The Tweets included in the data range from Trump’s first tweet on December 11, 2012 to the last tweet using his Android on March 25, 2017.

Exploring the Data

In this section the data will be explored with a focus on assessing the evidence that the device used to tweet has a different usage pattern.

Tweets from the Android are sent at different times of day compared to the iPhone. The Android rarely sends links or pictures while the iPhone sends links and pictures.

Comparison of Words

Individual words that comprise Trump’s tweets are analyzed in this section. In other words, Trump’s tweets can be tokenized with stop words removed.

The plot below shows the twenty most frequent words appearing in his tweets during the study period.

Which words are more commonly used when the source is Android versus iPhone? One measure that can be used to compare the rates of words tweeted from an Android versus iPhone is the log-odds ratio.

\[\log\left(\frac{\frac{\#\text{ times word from Android }+1}{\text{Total Android Words}}} {\frac{\#\text{ times word from iPhone }+1}{\text{Total iPhone Words}}} \right) \]

This compares the odds of a word being tweeted from an Android compared to an iPhone.

The plot below shows the log-odds ratio for the top twenty words tweeted from an Android versus iPhone provided that the word had been tweeted at least five times. Words with a positive log-odds ratio imply that the word is tweeted at a higher rate on Android versus iPhone, and a negative log-odds ratio means that the word is tweeted at a higher rate on iPhone versus Android.

Sentiment Analysis of Words used in Trump’s Tweets

The NRC Emotion Lexicon is a list of English words and their associations with eight basic emotions (anger, fear, anticipation, trust, surprise, sadness, joy, and disgust) and two sentiments (negative and positive). The annotations were manually done by crowdsourcing.

Words can be classified into two sentiments (positive or negative) and eight emotions (sentiments: anger, anticipation, disgust, fear, joy, sadness, surprise, trust). Words can have a sentiment association and several emotional associations.

Several words and thier NRC classification is shown in the table below. Abandon, for example, falls into several categories.

word sentiment
abacus trust
abandon fear
abandon negative
abandon sadness
abandoned anger
abandoned fear

The bar chart below shows the distribution of sentiment and emotions for all the NRC categories for Android and iPhone.

The percentage of words in each category of sentiment/emotion was calculated as:

\[\text{Percentage of Words} = \frac{\#\text{ words in Sentiment/Emotion tweeted using Source}}{\text{Total number of words tweeted using Source}} \times 100 \]

Statistical Analysis

Comparing Rates of Words Categorized using the NRC Lexicon

One simple statistical model to compare word sentiments and emotions in Android versus iPhone is a Poisson regression.

The dependent variable \(Y_i,\, i=1,2\) is the count of words within a sentiment/emotion category for each source (2 sources) with \(n_i\) total words from the source. The covariate of interest \(x_i\) is source of the tweet:

\[ x_{i} =\left\{ \begin{array}{ll} 1 & \mbox{if } i^{th}\text{word from Android} \\ 0 & \mbox{if } i^{th} \text{word from iPhone} \end{array} \right. \]

The counts can be modelled as a Poisson random variable. A generalized linear model for word count is:

\[E\left( Y_i\right)=\mu_i=n_i\theta_i,\, Y_i \sim Poisson(\mu_i), \]

where \(\theta_i=\exp\left(x_i\beta\right).\) \(\mu_i\) is the average number of Trump tweets with a certain sentiment/emotion out of all the tweets sent from one of the sources during the time period December 12, 2012 and September 28, 2017. The natural link function is:

\[\log\left(\mu_i \right)=log(n_i)+x_i\beta. \]

The parameter estimate for \(\beta\) is an estimate of the rate ratio \[\log \left(\frac{E(Y_i|x_i=\text{Android})}{E(Y_i|x_i=\text{iPhone})} \right).\]

For example, \(\exp(\beta)\) is the percent increase in a word being tweeted from an Android versus an iPhone. The percent increase in tweets with words related to anticipation is 18%

This is identical to conducting a hypothesis test of \(H_0:\lambda_1=\lambda_2\). These hypotheses can be evaluated in R using poisson.test. A plot of the 95% confidence intervals is shown below.

Comparing AFINN Sentiment Score

To evaluate the sensitivity of lexicon choice, an analysis was conducted using the AFINN lexicon. The AFINN sentiment library words have been manually rated for valence with an integer between minus five (negative) and positive five (positive).

Tweets were tokenized into words. If a word is in the AFINN lexicon then it will be scored. The average score for each is then calculated.

A side-by-side boxplot of the distributions of AFINN scores by device, and the results of a two-sample t-test of the difference is shown below.

Difference Mean AFINN (Android - iPhone) P-value Lower 95% CI Upper 95% CI
-0.71 0 -0.83 -0.58

The boxplot and t-test show that tweets sent from an iPhone have a significantly higher sentiment compared to tweets sent from an Android.

Limitations

A few notable limitations are:

NB: Ideally this section would also describe how the limitations effect the analysis.

Conclusions

Negative words and words associated with disgust, sadness, anger, and fear are tweeted more frequently from an Android versus iPhone during the study period. Positive words and words associated with surprise, joy, anticipation, and trust are tweeted at a higher rate from Android versus iPhone, although the magnitude of the percent increase is less compared to negative and angry words. The percent increase of negative and angry words from the Android device are significantly greater compared to positive words.

Trump’s staffs’ tweets have a positive sentiment compared to Trump’s tweets. Overall, Trump’s tweets have a neutral sentiment, and his staffs’ tweets have a positive sentiment.