2019 Canadian Federal Elections Sentiment Analysis

Presented by: Afeena Gafoor, Oyinlola Olaseha, Dolphyn Atitsogbi, Donald Jordy.
Asha Vale@asha.example

My neighbours moved here last year. They work, volunteer, and make this street feel like home.

Fictional postWelcoming
Martin Cole@martin.example

I'm worried immigration targets are rising faster than housing and public services can keep up.

Fictional postPolicy concern
Nia Brooks@nia.example

Black newcomers deserve the same chance to build a life here as anyone else.

Fictional postWelcoming
Ken Miles@ken.example

New immigration targets announced today. Waiting to see how the policy will work.

Fictional postNeutral
Ellen Rowe@ellen.example

I don't want Black immigrants moving into my neighbourhood.

Fictional postDiscriminatory example
Sami Noor@sami.example

We can welcome newcomers and still ask for a plan on housing. Both matter.

Fictional postMixed view
Amal Dara@amal.example

I came here for a safer future. I wish people could see us as neighbours first.

Fictional postNewcomer perspective
Caleb Reed@caleb.example

I'm tired of every immigration debate turning into an excuse to attack people.

Fictional postResponse to racism
Asha Vale@asha.example

Our newest neighbours brought food to the block party. That's the kind of community I want.

Fictional postWelcoming
Martin Cole@martin.example

Before raising immigration targets again, show us the housing and school capacity plan.

Fictional postPolicy concern
Nia Brooks@nia.example

Being new to a country doesn't make someone less deserving of respect.

Fictional postWelcoming
Ken Miles@ken.example

How long are work permit applications taking now? Looking for a clear answer.

Fictional postQuestion
Ellen Rowe@ellen.example

I think immigration levels should come down until public services catch up.

Fictional postPolicy concern
Sami Noor@sami.example

I support immigration. I also want wages, rent, and access to healthcare taken seriously.

Fictional postMixed view
Amal Dara@amal.example

My qualifications count back home. Here I'm starting over. A little patience would mean a lot.

Fictional postNewcomer perspective
Caleb Reed@caleb.example

You can disagree about immigration policy without blaming an entire group of people.

Fictional postResponse to racism

Research Methodology

5-Stage Data Pipeline & The 5 Ws

  1. STAGE 1

    Data Preparation

    • Load & flatten raw JSON data
    • Clean tweet text (URLs)
    • Standardize timestamp formats
  2. STAGE 2

    Exploratory Data Analysis

    • Audit tweet volume and missing data
    • Identify frequent keywords
    • Refine text cleaning rules
  3. STAGE 3

    Data Transformation

    • Identify columns
    • Filter migration-related tweets
    • Classify actor categories and bot labels
    • Create temporal intervals
    • Extract & standardize user location
  4. STAGE 4

    Content, Sentiment & Network Analysis

    • Generate themes (core topics)
    • Conduct tweet-level sentiment analysis
    • Identify sentiment across themes
    • Determine retweet amplification
  5. STAGE 5

    Visualizations

    • Plot temporal tweet and sentiment trends
    • Plot overall immigration theme
    • Plot location of immigration related tweets
    • Plot sentiment across theme, Retweet amplification across themes

THE 5 Ws ANALYTICAL FRAMEWORK ACROSS THE PIPELINE

WHO
Actors & Bot Labels (Stages 3–4)
WHAT
Keywords & Migration Tweets (Stages 2–4)
WHEN
Temporal Intervals (Stage 3)
WHERE
User Locations (Stage 3)
WHY
Themes & Sentiment (Stage 4)

Content Analysis

Data transformation charts

Lexical Dispersion of Key Terms in 2019 Canadian Election Tweets

  • Each blue mark shows the occurrence of a text. The horizontal axis shows where it appears in the text.
  • Immigration, refugees, border and immigrants appear throughout the tweet collection.
  • As you can see, from the top words immigration related are popular
Lexical dispersion of the ten most frequent words across the cleaned tweet-token sequence.

Data transformation charts

Election Tweets by User-Reported Location

  • Ontario ranked first with 1,320 tweets, representing 55.56% of mapped tweets.
  • Darker shades indicate higher tweet counts. Locations come from users’ profiles.
  • The map excludes 1,238 tweets with no profile location and 1,201 with locations that could not be matched.

Total Tweets by User-Reported Location

Canada · 2019 election dataset
Tweet records
01–2526–7576–299300–699700+

Immigration- Related and Other Tweets by Time of the Day

  • The blue line shows immigration-related tweets. The orange line shows other election tweets.
  • In the dataset, immigration-related tweets outnumbered other election tweets in every three-hour period.
  • Both categories peaked from 9:00 to 11:59 a.m. Eastern Time, with 717 immigration-related tweets and 207 other election tweets.
Tweet records · n = 4,815

Data transformation charts

Bot-Like Behaviour in Immigration-Related Election Tweets by Actor Category

  • 807 of 3,711 representing 21.7% tweets were flagged for bot-like behaviour.
  • Unclassified accounts had the highest number of flagged tweets (456).
  • Political parties and politicians had the highest flagged share (26.9% within that category).
Tweet events · n = 3,711
Tweet events, value by category
CategoryBot-like flag: NoBot-like flag: YesTotal
Unclassified1,6624562,118
Political Party / Politician664244908
Journalist / Media41485499
Civil Society / Advocate16022182
Government Agency404

Data transformation charts

Share of Immigration-Related Tweets in the Election Dataset

  • 3,711 tweets representing 77.1% matched at least one immigration related keyword in the dataset.
  • 1,104 tweets representing 22.9% did not match any of the immigration related keywords in the dataset.
  • The 3,711 tweets matching tweets formed the basis for our sentiment analysis
retained tweets

Sentiment Analysis

What We Are Here to Answer

  • What was the overall sentiment of immigration-related tweets during the election?
  • How did sentiment vary across immigration themes?
  • How did the meanings of negative tweets differ from week to week?

Q1: Overall Sentiment of Immigration-Related Tweets During the 2019 Canadian Federal Election

A total of 3,711 unique tweet records were analysed.

  • Negative sentiment: 45.35% (1,683 tweets).
  • Positive sentiment: 36.30% (1,347 tweets).
  • Neutral sentiment: 18.35% (681 tweets).

Negative sentiment was the most common in immigration-related discussions during the election.

Tweet events · n = 3,711

Q2: Sentiment Distribution Across Immigration Themes

  • Political rhetoric and refugee rights were the most discussed themes.
  • Border security recorded the highest negative sentiment (62.4%).
  • Economic impact and employment recorded the highest positive sentiment (61.3%).
  • Multiculturalism also received mostly positive sentiment (58.1%).

People's reactions to immigration varied depending on the topic being discussed.

Theme assignments

2019 Canadian Federal Election

NegativePositiveNeutral
Political Rhetoric & Election Discourse
n=1,642
Humanitarian Issues & Refugee Rights
n=1,305
Government Policy & Immigration Administration
n=211
Citizenship, Identity & Multiculturalism
n=160
Economic Impact & Employment
n=124
Border Security & National Security
n=101
Public Opinion & Social Debate
n=20

Percentage of Theme Assignments (%)

Note: n represents the number of theme assignments. Some tweets may belong to more than one theme.

Q3: Different Meanings of Negative Tweets by Week

Of the 25 manually reviewed negative tweets:

  • 36% supported immigrants or refugees.
  • 28% focused on political criticism or other discussions.
  • 24% raised immigration concerns.
  • 12% were mixed or unclear.

Limitation: The small sample cannot represent all negative tweets. Negative sentiment does not necessarily mean opposition to immigration.

Reviewed messages · n = 25

Qualitative Category

Supporting immigrants or refugeesPolitical criticism or other discussionConcerned about immigrationMixed or unclear
Different Meanings of Negative Tweets by Week25 manually coded negative tweets, grouped by week starting September 09, 16, 23 and 30, 2019.Number of Tweetsn=10Sep 09n=9Sep 16n=4Sep 23n=2Sep 30Week Starting

Note: Based on 25 manually coded negative tweets.

Network Data Analysis

Network Data Analysis

Who retweeted whom?

1,315retweet events
1,278accounts
1,283directed pairs
RETWEETERSORIGINAL AUTHORS@maritstiles#1 · 236 retweet events@sunlorrie#2 · 219 retweet events@macleans@cdnpoli_memes@QuigginReport@TheTorontoSun@ctvqp@SebBovetSRC@WhatAboutMadMax@MigrantRightsCA
43 accounts · 33 selected linksArrows point to original authors. Counts in the panel use the full network.

Network analysis

Amplification Diagram

Original circular amplification diagram from the final notebook, with 43 accounts and 33 selected directed retweet links. Arrows point from retweeters to original authors.

The original circular retweet diagram: 43 accounts and 33 selected links.

Arrows point to original authors. Rankings use the full 1,278-account network.

Who Got Amplified?

Incoming events and distinct retweeters

Top Ten Original Authors

Incoming retweets / accounts
Retweet eventsDistinct retweeters
01@maritstiles
236236
02@sunlorrie
219211
03@macleans
7070
04@cdnpoli_memes
6161
05@QuigginReport
4141
06@TheTorontoSun
4038
07@ctvqp
3939
08@SebBovetSRC
3737
09@WhatAboutMadMax
3433
10@MigrantRightsCA
3432
0236 incoming events / distinct accounts
Ranked by retweet events received
Full-network rankings. The animation sorts the final totals; both measures start at zero.

Two Authors Received
455 Retweets.

included retweets
@maritstiles236@sunlorrie219
455 of 1,315 included retweets. Other authors: 860 events.
Original authorRetweet events receivedDistinct retweeters
@maritstiles
236
236
@sunlorrie
219
211
@macleans
70
70
@cdnpoli_memes
61
61
@QuigginReport
41
41
@TheTorontoSun
40
38
@ctvqp
39
39
@SebBovetSRC
37
37
@WhatAboutMadMax
34
33
@MigrantRightsCA
34
32

Amplification & Sentiment

3,711 Tweet Events

Overall VADER language labels

Tweet events · n = 3,711
Tweet events, share by category
CategoryNegativePositiveNeutralTotal
All events1,6831,3476813,711
Retweets contribute separate events to these totals.

25 Negative Messages Reviewed

One cell = one reviewed message

Manual Interpretation
VADER-negative sample, 25 reviewed messages
  • Support for immigrants / refugees36%
  • Political criticism / other28%
  • Immigration concerns24%
  • Mixed / unclear12%

Negative language does not establish opposition. A retweet does not establish agreement.

Conclusion

Language

Tweet events · n = 3,711
Negative was the largest category.3,711 tweet events, including retweets.

Topics

Theme assignments
Theme assignments, share by category
CategoryNegativePositiveNeutralTotal
Border Security & National Security632414101
Economic Impact & Employment387610124
Sentiment differed by theme.Tweets can belong to several themes.

Circulation

included retweets
455 retweets went to two authors.1,315 included retweets.

Thank You

Thank you for listening Questions are welcome

Open for discussion

Questions about the data, methods or findings are welcome.

With thanks,

The team

Discussion

Questions?

Reference for Q&A

Appendix

Important transformations.
Open a step for its rules and counting choices.

  1. 4,966loaded records
  2. 4,815with tweet text
  3. 3,711keyword matches
  4. 1,315included retweets
01Text preparationKeep text. Decode entities. Remove RT headers.

Flatten the JSON with pd.json_normalize. Drop 151 rows where full_text is null, leaving 4,815 records.

Create full_text_Clean by decoding HTML entities and removing the RT @username: header. Retweet events remain in the data.

Stop words and non-alphabetic tokens are removed in a separate column for word frequency and lexical dispersion. VADER uses full_text_Clean, retaining punctuation and stop words.

Notebook cells 2–4, 7–8

02Immigration selectionAt least one English keyword → Yes.

Search the original full_text using a case-insensitive English keyword list. Escape the terms, check longer phrases first and use word boundaries to avoid matches inside longer words.

3,711 records match at least one term; 1,104 match none. Examples include immigration, refugee, work permit and citizenship.

The flag identifies keyword matches. It can miss relevant posts without those terms and does not establish a person's position on immigration.

Notebook cell 11 · Immigration flag check export

03Time & locationUTC → Toronto time. Profile text → region.

Parse created_at as UTC, then convert to America/Toronto. Extract dates, weekdays and hours; group times into eight three-hour windows. Unparseable timestamps become missing values.

Lowercase user.location and match province names, selected cities and abbreviations. For example, Toronto maps to Ontario.

Keep missing or blank locations as No User Location Provided; keep nonblank unmatched locations as Unknown. These are profile descriptions, not verified posting locations.

Notebook cells 10, 12 · Province identification check export

04Account rulesProfile keywords + lifetime posting rate.

Match the account name and biography in this order: government, media, political, civil society. The first matching category wins; unmatched accounts remain Unclassified.

Estimate posts per day as lifetime user.statuses_count divided by account age at the tweet date. Zero or negative account ages become missing.

Flag bot-like behaviour above 50 posts/day, or above 25 with a default image, default profile or empty biography. A missing rate is Not assessed.

These rules provide provisional categories and flags. They do not verify identity or automation.

Notebook cell 20

05Sentiment & themesOne score per tweet ID. Several themes possible.

Score full_text_Clean once per distinct immigration tweet id_str. VADER compound scores ≥ 0.05 are positive, ≤ −0.05 negative; values between them are neutral.

Match seven theme dictionaries, counting each theme once per tweet. Expand the matched list into one row per tweet–theme pair; keep unmatched tweets as Unclassified.

3,711 scored events become 4,691 tweet–theme rows, including Unclassified. Theme totals can exceed event totals. Retweeted copies have their own tweet IDs and contribute separate events.

A negative language score does not establish opposition to immigration.

Notebook cells 22–23, 32–33 · Event and theme sentiment exports

06Retweet networkRetweeter → original author. Repetition → weight.

Use structured posting and original-author handles. Keep one row per tweet ID: 1,325 events have both endpoints. Exclude 10 self-retweets, leaving 1,315 included events.

Group retweeter–author pairs; each pair's event count is its edge weight. This gives 1,283 directed pairs across 1,278 accounts. Incoming events and distinct retweeters are counted separately.

10 RT-prefixed records lack a structured original author and cannot supply an edge. The diagram shows 43 accounts and 33 selected links; rankings use the full network.

Retweets record repetition. They do not establish agreement, audience reach or a causal effect on sentiment.

Notebook cells 59–69 · Network selection checks and edge exports

Rules from the project notebook.