Skip to content
naulon

No retraction, correction or concern found when last checked on Oct 23, 2026.

Twitter Discussions and Emotions About the COVID-19 Pandemic: Machine Learning Approach

Jia Xue, Junxiang Chen, Ran Hu and 4 more

Journal of Medical Internet Research · 2020

doi:10.2196/20550

Abstract

Background. It is important to measure the public response to the COVID-19 pandemic. Twitter is an important data source for infodemiology studies involving public response monitoring.

Objective. The objective of this study is to examine COVID-19–related discussions, concerns, and sentiments using tweets posted by Twitter users.

Methods. We analyzed 4 million Twitter messages related to the COVID-19 pandemic using a list of 20 hashtags (eg, “coronavirus,” “COVID-19,” “quarantine”) from March 7 to April 21, 2020. We used a machine learning approach, Latent Dirichlet Allocation (LDA), to identify popular unigrams and bigrams, salient topics and themes, and sentiments in the collected tweets.

Results. Popular unigrams included “virus,” “lockdown,” and “quarantine.” Popular bigrams included “COVID-19,” “stay home,” “corona virus,” “social distancing,” and “new cases.” We identified 13 discussion topics and categorized them into 5 different themes: (1) public health measures to slow the spread of COVID-19, (2) social stigma associated with COVID-19, (3) COVID-19 news, cases, and deaths, (4) COVID-19 in the United States, and (5) COVID-19 in the rest of the world. Across all identified topics, the dominant sentiments for the spread of COVID-19 were anticipation that measures can be taken, followed by mixed feelings of trust, anger, and fear related to different topics. The public tweets revealed a significant feeling of fear when people discussed new COVID-19 cases and deaths compared to other topics.

Conclusions. This study showed that Twitter data and machine learning approaches can be leveraged for an infodemiology study, enabling research into evolving public discussions and sentiments during the COVID-19 pandemic. As the situation rapidly evolves, several topics are consistently dominant on Twitter, such as confirmed cases and death rates, preventive measures, health authorities and government policies, COVID-19 stigma, and negative psychological reactions (eg, fear). Real-time monitoring and assessment of Twitter discussions and concerns could provide useful data for public health emergency responses and planning. Pandemic-related fear, stigma, and mental health concerns are already evident and may continue to influence public trust when a second wave of COVID-19 occurs or there is a new surge of the current pandemic.

Full text

From PubMed Central, U.S. National Library of Medicine, as current on Oct 23, 2026. Paragraph numbers are ours, so an answer can point at one.

Introduction

Thirty million cases of COVID-19 have been confirmed across 110 countries as of mid-September 2020, and the death toll has reached close to 947,000. The widespread use of social media, such as Twitter, accelerates the process of exchanging information and expressing opinions about public events and health crises. COVID-19 has been one of the trending topics on Twitter since January 2020 and has continued to be discussed to date. Since quarantine measures have been implemented across most countries (eg, the shelter-in-place order in the United States), people have been increasingly relying on different social media platforms to receive news and express opinions. Twitter data are valuable for revealing public discussions and sentiments related to various topics, as well as real-time news updates during global pandemics, such as H1N1 and Ebola. Chew and Eysenbach’s study showed that Twitter could be used for real-time “infodemiology” studies, providing a source of opinions for health authorities to respond to public concerns. During the COVID-19 pandemic, many government officials worldwide have used Twitter as one of their main communication channels to regularly share policy updates and news related to COVID-19 to the general public.

Since the COVID-19 outbreak, a growing number of studies have collected Twitter data to understand the public responses to and discussions around COVID-19. For instance, Abd-Alrazaq and colleagues adopted topic modeling and sentiment analysis to determine the main discussion themes and sentiments around COVID-19, using tweets collected between February 2 and March 15, 2020. Budhwani and Sun compared Twitter discussions before and after March 16, 2020, when President Trump tweeted about the “Chinese virus,” and found a significantly increased use of the phrase “Chinese virus” in people’s tweets across many US states afterward. Mackey and colleagues analyzed about 3465 tweets collected between March 2 and 20, 2020, using a topic model to explore users’ self-reported experiences with COVID-19 and related symptoms. Ahmed and colleagues conducted social network analysis and content analysis of collected tweets between March 27 and April 4, 2020, to understand what may have driven the misinformation that linked 5G towers in the United Kingdom to the COVID-19 pandemic. As conversations on Twitter continue to take place and evolve, it is worth continuing to use tweets as a source of data to track and understand the salient topics discussed on Twitter in response to the COVID-19 pandemic and track their changes across time.

To expand the literature on public reactions to the COVID-19 pandemic, this study aims to examine the public discourse and emotions related to the COVID-19 pandemic by analyzing more than 4 million tweets collected between March 7 and April 21, 2020.

Research Design

We used a purposive sampling approach to collect COVID-19–related tweets published between March 7 and April 21, 2020. Our Twitter data mining approach followed the pipeline displayed in Figure 1. Data preparation included the following three steps: (1) sampling, (2) data collection, and (3) preprocessing the raw data. The data analysis stage included unsupervised machine learning, sentiment analysis, and thematic qualitative analysis. The unit of analysis was each message-level tweet. Unsupervised learning is one approach in machine learning; it is used to examine data for patterns, and derives a probabilistic clustering based on text data. We chose unsupervised learning because it is commonly used when existing studies have few observations of or insights into unstructured text data. Since a qualitative approach would be challenging when analyzing large-scale Twitter data, unsupervised learning allows us to conduct exploratory analyses of large text data for social science research. In this study, we first employed an unsupervised machine learning approach to identify salient latent topics. We used a thematic analysis approach to develop themes further, allowing a deeper dive into the data, such as through manual coding and inductively developing themes based on the latent topics generated by machine learning algorithms.

Sampling and Data Collection

We used a list of COVID-19–related hashtags as search terms to fetch tweets (eg, #coronavirus, #2019nCoV, #COVID19, #coronaoutbreak, and #quarantine; Multimedia Appendix 1). Twitter’s open application programming interface (API) allowed us to collect updated Twitter messages set to open by default. From March 7 to April 21, 2020, we collected 35,204,604 tweets during this period (Figure 2). After removing non-English tweets, 23,817,948 tweets remained. After removing duplicates and retweets (ie, tweets that only repost the original message without adding any more words), we had 4,196,020 tweets in our final data set. We collected and downloaded the following features for each tweet: (1) the full text, (2) the numbers of favorites, followers, and followings, (3) users’ geolocation, and (4) users' description/self-created profile.

Preprocessing the Raw Data

We used Python to clean the raw data (Figure 1). The process was as follows:

We removed the hashtag symbol, @users, and URLs from the tweets in the data set.

We removed non-English characters (non-ASCII characters) because this study focused on tweets in English.

We removed special characters, punctuation, and stop-words from the data set as they do not contribute to the semantic meanings of messages.

Unsupervised Machine Learning

Latent Dirichlet Allocation (LDA) is a widely used unsupervised machine learning approach that allows researchers to analyze unstructured text data (eg, Twitter messages). Based on the data itself, the algorithm produces frequently mentioned pairs of words, the pairs of words that co-occur together, and latent topics and their distributions over topics in the document. Existing studies have indicated the feasibility of using LDA to identify the patterns and themes of tweets related to COVID-19.

Qualitative Analysis

To triangulate and contextualize findings from the LDA model, we employed a qualitative approach to develop themes further. Specifically, we used Braun and Clarke's six steps of thematic analysis: (1) getting familiar with the keyword data, (2) generating initial codes, (3) searching for themes, (4) reviewing potential themes, (5) defining themes, and (6) reporting. In addition to following the six-phase approach, our process was iterative and reflective by moving backward and forward through the six phases. The thematic approach relied on human interpretation, a process that can be significantly influenced by personal understanding of the topics and a variety of biases. Two team members who have experience analyzing Twitter data documented their thoughts about potential codes in NVivo independently. Two other team members then reviewed the initial codes and considered whether they reflected the identified topics. For example, two team members collapsed several similar codes into one theme to ensure the topics corresponded meaningfully under one theme. The next stage was naming the themes to ensure the themes fitted into the overall meanings of the identified salient topics. We finalized themes corresponding to each of the 13 topics.

Sentiment Analysis

We used sentiment analysis, a natural language processing (NLP) approach, to classify the main sentiments of a given twitter message, such as fear and joy. In this study, we used the NRC Emotion Lexicon, which consists of 8 primary emotions: anger, anticipation, fear, surprise, sadness, joy, disgust, and trust. We followed 4 steps to calculate the emotion index for each Twitter message: (1) removed articles and pronouns (eg, “and,” “the,” “to”), (2) applied a stemmer by removing the predefined list of prefixes and suffixes (eg, “running” becomes “run” after stemming), and (3) calculated the emotion index (if a sentence had multiple emotions, we only kept the emotion with the highest matching count), and (4) calculated the scores for each 8-emotion type. We discussed these 4 steps in detail in a previous study.

Descriptive Results

In total, after preprocessing all raw data, our final data set included 4,196,020 tweets. We identified the most popular tweeted bigrams (pairs of words) related to COVID-19. Bigrams captured “two concessive words regardless of the grammar structure and semantic meaning and may not be self-explanatory”. Bigrams identified included the following: “covid 19,” “stay home,” “social distancing,” “new cases,” “don't know,” “confirmed cases,” “home order,” “New York,” “tested positive,” “death toll,” and “stay safe.” Popular unigrams included “virus,” “lockdown,” “quarantine,” “people,” “new,” “home,” “like,” “stay,” “don't,” and “cases.” We presented the most popular unigrams and bigrams related to COVID-19 in Table 1 and visualized them using word clouds in Figures 3 and 4.

COVID-19–Related Topics

Our approach, LDA, produced frequently co-occurring pairs of words related to COVID-19 and organized these co-occurring words into different topics. LDA allowed us to manually define the number of topics (eg, 10 topics, 20 topics) that we would like to generate. Consistent with previous studies, we used the coherence model, Gensim (RARE Technologies Ltd), to calculate the most appropriate number of topics based on the data itself. For this data set, the LDA indicated that having 13 topics would give a high coherence score and the smallest topic number (eg, while having 19 or 20 topics would give a higher coherence score, they involve more topics; Figure 5).

We further analyzed the document-term matrix and obtained the distributions of 13 topics. We presented the results of 13 salient topics and the most popular pairs of words (bigrams) within each topic in Table 2. For example, Topic 3 had the highest distribution (8.87%) among all 13 common latent topics. The bigrams associated with Topic 3 included “tested positive,” “coronavirus outbreak,” “New York,” “shelter place,” and “mental health.” These pairs of words frequently co-occurred together, and therefore the LDA model assigned them to the same topic.

COVID-19–Related Themes

The thematic analysis enabled us to categorize these topics into different distinct themes. The team considered the identified topics, bigrams, and representative tweet samples in each topic and categorized them into different themes. To protect the privacy and anonymity of the Twitter users, we did not present any user-related information, such as users’ Twitter handles or other identifying information. Therefore, sample tweets were excerpts drawn from original tweets in Table 3.

We organized 13 topics into 5 themes: “Public health measures to slow the spread of COVID-19” (eg, face masks, test kits, vaccine), “Social stigma associated with COVID-19” (eg, Chinese virus, Wuhan virus), “Coronavirus news cases and deaths” (eg, new cases, deaths), “COVID-19 in the United States” (eg, New York, protests, task force), and “Coronavirus cases in the rest of the world” (eg, UK, global issue). For example, the theme “public health measures to slow the spread of COVID-19” included the relevant topics of “facemasks,” “quarantine,” “test kits,” “lockdown,” “safety,” “vaccine,” and “shelter-in-place.” In addition, “home quarantine” and “self-quarantine” were two of the most commonly co-occurred words under the topic quarantine.

Sentiment Analysis

We presented the results of the sentiment analysis for each of the 13 latent topics in Figure 6 and Table 4. Figure 6 presented 8 emotions of trust, anticipation, joy, surprise, anger, fear, disgust, and sadness. Results showed that across all 13 topics, anticipation (dark blue line) dominated 12 topics, followed by fear (orange line), trust (grey line), and anger (yellow line).

We also ran a one-tailed z test to examine if each of the 8 emotions is statistically significantly different across topics. A P value <.01 was set as the threshold for significance. For example, about 23.8% of tweets in Topic 5 revealed feelings of anticipation that “necessary steps and precautions will be taken”. Statistical significance indicated that it was very likely (P<.001) that the anticipation emotion is more prevalently expressed in Topic 5 (23.8%) than all other topics. The emotion fear (of the impacts of the virus) was found in 18.8% of the tweets in Topic 10, which was statistically different from the fear expressed in other topics.

Principal Results

In this study, we addressed public discussions and emotions using COVID-19–related messages on Twitter. Twitter users discussed 5 main themes related to COVID-19 between March 7 and April 21, 2020. Topic modeling of the tweets was useful for providing insights about COVID-19 topics and concerns. Results showed several essential points. First, the public uses a variety of terms when referring to COVID-19, including virus, COVID-19, coronavirus, and corona virus. Second, COVID-19 has been referred to as the “China virus,” which can create stigma and harm efforts to address the COVID-19 outbreak. Third, discussions about the pandemic in New York were salient, and its associated public sentiment was anger. Fourth, public discussions about the Chinese Communist Party (CCP) and the spread of the virus emerged as a new topic that was not identified in previous studies, suggesting the connection between COVID-19 and politics is increasingly circulating on Twitter as the situation evolves. Fifth, public sentiments on the spread of COVID-19 reveal anticipation for the potential measures that can be taken, followed by mixed feelings of trust, anger, and fear. Results suggest that the public is not surprised by the rapid spread of COVID-19. Sixth, people have a significant feeling of fear when they discuss the COVID-19 crisis and deaths. Lastly, trust is no longer a prominent emotion when Twitter users discuss COVID-19, which is different from the findings of an earlier study.

Comparison With Prior Work

Our findings are consistent with previous studies using social media data to assess the public health responses and sentiments related to COVID-19, and suggest that public attention has been focusing on the following topics since January 2020: (1) the confirmed cases and death rates, (2) preventive measures, (3) health authorities and government policies, (4) an outbreak in New York, (5) COVID-19 stigma (eg, referring to COVID-19 as the “Chinese virus”), and (6) negative psychological reactions (eg, fear) or mental health consequences.

Compared with a study examining public discussions and concerns related to COVID-19 using Twitter data from January 20 to March 7, 2020, we found that several salient topics are no longer popular: (1) an outbreak in South Korea, (2) the Diamond Princess cruise ship, (3) the economic impact, and (4) supply chains. Given current preventive measures, washing hands is no longer a prevalent topic; instead, quarantine has become dominant.

In addition, our study identified new discussion topics about COVID-19 occurring between March 7 to April 21: (1) the need for a vaccine to stop the spread, (2) quarantine and shelter-in-place orders, (3) protests against the lockdown, and (4) the COVID-19 pandemic in the United States. The new salient topics suggest that Twitter users (tweeting in English) are focusing their attention on COVID-19 in the United States (eg, New York, protests, task force, millions of confirmed cases) rather than global news (eg, South Korea, Diamond Princess cruise ship, Dr Li Wenliang in China).

Limitations

First, we only sampled 20 hashtags as the key search terms to collect Twitter data (Multimedia Appendix 1). New hashtags keep coming up as the situation evolves. For example, a hashtag may become widely used after a related topic becomes more popular, such as the official name for the virus (COVID-19). Second, Twitter users are not representative of the whole global population, and topics of tweets only indicate online users' opinions about and reactions to COVID-19. However, the Twitter data set is still a valuable resource, allowing us to examine real-time Twitter users’ responses and online activities related to COVID-19. Third, non-English tweets were removed from our analyses, and hence the results are limited to users who posted in English only. Future COVID-19 studies should include other languages, such as Italian, French, German, and Spanish.

Future Research

Future research could further explore public trust and confidence in existing measures and policies, which are essential. Compared to prior work, our study showed that Twitter users had a feeling of joy when talking about herd immunity. Sentiments of fear and anticipation related to the topics of quarantine and shelter-in-place. Future studies could evaluate how government officials (eg, President Trump) and international organizations (eg, World Health Organization) deliver and convey messages to the public, and the subsequent impact on public opinions and sentiments. Anti-Chinese/Asian sentiments spread on social media, and it would be worth assessing how people use these platforms to resist and challenge COVID-19 stigma. Misinformation during the COVID-19 pandemic was not a prominent theme in this study. An existing study showed that 25% (n=153) of sampled tweets contained misinformation. The term COVID-19 has lower rates of misinformation associated with it than that associated with #2019_ncov and Corona. Future research should investigate misinformation and how it expands on social media. Finally, trust is no longer prominent when people tweet about confirmed cases and deaths. Instead, fear has replaced trust to be the dominant emotion. Future research should examine the changes in trust over time.

Conclusions

Twitter data and machine learning approaches can be leveraged for infodemiology studies by studying evolving public discussions and sentiments during the COVID-19 pandemic. Our findings facilitate an understanding of public discussions and concerns about the COVID-19 pandemic among Twitter users between March 7 and April 21, 2020. Several topics were consistently dominant on Twitter, such as “the confirmed cases and death rates,” “preventive measures,” “health authorities and government policies,” “stigma,” and “negative psychological reactions” (eg, fear). As the situation rapidly evolves, new salient topics emerge accordingly. Fear arises in messages of new cases or death reports. Real-time monitoring and assessment of Twitter users’ concerns can be promising for informing public health emergency responses and planning. Hearing and reacting to real concerns from the public can enhance trust between the health care system and the public and enable better preparation for a future public health emergency.

References 34

  1. 1.

    Center for Systems Science and Engineering (CSSE). COVID-19 Dashboard by CSSE at Johns Hopkins University (JHU).

    Not in our library

  2. 2.
  3. 3.

    Scanfeld D, Scanfeld V, Larson EL. Dissemination of health information through social networks: twitter and antibiotics. Am J Infect Control. 2010;38(3):182-8.

    Not in our library10.1016/j.ajic.2009.11.004

  4. 4.

    Xue J, Chen J, Chen C, Hu R, Zhu T. The Hidden Pandemic of Family Violence During COVID-19: Unsupervised Learning of Tweets. J Med Internet Res. 2020;22(11):e24361-53.

    Not in our library10.2196/24361

  5. 5.

    Cheong M, Lee VCS. A microblogging-based approach to terrorism informatics: Exploration and chronicling civilian sentiment and response to terrorism events via Twitter. Inf Syst Front. 2010;13(1):45-59.

    Not in our library10.1007/s10796-010-9273-x

  6. 6.
  7. 7.
  8. 8.

    Kim Y, Kim JH. Using photos for public health communication: A computational analysis of the Centers for Disease Control and Prevention Instagram photos and public responses. Health Informatics J. 2020;26(3):2159-2180.

    Not in our library10.1177/1460458219896673

  9. 9.
  10. 10.

    Rufai S, Bunce C. World leaders' usage of Twitter in response to the COVID-19 pandemic: a content analysis. J Public Health (Oxf). 2020;42(3):510-516.

    Not in our library10.1093/pubmed/fdaa049

  11. 11.
  12. 12.
  13. 13.

    Alvarez-Risco A, Mejia C, Delgado-Zegarra J, Del-Aguila-Arcentales S, Arce-Esquivel A, Valladares-Garrido M, Rosas Del Portal M, Villegas LF, Curioso WH, Sekar MC, Yáñez JA. The Peru Approach against the COVID-19 Infodemic: Insights and Strategies. Am J Trop Med Hyg. 2020;103(2):583-586.

    Not in our library10.4269/ajtmh.20-0536

  14. 14.

    Budhwani H, Sun R. Creating COVID-19 Stigma by Referencing the Novel Coronavirus as the. J Med Internet Res. 2020;22(5):e19301.

    Not in our library10.2196/19301

  15. 15.
  16. 16.

    Mackey T, Purushothaman V, Li J, Shah N, Nali M, Bardier C, Liang B, Cai M, Cuomo R. Machine Learning to Detect Self-Reporting of Symptoms, Testing Access, and Recovery Associated With COVID-19 on Twitter: Retrospective Big Data Infoveillance Study. JMIR Public Health Surveill. 2020;6(2):e19509.

    Not in our library10.2196/19509

  17. 17.

    Xiang X, Lu X, Halavanau A, Xue J, Sun Y, Lai P, Wu Z. Modern Senicide in the Face of a Pandemic: An Examination of Public Discourse and Sentiment about Older Adults and COVID-19 Using Machine Learning. J Gerontol B Psychol Sci Soc Sci. 2020;A.

    Not in our library10.1093/geronb/gbaa128

  18. 18.

    Xue J, Chen J, Chen C, Zheng C, Li S, Zhu T. Public discourse and sentiment during the COVID 19 pandemic: Using Latent Dirichlet Allocation for topic modeling on Twitter. PLoS One. 2020;15(9):e0239441.

    Not in our library10.1371/journal.pone.0239441

  19. 19.

    James G, Witten D, Hastie T, Tibshirani R. An Introduction to Statistical Learning. 2013.

    Not in our library

  20. 20.

    Blei D, Ng A, Jordan M. Latent Dirichlet Allocation. Journal of Machine Learning Research March. 2003;3:993-1022.

    Not in our library

  21. 21.

    Xue J, Chen J, Gelles R. Using Data Mining Techniques to Examine Domestic Violence Topics on Twitter. Violence and Gender. 2019;6(2):105-114.

    Not in our library10.1089/vio.2017.0066

  22. 22.
  23. 23.

    Braun V, Clarke V. Using thematic analysis in psychology. Qualitative Research in Psychology. 2006;3(2):77-101.

    Not in our library10.1191/1478088706qp063oa

  24. 24.

    Nowell LS, Norris JM, White DE, Moules NJ. Thematic Analysis. International Journal of Qualitative Methods. 2017;16(1):1.

    Not in our library10.1177/1609406917733847

  25. 25.

    Beigi G, Hu X, Maciejewski R, Liu H, Pedrycz W, Chen SM. An overview of sentiment analysis in social mediaits applications in disaster relief. Studies in Computational Intelligence. 2016;313-340.

    Not in our library

  26. 26.

    Mohammad S, Turney P. NRC emotion lexicon. National Research Council Canada. 2013.

    Not in our library

  27. 27.

    Manning C, Raghavan P, Schütze H. Introduction to Information Retrieval. 2008.

    Not in our library

  28. 28.

    Michael R, Andreas B, Alexander H. Exploring the space of topic coherence measures. 2015;399-408.

    Not in our library10.1145/2684822.2685324

  29. 29.

    Kaila RP, Prasad AVK. Informational flow on Twitter - corona virus outbreak - topic modelling approach. International Journal of Advanced Research in Engineering and Technology. 2020;11(3):128-134.

    Not in our library

  30. 30.

    Stokes DC, Andy A, Guntuku SC, Ungar LH, Merchant RM. Public Priorities and Concerns Regarding COVID-19 in an Online Discussion Forum: Longitudinal Topic Modeling. J Gen Intern Med. 2020;35(7):2244-2247.

    Not in our library10.1007/s11606-020-05889-w

  31. 31.

    Nobles J, Martin F, Dawson S, Moran P, Savovic J. The potential impact of COVID-19 on mental health outcomes and the implications for service solutions. 2020.

    Not in our library

  32. 32.
  33. 33.

    Su Y, Xue J, Liu X, Wu P, Chen J, Chen C, Liu T, Gong W, Zhu T. Examining the Impact of COVID-19 Lockdown in Wuhan and Lombardy: A Psycholinguistic Analysis on Weibo and Twitter. Int J Environ Res Public Health. 2020;17(12):4552.

    Not in our library10.3390/ijerph17124552

  34. 34.

    Medford R, Saleh S, Sumarsono A, Perl T, Lehmann C. An. Open Forum Infect Dis. 2020;7(7):ofaa258.

    Not in our library10.1093/ofid/ofaa258

Cited by papers we hold 1

Reads

Read by people on this page

None yet.

Checked or read by AI through naulon

None yet.

A person counts once a day per paper. We keep no cookie and no address: a reader is a hash that changes every day. Any month under five reads shows no number.

Are you an author?

Is this your paper?

Claim it to add your note and be paid when agents cite it. Free.