{"id":2740,"date":"2018-03-20T08:59:16","date_gmt":"2018-03-20T13:59:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=2740"},"modified":"2018-04-11T07:40:47","modified_gmt":"2018-04-11T12:40:47","slug":"what-is-president-trump-tweeting-about-that-gets-our-attention","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2018\/03\/20\/what-is-president-trump-tweeting-about-that-gets-our-attention\/","title":{"rendered":"What is President Trump tweeting about that gets our attention?"},"content":{"rendered":"<div class=\"content\">\n\n<!--introduction-->\n\nToday I'd like to introduce a guest blogger, Grace Kennedy, who works for the Training Services team here at MathWorks. She has been interested in learning what we can find from Twitter, and she will share techniques she uses in her Twitter data analysis.\n\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/INTROWORDCLOUDrs.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n\nHi, I\u2019m Grace Kennedy. I've been fascinated with how President Trump uses Twitter - what he talks about and how people respond to him. So when the <a href=\"https:\/\/www.mathworks.com\/products\/text-analytics.html\">Text Analytics Toolbox<\/a> was introduced in R2017b, I could not wait to use it to work with Twitter data. In this blogpost, I'll show you how to retrieve and work with tweets and investigate what President Trump is tweeting about that is so popular.\n\n<!--\/introduction-->\n<h3>Contents<\/h3>\n<div>\n<ul>\n \t<li><a href=\"#030f11b8-8fd5-4121-b583-b8bd131fc06d\">Getting Twitter Data<\/a><\/li>\n \t<li><a href=\"#48f65414-0b90-4d64-85bf-8017dcdaa83a\">There Was More to Defining Popularity Than I Expected<\/a><\/li>\n \t<li><a href=\"#a5b6e910-41e6-4c90-bbf0-4a97f6f0ddc0\">What are all the tweets about?<\/a><\/li>\n \t<li><a href=\"#57e59a01-953a-42b5-b837-caceb1ee938f\">And which topics are the most popular?<\/a><\/li>\n \t<li><a href=\"#cc66bc93-87ff-4c84-b99c-e4996b42077b\">Do you work with text data?<\/a><\/li>\n<\/ul>\n<\/div>\n<h4>Getting Twitter Data<a name=\"030f11b8-8fd5-4121-b583-b8bd131fc06d\"><\/a><\/h4>\nAs of R2017b, you can use MATLAB functions from the <a href=\"https:\/\/www.mathworks.com\/products\/datafeed.html\">Datafeed Toolbox<\/a> to retrieve tweets. First you will need to <a href=\"https:\/\/developer.twitter.com\/en\/docs\/basics\/authentication\/guides\/access-tokens\">sign up for a developer account<\/a> with Twitter to obtain credentials.\n\nI have my developer credentials saved as a MAT-file for privacy. We pass our credentials to the <tt><a href=\"https:\/\/www.mathworks.com\/help\/datafeed\/twitter.html\">twitter<\/a><\/tt> function to open a connection to the Twitter API. Then, searching Twitter is an easy one-liner with the <tt><a href=\"https:\/\/www.mathworks.com\/help\/datafeed\/twitter.search.html\">search<\/a><\/tt> function. The response is a <tt>struct<\/tt> with information about the individual tweets and the search metadata.\n<pre class=\"codeinput\">load <span class=\"string\">creds.mat<\/span>\nconnection = twitter(consumerKey,consumerSecret,accessToken,accessTokenSecret);\n<span class=\"comment\">% 100 is the maximum number of tweets that can be pulled at a time<\/span>\nresponse = search(connection,<span class=\"string\">'mathworks'<\/span>,<span class=\"string\">'count'<\/span>,100,<span class=\"string\">'lang'<\/span>,<span class=\"string\">'en'<\/span>)\n<\/pre>\n<pre class=\"codeoutput\">response = \n  ResponseMessage with properties:\n\n    StatusLine: 'HTTP\/1.1 200 OK'\n    StatusCode: OK\n        Header: [1\u00d726 matlab.net.http.HeaderField]\n          Body: [1\u00d71 matlab.net.http.MessageBody]\n     Completed: 0\n<\/pre>\nEach status contains information about a single tweet, such as the number of likes, when the tweet was posted, and the text of the tweet.\n<pre class=\"codeinput\"><span class=\"comment\">% extract each status as a string<\/span>\ntweets = cellfun(@(x) extractBefore(string(x.text),50), response.Body.Data.statuses);\ntweets(1:3)\n<\/pre>\n<pre class=\"codeoutput\">ans = \n  3\u00d71 string array\n    \"listening to NPR and there's a mathworks ad? :thi\"\n    \"RT @MetrowestSTEM: Thank you @MathWorks, Underwri\"\n    \"Basics of eigenvalues and eigenvectors with MIT P\"\n<\/pre>\nI was looking for tweets from a specific user. The syntax for queries that are more advanced than just a search string can be found in the <a href=\"https:\/\/developer.twitter.com\/en\/docs\/tweets\/search\/guides\/standard-operators\">Twitter documentation<\/a>. This query takes the form <tt>'from:mathworks'<\/tt>. However, we must use <a href=\"https:\/\/en.wikipedia.org\/wiki\/Percent-encoding\">percent encoding<\/a>. So, we need to change the colon to <tt>%3A<\/tt>. We can automate percent encoding using a trick from <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/951521\">Toshi Takeuchi's<\/a> February <a title=\"https:\/\/blogs.mathworks.com\/developer\/2017\/02\/07\/connect-to-twitter-with-oauth-over-http-interface\/ (link no longer works)\">blogpost<\/a>, which sparked my original interest in using MATLAB for Twitter analysis.\n<pre class=\"codeinput\">pctencode = @(str) replace(char(java.net.URLEncoder.encode(str,<span class=\"string\">'UTF-8'<\/span>) ),<span class=\"string\">'+'<\/span>,<span class=\"string\">'%20'<\/span>);\nst = pctencode(<span class=\"string\">'from:mathworks'<\/span>)\n<\/pre>\n<pre class=\"codeoutput\">st =\n    'from%3Amathworks'\n<\/pre>\n<pre class=\"codeinput\">response = search(connection,st,<span class=\"string\">'count'<\/span>,100,<span class=\"string\">'lang'<\/span>,<span class=\"string\">'en'<\/span>);\ntweets = cellfun(@(x) extractBefore(string(x.text),50), response.Body.Data.statuses);\ntweets(1:3)\n<\/pre>\n<pre class=\"codeoutput\">ans = \n  3\u00d71 string array\n    \"#HardTech Is it possible to add EtherCAT Master t\"\n    \"Uses #drones and kites as #renewable energy sourc\"\n    \"Are We Taking the \u201cU\u201d Out of UX? - What is a UX d\"\n<\/pre>\nSeveral months and 1033 tweets later, here is what I found.\n<h4>There Was More to Defining Popularity Than I Expected<a name=\"48f65414-0b90-4d64-85bf-8017dcdaa83a\"><\/a><\/h4>\nMy first thought was to define popularity as the number of retweets and likes a tweet receives. So, as I pulled Twitter responses, I saved these metrics, the date of each tweet, and the tweets themselves.\n<pre class=\"codeinput\">data = readtable(<span class=\"string\">'someTrumpTweets.csv'<\/span>,<span class=\"string\">'TextType'<\/span>,<span class=\"string\">'string'<\/span>);\ndata = table2timetable(data);\n<\/pre>\nLet's take a quick peek at the numeric data.\n<pre class=\"codeinput\">subplot(2,1,1)\nplot(data.whenTweeted,[data.retweetsNo,data.likesNo],<span class=\"string\">'o'<\/span>)\nlegend(<span class=\"string\">'Number of Retweets'<\/span>, <span class=\"string\">'Number of Likes'<\/span>, <span class=\"string\">'Location'<\/span>,<span class=\"string\">'northwest'<\/span>)\naxis(<span class=\"string\">'tight'<\/span>)\nsubplot(2,1,2)\nplot(data.retweetsNo,data.likesNo,<span class=\"string\">'o'<\/span>)\nxlabel(<span class=\"string\">'Number of Retweets'<\/span>)\nylabel(<span class=\"string\">'Number of Likes'<\/span>)\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n\nIt turns out that the number of retweets and number of likes are highly correlated, so we can remove the number of retweets. In R2018a, functionality to work more easily with table variables was added, including the <tt>removevars<\/tt> function.\n<pre class=\"codeinput\">data = removevars(data,<span class=\"string\">'retweetsNo'<\/span>);\n<\/pre>\nI also looked at whether the time of day or day of the week had any effect on the popularity of a tweet. This was easy with the <tt>groupsummary<\/tt> function in R2018a, which enables group summary statistics on timetables. While I didn't find that popularity of the tweets varied by time of day, I did find that President Trump tweets more at some times than others.\n<pre class=\"codeinput\"><span class=\"comment\">% number of tweets by hour of day<\/span>\nbyHour = groupsummary(data(:,<span class=\"string\">'likesNo'<\/span>),<span class=\"string\">'whenTweeted'<\/span>,<span class=\"string\">'hourofday'<\/span>);\nfigure\nbar(0:23,byHour.GroupCount)\nxlabel(<span class=\"string\">'Hour of the Day'<\/span>)\nylabel(<span class=\"string\">'Total Number of Tweets'<\/span>)\ntitle(<span class=\"string\">'Number of Tweets By Hour of the Day'<\/span>)\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_02.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n\nAfter about five months of data collection, I realized that I had introduced systematic bias into my data. Tweets that are up longer have had more time to collect likes. While the Twittersphere moves quickly, I observed that weekend posts were getting a lot more likes than weekday ones. This was in part because I collected data several times a day... during the workday. This meant weekend tweets would naturally have more time to accumulate likes.\n\nLuckily, I had been stashing my raw data from each pull for reproducibility, so I was able to go back and correct this. I merged datasets, keeping likes from the latest recording available. This is not perfect, but each tweet had a few days to collect likes.\n\nAfter adjusting for the bias, we test for statistical significance using <tt><a href=\"https:\/\/www.mathworks.com\/help\/stats\/ttest2.html\">ttest2<\/a><\/tt> and still see weekend tweets receive more likes than workday tweets. Perhaps this is because people have more time during the weekend to be active on social media.\n<pre class=\"codeinput\">data.wkEnd = isweekend(data.whenTweeted);\nboxplot(data.likesNo,data.wkEnd,<span class=\"string\">'Labels'<\/span>,{<span class=\"string\">'Weekday'<\/span> <span class=\"string\">'Weekend'<\/span>})\nylabel(<span class=\"string\">'Number of Likes'<\/span>)\ntitle(<span class=\"string\">'Weekday vs. Weekend'<\/span>)\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_03.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n<pre class=\"codeinput\"><span class=\"comment\">% test for statistical significance<\/span>\nttest2(data.likesNo(data.wkEnd),data.likesNo(~data.wkEnd))\n<\/pre>\n<pre class=\"codeoutput\">ans =\n     1\n<\/pre>\n<h4>What are all the tweets about?<a name=\"a5b6e910-41e6-4c90-bbf0-4a97f6f0ddc0\"><\/a><\/h4>\nThe president likes to call out individuals, themes, and slogans with hashtags and @ mentions. It is a concise way of linking ideas and people or corporations. As of R2018a, we can identify many of these common elements in text data with the <tt>'DetectPatterns'<\/tt> option for the <tt><a href=\"https:\/\/www.mathworks.com\/help\/textanalytics\/ref\/tokenizeddocument.html\">tokenizedDocument<\/a><\/tt> function. Hashtags give us a pretty good idea of what President Trump likes to call out.\n<pre class=\"codeinput\">tweetDocuments = tokenizedDocument(data.tweets,<span class=\"string\">'DetectPatterns'<\/span>,{<span class=\"string\">'at-mention'<\/span>,<span class=\"string\">'hashtag'<\/span>,<span class=\"string\">'web-address'<\/span>});\ntweetDeets = tokenDetails(tweetDocuments);\ntweetDeets(37:39,:)\n<\/pre>\n<pre class=\"codeoutput\">ans =\n  3\u00d74 table\n     Token      DocumentNumber    LineNumber       Type    \n    ________    ______________    __________    ___________\n    \"Jersey\"          2               1         letters    \n    \".\"               2               1         punctuation\n    \"#MAGA\"           2               1         hashtag    \n<\/pre>\n<pre class=\"codeinput\">hashtags = tweetDeets(tweetDeets.Type == <span class=\"string\">'hashtag'<\/span>,:);\nwordcloud(hashtags.Token);\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_04.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n\nNot only does looking at the hashtags give us an idea of what President Trump is tweeting about (#taxreform, #fakenews, #maga), but we see some abbreviations that represent common phrases he likes to use. I used the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/local-functions-in-scripts.html\">custom function<\/a> below, <tt>replaceHashtags<\/tt>, to replace non-word hashtags with their complete phrases (like \"MAGA\" with his campaign slogan, \"Make America Great Again\") before visualizing common phrases.\n<pre class=\"codeinput\"><span class=\"comment\">% make everything lower case<\/span>\ncleanDocs = lower(tweetDocuments);\n<span class=\"comment\">% replace hashtag abbreviations with standard language<\/span>\ncleanDocs = replaceHashtags(cleanDocs);\n<\/pre>\nAs of R2018a, we can create bags of N-grams, which enables us to look at phrases rather than just individual words. I first did a little processing to remove some noise in the form of punctuation or words that don't tell us much about the content.\n<pre class=\"codeinput\"><span class=\"comment\">% erase punctuation<\/span>\ncleanDocs = erasePunctuation(cleanDocs);\n<span class=\"comment\">% remove common words before analysis<\/span>\ncleanDocs = removeWords(cleanDocs,stopWords);\n<span class=\"comment\">% remove two letter words<\/span>\ncleanDocs = removeShortWords(cleanDocs,2);\n\nbag = bagOfNgrams(cleanDocs,<span class=\"string\">'NgramLengths'<\/span>,3);\nw = wordcloud(bag);\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_05.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n<h4>And which topics are the most popular?<a name=\"57e59a01-953a-42b5-b837-caceb1ee938f\"><\/a><\/h4>\nWe can sort the tweets into a set number of previously undetermined topics using the <tt><a href=\"https:\/\/www.mathworks.com\/help\/textanalytics\/ref\/fitlda.html\">fitlda<\/a><\/tt> function from the Text Analytics Toolbox. I chose eighteen as the number of topics using the perplexity metric in the LDA model. For more details, please refer to <a href=\"https:\/\/www.mathworks.com\/help\/textanalytics\/examples\/analyze-text-data-using-topic-models.html\">this example<\/a>.\n<pre class=\"codeinput\">bag2Model = bagOfWords(cleanDocs);\n\n<span class=\"comment\">% set seed for reproducibility<\/span>\nrng(123)\nnumTopics = 18;\n\nmdl = fitlda(bag2Model,numTopics,<span class=\"string\">'Verbose'<\/span>,0);\n[~,topics] = max(mdl.DocumentTopicProbabilities,[],2);\ndata.topics = topics;\n<\/pre>\nNot every tweet fits perfectly into one of eighteen well-defined topics. To help me label the topics, I removed some of the noise by excluding tweets classified with the lowest confidence.\n<pre class=\"language-matlab\">p = mdl.DocumentTopicProbabilities; maxs = max(p,[],2); cutoff =<span class=\"keyword\">...<\/span>\nquantile(maxs,.5); dataTrimmed = data(maxs&gt;=cutoff,:);\n<\/pre>\n<pre class=\"language-matlab\"><span class=\"keyword\">for<\/span> ii = 1:numTopics\n     figure <span class=\"string\">wordcloud(dataTrimmed.tweets(dataTrimmed.topics == ii))<\/span>;\n<span class=\"keyword\">end<\/span>\n<\/pre>\nFinally, let's get the average number of likes by topic so we can look at the four most and least popular topics.\n<pre class=\"codeinput\">popCats = groupsummary(data(:,{<span class=\"string\">'likesNo'<\/span>,<span class=\"string\">'topics'<\/span>}),<span class=\"string\">'topics'<\/span>,<span class=\"string\">'mean'<\/span>);\nload <span class=\"string\">topicNames.mat<\/span>\n\nbar(topicNames, popCats.mean_likesNo);\ntitle(<span class=\"string\">'Popularity by Topics'<\/span>)\nylabel(<span class=\"string\">'Number of Likes'<\/span>)\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_06.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n\nIn the word cloud below, the most popular topic looks like a collection of subjects that includes the FBI investigation and Hillary Clinton. The next three most popular topics are clearer: NFL players kneeling during the national anthem, fake news, and tweets about North Korea.\n<pre class=\"codeinput\">[~,idx] = sort(popCats.mean_likesNo,<span class=\"string\">'descend'<\/span>);\n\nrank = [<span class=\"string\">\"The\"<\/span> <span class=\"string\">\"Second\"<\/span> <span class=\"string\">\"Third\"<\/span> <span class=\"string\">\"Fourth\"<\/span>];\nnGrams = [1 2 1 2];\n<span class=\"keyword\">for<\/span> ii = 1:4\n    subplot(2,2,ii)\n    bag = bagOfNgrams(cleanDocs(data.topics == idx(ii)),<span class=\"string\">'NgramLengths'<\/span>,nGrams(ii));\n    wordcloud(bag);\n    text = rank(ii) + <span class=\"string\">\" Most Popular, N-Grams = \"<\/span> + nGrams(ii);\n    title(text)\n<span class=\"keyword\">end<\/span>\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_07.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n\nNow let's create word clouds for the four least popular topics defined by the <tt>fitlda<\/tt> function. As we see in the first word cloud below, the topic that received the fewest number of likes included tweets about something being a great honor to President Trump. Some of the \"great honors\" were to sign bills into law, meet foreign dignitaries, and visit military sites. These tweets weren't exactly controversial and didn't attract as much attention.\n\nThe second least popular topic included tweets about Hurricane Maria, which could be because people are hesitant to click \"like\" on a tragedy.\n\nInterestingly, it appears President Trump's Twitter followers weren't particularly excited about tweets on the tax overhaul, as we see in the last two word clouds. The third and fourth least popular topics were on this signature legislation, with tweets in the third least popular topic containing more partisan language (dems, republican, party...).\n<pre class=\"codeinput\">nGrams = [2 2 1 2];\n<span class=\"keyword\">for<\/span> ii = 0:3\n    subplot(2,2,ii+1)\n    bag = bagOfNgrams(cleanDocs(data.topics == idx(end-ii)),<span class=\"string\">'NgramLengths'<\/span>,nGrams(ii+1));\n    wordcloud(bag);\n    text = rank(ii+1) + <span class=\"string\">\" Least Popular with N-Grams = \"<\/span> + nGrams(ii+1);\n    title(text)\n<span class=\"keyword\">end<\/span>\n<\/pre>\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_08.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\n<h4>Do you work with text data?<a name=\"cc66bc93-87ff-4c84-b99c-e4996b42077b\"><\/a><\/h4>\nI've enjoyed watching my word clouds change daily with the speed of the news, and now, stepping back to analyze the popularity of various topics. I am wondering who else uses MATLAB to work with Twitter data. What are you investigating? What methods do you use to retrieve and analyze data?\n\nMore generally, what kinds of text data do you come across in your work or hobbies? What insight could topic modeling provide?\n\nLet us know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=2740#respond\">here<\/a>!\n<pre class=\"codeinput\"><span class=\"keyword\">function<\/span> cleanTweets = replaceHashtags(tweets)\n<span class=\"comment\">% custom function used in \"What are all the tweets about?\" to replace<\/span>\n<span class=\"comment\">% hashtags with full expressions<\/span>\n    cleanTweets = tweets;\n\n    oldFN = <span class=\"string\">\"fakenews\"<\/span>;\n    newFN = <span class=\"string\">\"fake news\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldFN,newFN);\n\n    oldHH = string({<span class=\"string\">\"hurricaneharvey\"<\/span>});\n    newHH = <span class=\"string\">\"hurricane harvey\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldHH,newHH);\n\n    oldNK = string({<span class=\"string\">\"northkorea\"<\/span> <span class=\"string\">\"noko\"<\/span>});\n    newNK = <span class=\"string\">\"north korea\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldNK,newNK);\n\n    oldTR = string({<span class=\"string\">\"taxreform\"<\/span>});\n    newTR = <span class=\"string\">\"tax reform\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldTR,newTR);\n\n    oldPR = string({<span class=\"string\">\"puerto rico\"<\/span>});\n    newPR = <span class=\"string\">\"puerto rico\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldPR,newPR);\n\n    oldPRs = string({<span class=\"string\">\"prstrong\"<\/span>});\n    newPRs = <span class=\"string\">\"puerto rico strong\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldPRs,newPRs);\n\n    oldStand = string({<span class=\"string\">\"standforouranthem\"<\/span>});\n    newStand = <span class=\"string\">\"stand for our anthem\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldStand,newStand);\n\n    oldMAGA = string({<span class=\"string\">\"maga\"<\/span>});\n    newMAGA = <span class=\"string\">\"make america great again\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldMAGA,newMAGA);\n\n    oldAF = string({<span class=\"string\">\"americafirst\"<\/span>});\n    newAF = <span class=\"string\">\"america first\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldAF,newAF);\n\n    oldTC = string({<span class=\"string\">\"taxcutsandjobsact\"<\/span>});\n    newTC = <span class=\"string\">\"tax cuts and jobs act\"<\/span>;\n    cleanTweets = replace(cleanTweets,oldTC,newTC);\n<span class=\"keyword\">end<\/span>\n<\/pre>\n<script language=\"JavaScript\"> <!-- \n    function grabCode_301a0cd8376b4a5ebf5e2527e7f097bc() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='301a0cd8376b4a5ebf5e2527e7f097bc ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 301a0cd8376b4a5ebf5e2527e7f097bc';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('<\/p>\n<p>\n<\/p>\n<p>\n<\/p>\n<p>\n<\/p>\n<pre>\\n');\n        d.write(code_string);\n\n        \/\/ Add copyright line at the bottom if specified.\n        if (copyright.length > 0) {\n            d.writeln('');\n            d.writeln('%%');\n            if (copyright.length > 0) {\n                d.writeln('% _' + copyright + '_');\n            }\n        }\n\n        d.write('<\/pre>\n<p>\n<\/p>\n<p>\n<\/p>\n<p>\n<\/p>\n<p>\\n');\n\n        d.title = title + ' (MATLAB code)';\n        d.close();\n    }   \n     --> <\/script>\nPublished with MATLAB\u00ae R2018a\n<a href=\"https:\/\/blogs.mathworks.com\/loren\/files\/trumpTweetAnalysis.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a>\n\n<\/div>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2018\/trumpTweetAnalysis_08.png\" onError=\"this.style.display ='none';\" \/><\/div>... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2018\/03\/20\/what-is-president-trump-tweeting-about-that-gets-our-attention\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,2],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/2740"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=2740"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/2740\/revisions"}],"predecessor-version":[{"id":2794,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/2740\/revisions\/2794"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=2740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=2740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=2740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}