<div> I decided to return to the analysis I conducted for the IRA tweets dataset. (You can read up on that analysis and R code <a href="https://www.deeplytrivial.com/2018/08/statistics-sunday-getting-started-with.html">here</a>.) Specifically, I returned to the LDA results, which looked like they lined up pretty well with the account categories identified by Darren Linvill and Patrick Warren. But with slightly altered code, we can confirm that or see if there’s more to the topics data than meets the eye. (Spoiler alert: There is more than meets the eye.)
<p>I reran much of the original code – creating the file, removing non-English tweets and URLs, generating the DTM and conducting the 6-topic LDA. For brevity, I’m not including it in this post, but once again, you can see it <a href="https://www.deeplytrivial.com/2018/08/statistics-sunday-getting-started-with.html">here</a>.</p>
<p>I will note that the topics were numbered a bit differently than they were in my previous analysis. Here’s the new plot. The results look very similar to before. (LDA is a variational Bayesian method and there is an element of randomness to it, so the results aren’t a one-to-one match, but they’re very close.)</p>
<div>
<div>
<div>
<pre><span>top_terms</span> <span>&lt;-</span> <span>tweet_topics</span> <span>%>%</span><br>  <span>group_by</span><span>(topic)</span> <span>%>%</span><br>  <span>top_n</span><span>(</span><span>15</span><span>, beta)</span> <span>%>%</span><br>  <span>ungroup</span><span>()</span> <span>%>%</span><br>  <span>arrange</span><span>(topic,</span> <span>-</span><span>beta)</span><br><br><span>top_terms</span> <span>%>%</span><br>  <span>mutate</span><span>(</span><span>term</span> <span>=</span> <span>reorder</span><span>(term, beta))</span> <span>%>%</span><br>  <span>ggplot</span><span>(</span><span>aes</span><span>(term, beta,</span> <span>fill</span> <span>=</span> <span>factor</span><span>(topic)))</span> <span>+</span><br>  <span>geom_col</span><span>(</span><span>show.legend</span> <span>=</span> <span>FALSE</span><span>)</span> <span>+</span><br>  <span>facet_wrap</span><span>(</span><span>~</span><span>topic,</span> <span>scales</span> <span>=</span> <span>&quot;free&quot;</span><span>)</span> <span>+</span><br>  <span>coord_flip</span><span>()</span><br></pre>
</div>
</div>
<p></p>
<div><a rel="nofollow" href="https://i2.wp.com/4.bp.blogspot.com/-hJygd-E_nK8/W3dCDRiQJxI/AAAAAAAANb8/lgM_BRBobUIsT6FQnFbnQEJbpfmqQnSbwCLcBGAs/s1600/LDA_results1.png?ssl=1" target="_blank"><img border="0" src="https://i1.wp.com/4.bp.blogspot.com/-hJygd-E_nK8/W3dCDRiQJxI/AAAAAAAANb8/lgM_BRBobUIsT6FQnFbnQEJbpfmqQnSbwCLcBGAs/s320/LDA_results1.png?resize=320%2C173&ssl=1" data-original-width="450" width="320" data-original-height="486" data-recalc-dims="1" height="173"></a></div>
</div>
<p>Before, when I generated a plot of the LDA results, I asked it to give me the top 15 terms by topic. I’ll use the same code, but instead have it give the top topic for each term.</p>
<div>
<div>
<div>
<pre><span>word_topic</span> <span>&lt;-</span> <span>tweet_topics</span> <span>%>%</span><br>  <span>group_by</span><span>(term)</span> <span>%>%</span><br>  <span>top_n</span><span>(</span><span>1</span><span>, beta)</span> <span>%>%</span><br>  <span>ungroup</span><span>()</span><br></pre>
</div>
</div>
</div>
<p>I can then match this dataset up to the original tweetwords dataset, to show which topic each word is most strongly associated with. Because the word variable is known by two different variable names in my datasets, I need to tell R how to match.</p>
<div>
<div>
<div>
<pre><span>tweetwords</span> <span>&lt;-</span> <span>tweetwords</span> <span>%>%</span><br>  <span>left_join</span><span>(word_topic,</span> <span>by</span> <span>=</span> <span>c</span><span>(</span><span>&quot;word&quot;</span> <span>=</span> <span>&quot;term&quot;</span><span>))</span><br></pre>
</div>
</div>
</div>
<p>Now we can generate a crosstable, which displays the matchup between LDA topic (1-6) and account category (Commercial, Fearmonger, Hashtag Gamer, Left Troll, News Feed, Right Troll, and Unknown).</p>
<div>
<div>
<div>
<pre><span>cat_by_topic</span> <span>&lt;-</span> <span>table</span><span>(tweetwords</span><span>$</span><span>account_category, tweetwords</span><span>$</span><span>topic)</span><br><span>cat_by_topic</span><br></pre>
</div>
<div>
<pre>##               <br>##                      1       2       3       4       5       6<br>##   Commercial     38082   34181   49625  952309   57744   19380<br>##   Fearmonger      9187    3779   37326    1515    8321    4864<br>##   HashtagGamer  117517  103628  183204   31739  669976   81803<br>##   LeftTroll     497796 1106698  647045   94485  395972  348725<br>##   NewsFeed     2715106  331987  525710   91164  352709  428937<br>##   RightTroll    910965  498983 1147854  113829  534146 2420880<br>##   Unknown         7622    5198   12808    1497   11282    4605<br></pre>
</div>
</div>
</div>
<p>This table is a bit hard to read, because it’s frequencies, and the total number of words for each topic and account category differ. But we can solve that problem by asking instead for proportions. I’ll have it generate proportions by column, so we can see the top account category associated with each topic.</p>
<div>
<div>
<div>
<pre><span>options</span><span>(</span><span>scipen</span> <span>=</span> <span>999</span><span>)</span><br><span>prop.table</span><span>(cat_by_topic,</span> <span>2</span><span>)</span> <span>#column percentages - which topic is each category most associated with</span><br></pre>
</div>
<div>
<pre>##               <br>##                          1           2           3           4           5<br>##   Commercial   0.008863958 0.016398059 0.019060352 0.740210550 0.028443218<br>##   Fearmonger   0.002138364 0.001812945 0.014336458 0.001177579 0.004098712<br>##   HashtagGamer 0.027353230 0.049714697 0.070366404 0.024670084 0.330013053<br>##   LeftTroll    0.115866885 0.530929442 0.248522031 0.073441282 0.195045686<br>##   NewsFeed     0.631967460 0.159268087 0.201918749 0.070859936 0.173735438<br>##   RightTroll   0.212036008 0.239383071 0.440876611 0.088476982 0.263106667<br>##   Unknown      0.001774095 0.002493699 0.004919395 0.001163588 0.005557225<br>##               <br>##                          6<br>##   Commercial   0.005856411<br>##   Fearmonger   0.001469844<br>##   HashtagGamer 0.024719917<br>##   LeftTroll    0.105380646<br>##   NewsFeed     0.129619781<br>##   RightTroll   0.731561824<br>##   Unknown      0.001391578<br></pre>
</div>
</div>
</div>
<p>Category 1 is News Feed, Category 2 Left Troll, Category 4 Commercial, and Category 5 Hashtag Gamer. But look at Categories 3 and 6. For both, the highest percentage is Right Troll. Fearmonger is not most strongly associated with any specific topic. What happens if we instead ask for a proportion table by row, which tells us which category each topic most associated with?</p>
<div>
<div>
<div>
<pre><span>prop.table</span><span>(cat_by_topic,</span> <span>1</span><span>)</span> <span>#row percentages - which category is each topic most associated with</span><br></pre>
</div>
<div>
<pre>##               <br>##                         1          2          3          4          5<br>##   Commercial   0.03307679 0.02968851 0.04310266 0.82714465 0.05015456<br>##   Fearmonger   0.14135586 0.05814562 0.57431684 0.02331056 0.12803114<br>##   HashtagGamer 0.09893111 0.08723872 0.15422939 0.02671932 0.56401601<br>##   LeftTroll    0.16106145 0.35807114 0.20935083 0.03057054 0.12811638<br>##   NewsFeed     0.61073827 0.07467744 0.11825366 0.02050651 0.07933866<br>##   RightTroll   0.16190164 0.08868197 0.20400284 0.02023031 0.09493132<br>##   Unknown      0.17720636 0.12085000 0.29777736 0.03480424 0.26229889<br>##               <br>##                         6<br>##   Commercial   0.01683284<br>##   Fearmonger   0.07483998<br>##   HashtagGamer 0.06886545<br>##   LeftTroll    0.11282966<br>##   NewsFeed     0.09648546<br>##   RightTroll   0.43025192<br>##   Unknown      0.10706315<br></pre>
</div>
</div>
</div>
<p>Based on these results, Fearmonger now seems closest to Category 3 and Right Troll with Category 6. But Right Troll also shows up on Categories 3 (20%) and 1 (16%). Left Trolls show up in these categories at almost each proportions. It appears, then, that political trolls show strong similarity in topics with Fearmongers (stirring things up) and News Feed (“informing”) trolls. Unknown isn’t the top contributer to any topic, but it aligns with Category 3 (showing elements of Fearmongering) and 5 (showing elements of Hashtag Gaming). Let’s focus in on 5 categories.</p>
<div>
<div>
<div>
<pre><span>categories</span> <span>&lt;-</span> <span>c</span><span>(</span><span>&quot;Fearmonger&quot;</span><span>,</span> <span>&quot;HashtagGamer&quot;</span><span>,</span> <span>&quot;LeftTroll&quot;</span><span>,</span> <span>&quot;NewsFeed&quot;</span><span>,</span> <span>&quot;RightTroll&quot;</span><span>)</span><br><br><span>politics_fear_hash</span> <span>&lt;-</span> <span>tweetwords</span> <span>%>%</span><br>  <span>filter</span><span>(account_category</span> <span>%in%</span> <span>categories)</span><br><br><span>PFH_counts</span> <span>&lt;-</span> <span>politics_fear_hash</span> <span>%>%</span><br>  <span>count</span><span>(account_category, topic, word,</span> <span>sort</span> <span>=</span> <span>TRUE</span><span>)</span> <span>%>%</span><br>  <span>ungroup</span><span>()</span><br></pre>
</div>
</div>
</div>
<p>For now, let’s define our topics like this: 1 = News Feed, 2 = Left Troll, 3 = Fearmonger, 4 = Commercial, 5 = Hashtag Gamer, and 6 = Right Troll. We’ll ask R to go through our PFH dataset and tell us when account category topic matches and when it mismatches. Then we can look at these terms.</p>
<div>
<div>
<div>
<pre><span>PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>ifelse</span><span>(PFH_counts</span><span>$</span><span>account_category</span> <span>==</span> <span>&quot;NewsFeed&quot;</span> <span>&amp;</span> <span>PFH_counts</span><span>$</span><span>topic</span> <span>==</span> <span>1</span><span>,PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>&quot;Match&quot;</span><span>,</span><br>                           <span>ifelse</span><span>(PFH_counts</span><span>$</span><span>account_category</span> <span>==</span> <span>&quot;LeftTroll&quot;</span> <span>&amp;</span> <span>PFH_counts</span><span>$</span><span>topic</span> <span>==</span> <span>2</span><span>,PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>&quot;Match&quot;</span><span>,</span><br>                                  <span>ifelse</span><span>(PFH_counts</span><span>$</span><span>account_category</span> <span>==</span> <span>&quot;Fearmonger&quot;</span> <span>&amp;</span> <span>PFH_counts</span><span>$</span><span>topic</span> <span>==</span> <span>3</span><span>,PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>&quot;Match&quot;</span><span>,</span><br>                                         <span>ifelse</span><span>(PFH_counts</span><span>$</span><span>account_category</span> <span>==</span> <span>&quot;HashtagGamer&quot;</span> <span>&amp;</span> <span>PFH_counts</span><span>$</span><span>topic</span> <span>==</span> <span>5</span><span>,PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>&quot;Match&quot;</span><span>,</span><br>                                                <span>ifelse</span><span>(PFH_counts</span><span>$</span><span>account_category</span> <span>==</span> <span>&quot;RightTroll&quot;</span> <span>&amp;</span> <span>PFH_counts</span><span>$</span><span>topic</span> <span>==</span> <span>6</span><span>,PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>&quot;Match&quot;</span><span>,</span><br>                                                       <span>PFH_counts</span><span>$</span><span>match</span> <span>&lt;-</span> <span>&quot;NonMatch&quot;</span><span>)))))</span><br><br><span>top_PFH</span> <span>&lt;-</span> <span>PFH_counts</span> <span>%>%</span><br>  <span>group_by</span><span>(account_category, match)</span> <span>%>%</span><br>  <span>top_n</span><span>(</span><span>15</span><span>, n)</span> <span>%>%</span><br>  <span>ungroup</span><span>()</span> <span>%>%</span><br>  <span>arrange</span><span>(account_category,</span> <span>-</span><span>n)</span><br><br><span>top_PFH</span> <span>%>%</span><br>  <span>mutate</span><span>(</span><span>word</span> <span>=</span> <span>reorder</span><span>(word, n))</span> <span>%>%</span><br>  <span>ggplot</span><span>(</span><span>aes</span><span>(word, n,</span> <span>fill</span> <span>=</span> <span>factor</span><span>(match)))</span> <span>+</span><br>  <span>geom_col</span><span>(</span><span>show.legend</span> <span>=</span> <span>FALSE</span><span>)</span> <span>+</span><br>  <span>facet_wrap</span><span>(</span><span>~</span><span>account_category,</span> <span>scales</span> <span>=</span> <span>&quot;free&quot;</span><span>)</span> <span>+</span><br>  <span>coord_flip</span><span>()</span><br></pre>
</div>
</div>
<p></p>
<div><a rel="nofollow" href="https://i1.wp.com/1.bp.blogspot.com/-e2VLYBV1NCw/W3dCcoOra-I/AAAAAAAANcE/X-BLMrZlIYIA735_zG4-2gJI2JXKox_iwCLcBGAs/s1600/match_mismatch.png?ssl=1" target="_blank"><img border="0" src="https://i1.wp.com/1.bp.blogspot.com/-e2VLYBV1NCw/W3dCcoOra-I/AAAAAAAANcE/X-BLMrZlIYIA735_zG4-2gJI2JXKox_iwCLcBGAs/s320/match_mismatch.png?resize=320%2C229&ssl=1" data-original-width="450" width="320" data-original-height="650" data-recalc-dims="1" height="229"></a></div>
</div>
<p>Red indicates a match and blue indicates a mismatch. So when Fearmongers talk about food poisoning or Koch Farms, it’s a match, but when they talk about Hillary Clinton or the police, it’s a mismatch. Terms like “MAGA” and “CNN” are matches for Right Trolls but “news” and “love” are mismatches. Left Trolls show a match when tweeting about “Black Lives Matter” or “police” but a mismatch when tweeting about “Trump” or “America.” An interesting observation is that Trump is a mismatch for every topic it’s displayed under on the plot. (Now, realdonaldtrump, Trump’s Twitter handle, is a match for Right Trolls.) So where does that term, and associated terms like “Donald” belong?</p>
<div>
<div>
<div>
<pre><span>tweetwords</span> <span>%>%</span><br>  <span>filter</span><span>(word</span> <span>%in%</span> <span>c</span><span>(</span><span>&quot;donald&quot;</span><span>,</span> <span>&quot;trump&quot;</span><span>))</span><br></pre>
</div>
<div>
<pre>## # A tibble: 157,844 x 7<br>##    author publish_date     account_category id         word  topic    beta<br>##    </pre></div></div></div></div>