This analysis adapts the multi-scrape Bluesky text and sentiment workflow to Nike social media data and connects those findings with primary Qualtrics survey data (\(n = 20\) responses).
#1
Combining & deduplicating weekly scrapes across Nike_Social media Analysis complete (3).xlsx, Scrape2.csv.xlsx, and social_media_analysis (1)-1 (1)-1 (1).xlsx
#2
Text cleaning & filtering (removing links, mentions, hashtags, non-English posts, spam/promo bots, and duplicate posts)
#3
Word frequency, TF-IDF, and bigrams across scrape batches
#4
Multi-lexicon sentiment analysis (Bing, AFINN, and NRC emotions) and lexicon agreement
#5
Sentiment vs. engagement (Spearman rank correlation and interactive Plotly scatter plot)
#7
Qualtrics survey analysis testing whether social media engagement and ad attention relate to Nike purchase intention
pkgs <- c("tidyverse", "readxl", "tidytext", "plotly", "scales", "knitr")
missing_pkgs <- pkgs[!pkgs %in% rownames(installed.packages())]
if (length(missing_pkgs) > 0) install.packages(missing_pkgs, repos = "[https://cloud.r-project.org](https://cloud.r-project.org)")
library(tidyverse)
library(readxl)
library(tidytext)
library(plotly)
library(scales)
library(knitr)
# Load Bing, AFINN-111, and NRC v0.92 lexicons without interactive prompts
dir.create("lexicons", showWarnings = FALSE)
get_lex <- function(url, file) {
path <- file.path("lexicons", file)
if (!file.exists(path)) download.file(url, path, quiet = TRUE)
path
}
afinn <- read_tsv(
get_lex("https://raw.githubusercontent.com/fnielsen/afinn/master/afinn/data/AFINN-111.txt", "AFINN-111.txt"),
col_names = c("word", "value"), col_types = "cd", quote = ""
)
nrc <- read_tsv(
get_lex("https://raw.githubusercontent.com/dinbav/LeXmo/master/NRC-Emotion-Lexicon-Wordlevel-v0.92.txt", "NRC-v0.92.txt"),
col_names = c("word", "sentiment", "flag"),
col_types = "ccd"
) %>%
filter(flag == 1) %>%
select(word, sentiment)
bing <- get_sentiments("bing")
s2_raw <- read_excel("Scrape2.csv (1).xlsx", sheet = "Scrape 2") %>%
transmute(
batch = "Batch 2 (BlueFacts Scrape)",
author_handle = str_remove(as.character(author_handle), "^@"),
text = replace_na(as.character(post_text), ""),
posted_at = as.character(posted),
like_count = replace_na(as.numeric(likes), 0),
repost_count = replace_na(as.numeric(reposts), 0),
reply_count = replace_na(as.numeric(replies), 0)
)
# Combine all files and compute total engagement
raw <- bind_rows(s1_raw, s2_raw) %>%
mutate(
batch = factor(batch, levels = c("Batch 1 (Oct 22 Scrape)", "Batch 2 (BlueFacts Scrape)")),
engagement = like_count + repost_count + reply_count,
post_id = row_number()
)
raw %>%
group_by(batch) %>%
summarise(
raw_rows = n(),
median_engagement = median(engagement),
mean_engagement = round(mean(engagement), 2),
max_engagement = max(engagement)
) %>%
kable()
| batch | raw_rows | median_engagement | mean_engagement | max_engagement |
|---|---|---|---|---|
| Batch 1 (Oct 22 Scrape) | 100 | 0 | 0.88 | 29 |
| Batch 2 (BlueFacts Scrape) | 15 | 0 | 3.20 | 39 |
cleaning_log <- tibble()
log_step <- function(step, data) {
cleaning_log <<- bind_rows(
cleaning_log,
data %>% count(batch, name = "posts") %>% mutate(step = step)
)
}
log_step("0. Combined raw rows", raw)
# 3.1 Clean text (remove @mentions, URLs, hashtags, and smart punctuation)
posts <- raw %>%
mutate(
nsfw = str_detect(str_to_lower(text), "nsfw"),
clean_text = text %>%
str_replace_all("[\u2018\u2019]", "'") %>%
str_replace_all("[\u201C\u201D]", '"') %>%
str_replace_all("[\u2013\u2014]", " - ") %>%
str_replace_all("\u2026", " ") %>%
str_replace_all(""", '"') %>%
str_replace_all("@[\\w.-]+", " ") %>%
str_replace_all("https?://\\S+|www\\.\\S+", " ") %>%
str_replace_all("\\b[a-z0-9.-]+\\.(com|org|net|co|to|in|uk|be|social|app|io|online|jp|us|gy|amazon|ly|la)(/\\S*)?", " ") %>%
str_replace_all("#\\S+", " ") %>%
str_squish(),
n_words = str_count(clean_text, "[A-Za-z']+")
) %>%
filter(n_words >= 3)
log_step("1. Remove empty / link-only / <3-word posts", posts)
# 3.2 Remove non-English posts (e.g., Portuguese/Spanish promo posts)
english_vocab <- unique(c(stop_words$word, bing$word, afinn$word))
lang_check <- posts %>%
select(post_id, clean_text) %>%
unnest_tokens(word, clean_text) %>%
group_by(post_id) %>%
summarise(share_english_words = mean(word %in% english_vocab), .groups = "drop")
posts <- posts %>%
left_join(lang_check, by = "post_id") %>%
mutate(
share_ascii = str_count(clean_text, "[A-Za-z]") / pmax(str_count(clean_text, "\\p{L}"), 1),
english = share_english_words >= 0.5 | (share_ascii >= 0.85 & share_english_words >= 0.3)
) %>%
filter(english)
log_step("2. Remove non-English posts", posts)
# 3.3 Remove duplicate posts across overlapping Batch 1 exports
posts <- posts %>%
arrange(desc(engagement)) %>%
distinct(clean_text, .keep_all = TRUE)
log_step("3. Remove duplicate posts (merged Batch 1 files)", posts)
# 3.4 Flag high-frequency deal/bot accounts (>= 4 posts in one batch)
heavy_posters <- posts %>%
count(batch, author_handle) %>%
filter(n >= 4)
posts <- posts %>%
filter(!author_handle %in% heavy_posters$author_handle, !nsfw)
log_step("4. Remove heavy promo/bot accounts (>=4 posts) & NSFW", posts)
cleaning_log %>%
pivot_wider(names_from = batch, values_from = posts, values_fill = 0) %>%
relocate(step) %>%
kable()
| step | Batch 1 (Oct 22 Scrape) | Batch 2 (BlueFacts Scrape) |
|---|---|---|
| 0. Combined raw rows | 100 | 15 |
| 1. Remove empty / link-only / <3-word posts | 95 | 15 |
| 2. Remove non-English posts | 39 | 5 |
| 3. Remove duplicate posts (merged Batch 1 files) | 36 | 5 |
| 4. Remove heavy promo/bot accounts (>=4 posts) & NSFW | 30 | 5 |
custom_stop <- tibble(word = c(
"nike", "nike's", "it's", "i'm", "don't", "amp", "gt", "lt", "i've", "that's", "can't"
))
tokens <- posts %>%
select(post_id, batch, clean_text, engagement) %>%
unnest_tokens(word, clean_text)
content_words <- tokens %>%
anti_join(stop_words, by = "word") %>%
anti_join(custom_stop, by = "word") %>%
filter(!str_detect(word, "^\\d+$"), nchar(word) > 1)
# Top 15 overall content words
content_words %>%
count(word, sort = TRUE) %>%
slice_max(n, n = 15, with_ties = FALSE) %>%
ggplot(aes(n, reorder(word, n))) +
geom_col(fill = "#111111") +
labs(title = "Top 15 Content Words Across Clean Nike Posts", x = "Count", y = NULL) +
theme_minimal()
batch_tfidf <- content_words %>%
count(batch, word) %>%
bind_tf_idf(word, batch, n) %>%
filter(n >= 2, idf > 0)
batch_tfidf %>%
group_by(batch) %>%
slice_max(tf_idf, n = 8, with_ties = FALSE) %>%
ungroup() %>%
mutate(word = reorder_within(word, tf_idf, batch)) %>%
ggplot(aes(tf_idf, word, fill = batch)) +
geom_col(show.legend = FALSE) +
scale_y_reordered() +
scale_fill_manual(values = c("#111111", "#E65100")) +
facet_wrap(~ batch, scales = "free") +
labs(title = "Most Distinctive Words by Scrape Batch (TF-IDF)", x = "TF-IDF", y = NULL) +
theme_minimal()
#Top Biagrams
posts %>%
unnest_tokens(bigram, clean_text, token = "ngrams", n = 2) %>%
filter(!is.na(bigram)) %>%
separate(bigram, into = c("w1", "w2"), sep = " ") %>%
filter(
!w1 %in% stop_words$word, !w2 %in% stop_words$word,
!w1 %in% custom_stop$word, !w2 %in% custom_stop$word
) %>%
unite(bigram, w1, w2, sep = " ") %>%
count(batch, bigram, sort = TRUE) %>%
group_by(batch) %>%
slice_head(n = 8) %>%
kable()
| batch | bigram | n |
|---|---|---|
| Batch 1 (Oct 22 Scrape) | 1224 current | 2 |
| Batch 1 (Oct 22 Scrape) | 28 months | 2 |
| Batch 1 (Oct 22 Scrape) | air max | 2 |
| Batch 1 (Oct 22 Scrape) | current size | 2 |
| Batch 1 (Oct 22 Scrape) | dick’s sporting | 2 |
| Batch 1 (Oct 22 Scrape) | listed 28 | 2 |
| Batch 1 (Oct 22 Scrape) | months ago | 2 |
| Batch 1 (Oct 22 Scrape) | tech fleece | 2 |
| Batch 2 (BlueFacts Scrape) | air force | 1 |
| Batch 2 (BlueFacts Scrape) | converse ad | 1 |
| Batch 2 (BlueFacts Scrape) | disciplinary action | 1 |
| Batch 2 (BlueFacts Scrape) | dri fit | 1 |
| Batch 2 (BlueFacts Scrape) | empty words | 1 |
| Batch 2 (BlueFacts Scrape) | favourite sneaker | 1 |
| Batch 2 (BlueFacts Scrape) | fit slim | 1 |
| Batch 2 (BlueFacts Scrape) | force 1 | 1 |
score_tokens <- tokens %>% filter(word != "like")
bing_scores <- score_tokens %>%
inner_join(bing, by = "word") %>%
count(post_id, sentiment) %>%
pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>%
transmute(post_id, bing_score = positive - negative)
afinn_scores <- score_tokens %>%
inner_join(afinn, by = "word") %>%
group_by(post_id) %>%
summarise(afinn_score = sum(value), .groups = "drop")
nrc_scores <- score_tokens %>%
inner_join(filter(nrc, sentiment %in% c("positive", "negative")), by = "word", relationship = "many-to-many") %>%
count(post_id, sentiment) %>%
pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>%
transmute(post_id, nrc_score = positive - negative)
label_sent <- function(x) {
factor(
case_when(x > 0 ~ "Positive", x < 0 ~ "Negative", TRUE ~ "Neutral"),
levels = c("Positive", "Neutral", "Negative")
)
}
scored <- posts %>%
select(post_id, batch, author_handle, clean_text, like_count, repost_count, reply_count, engagement) %>%
left_join(bing_scores, by = "post_id") %>%
left_join(afinn_scores, by = "post_id") %>%
left_join(nrc_scores, by = "post_id") %>%
mutate(
across(c(bing_score, afinn_score, nrc_score), ~ replace_na(.x, 0)),
bing_label = label_sent(bing_score),
afinn_label = label_sent(afinn_score),
nrc_label = label_sent(nrc_score)
)
# Sentiment distribution by lexicon
sent_summary <- scored %>%
pivot_longer(c(bing_label, afinn_label, nrc_label), names_to = "lexicon", values_to = "label") %>%
mutate(lexicon = recode(lexicon, bing_label = "Bing", afinn_label = "AFINN", nrc_label = "NRC")) %>%
count(batch, lexicon, label) %>%
group_by(batch, lexicon) %>%
mutate(share = n / sum(n)) %>%
ungroup()
sent_summary %>%
select(-n) %>%
mutate(share = percent(share, accuracy = 1)) %>%
pivot_wider(names_from = label, values_from = share) %>%
kable()
| batch | lexicon | Positive | Neutral | Negative |
|---|---|---|---|---|
| Batch 1 (Oct 22 Scrape) | AFINN | 30% | 47% | 23% |
| Batch 1 (Oct 22 Scrape) | Bing | 40% | 53% | 7% |
| Batch 1 (Oct 22 Scrape) | NRC | 60% | 30% | 10% |
| Batch 2 (BlueFacts Scrape) | AFINN | 40% | 40% | 20% |
| Batch 2 (BlueFacts Scrape) | Bing | 40% | 20% | 40% |
| Batch 2 (BlueFacts Scrape) | NRC | 60% | 20% | 20% |
ggplot(sent_summary, aes(x = lexicon, y = share, fill = label)) +
geom_col() +
facet_wrap(~ batch) +
scale_y_continuous(labels = percent) +
scale_fill_manual(values = c(Positive = "#2C7FB8", Neutral = "#BDBDBD", Negative = "#D7301F")) +
labs(title = "Sentiment Label Share by Batch and Lexicon", x = NULL, y = "Share of Posts", fill = NULL) +
theme_minimal()
scored %>%
summarise(
bing_vs_afinn = percent(mean(bing_label == afinn_label), accuracy = 1),
bing_vs_nrc = percent(mean(bing_label == nrc_label), accuracy = 1),
afinn_vs_nrc = percent(mean(afinn_label == nrc_label), accuracy = 1),
all_three = percent(mean(bing_label == afinn_label & afinn_label == nrc_label), accuracy = 1)
) %>%
kable(caption = "Pairwise and Three-Way Lexicon Agreement")
| bing_vs_afinn | bing_vs_nrc | afinn_vs_nrc | all_three |
|---|---|---|---|
| 57% | 46% | 49% | 26% |
# NRC 8 Emotions breakdown
score_tokens %>%
inner_join(filter(nrc, !sentiment %in% c("positive", "negative")), by = "word", relationship = "many-to-many") %>%
count(sentiment) %>%
mutate(share = n / sum(n)) %>%
ggplot(aes(share, reorder(sentiment, share))) +
geom_col(fill = "#E65100") +
scale_x_continuous(labels = percent) +
labs(title = "NRC Emotion Distribution Across Nike Posts", x = "Share of Emotion Words", y = NULL) +
theme_minimal()
#Does Sentiment Predict Engagement?
overall_cor <- cor.test(scored$afinn_score, scored$engagement, method = "spearman", exact = FALSE)
overall_cor
##
## Spearman's rank correlation rho
##
## data: scored$afinn_score and scored$engagement
## S = 8873.2, p-value = 0.16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.2427463
scored %>%
group_by(bing_label) %>%
summarise(
posts = n(),
mean_engagement = round(mean(engagement), 2),
median_engagement = median(engagement),
.groups = "drop"
) %>%
kable()
| bing_label | posts | mean_engagement | median_engagement |
|---|---|---|---|
| Positive | 14 | 0.86 | 0.0 |
| Neutral | 17 | 0.59 | 0.0 |
| Negative | 4 | 17.00 | 14.5 |
# Interactive scatter plot (posts with >= 1 engagement shown on log scale)
plot_data <- scored %>%
filter(engagement > 0) %>%
mutate(
hover = paste0(
"<b>@", author_handle, "</b> (", batch, ")<br>",
str_wrap(str_trunc(clean_text, 200), 55) %>% str_replace_all("\n", "<br>"),
"<br><br>AFINN: ", afinn_score, " | Bing: ", bing_score,
"<br>Likes: ", like_count, " | Reposts: ", repost_count, " | Replies: ", reply_count
)
)
plot_ly(
plot_data, x = ~afinn_score, y = ~engagement, color = ~batch,
colors = c("#111111", "#E65100"),
type = "scatter", mode = "markers",
marker = list(size = 9, opacity = 0.75, line = list(width = 0.5, color = "white")),
text = ~hover, hoverinfo = "text"
) %>%
layout(
title = list(text = "Sentiment vs. Engagement: Nike Bluesky Posts (Engagement > 0)", x = 0.02),
xaxis = list(title = "AFINN Sentiment Score"),
yaxis = list(title = "Engagement (Likes + Reposts + Replies)", type = "log")
)
#Survey Analysis: Social Media Engagement & Purchase Intention
survey_file <- "Nike Social Media Engagement_December 1, 2026_00.28 (1).csv"
col_names <- names(read_csv(survey_file, n_max = 0, show_col_types = FALSE))
survey_raw <- read_csv(survey_file, skip = 3, col_names = col_names, show_col_types = FALSE) %>%
filter(Finished == TRUE | Finished == "True")
# Helper functions to convert Likert and intent responses to numeric 1-5 / 1-3 scales
recode_likert5 <- function(x) {
x_clean <- str_to_lower(str_squish(as.character(x)))
case_when(
str_detect(x_clean, "highly disagree|strongly disagree") ~ 1,
str_detect(x_clean, "diagree|disagree") & !str_detect(x_clean, "neither") ~ 2,
str_detect(x_clean, "neither|neutral|nuetral") ~ 3,
str_detect(x_clean, "somewhat|somwhate") & !str_detect(x_clean, "agree") ~ 3,
str_detect(x_clean, "somewhat agree|somwhate agree|^agree$") ~ 4,
str_detect(x_clean, "highly agree|strongly agree") ~ 5,
TRUE ~ NA_real_
)
}
recode_intent3 <- function(x) {
x_clean <- str_to_lower(str_squish(as.character(x)))
case_when(
x_clean == "no" ~ 1,
x_clean == "maybe" ~ 2,
x_clean == "yes" ~ 3,
TRUE ~ NA_real_
)
}
survey_clean <- survey_raw %>%
transmute(
ResponseId,
duration_sec = as.numeric(`Duration (in seconds)`),
# Q2-Q5: Social Media Engagement & Attention (1 = Low, 5 = High)
Q2_interact = recode_likert5(Q2),
Q3_attention = recode_likert5(Q3),
Q4_regular = recode_likert5(Q4),
Q5_vs_brands = recode_likert5(Q5),
# Q6: Purchase Likelihood (1 = Low, 5 = High)
Q6_purchase = recode_likert5(`Q6 Dependent`),
# Q7-Q10: Behavioral Intentions (1 = No, 2 = Maybe, 3 = Yes)
Q7_interest = recode_intent3(Q7),
Q8_recommend = recode_intent3(Q8),
Q9_6mo_buy = recode_intent3(Q9),
Q10_consider = recode_intent3(Q10)
) %>%
rowwise() %>%
mutate(
sm_engagement_index = mean(c(Q2_interact, Q3_attention, Q4_regular, Q5_vs_brands), na.rm = TRUE),
purchase_intent_index = mean(c(Q7_interest, Q8_recommend, Q9_6mo_buy, Q10_consider), na.rm = TRUE)
) %>%
ungroup()
# Summary statistics table
survey_clean %>%
summarise(
Respondents = n(),
Mean_SM_Engagement_1to5 = round(mean(sm_engagement_index, na.rm = TRUE), 2),
SD_SM_Engagement = round(sd(sm_engagement_index, na.rm = TRUE), 2),
Mean_Purchase_Likert_1to5 = round(mean(Q6_purchase, na.rm = TRUE), 2),
Mean_Intent_Index_1to3 = round(mean(purchase_intent_index, na.rm = TRUE), 2)
) %>%
kable(caption = "Survey Construct Summary Statistics (n = 20)")
| Respondents | Mean_SM_Engagement_1to5 | SD_SM_Engagement | Mean_Purchase_Likert_1to5 | Mean_Intent_Index_1to3 |
|---|---|---|---|---|
| 20 | 2.78 | 0.74 | 2.7 | 1.9 |
#Correlation & Regression: Does Social Media Engagement Predict Purchase Intention?
# Correlation between Social Media Engagement Index and Q6 Purchase Likelihood
cor_q6 <- cor.test(survey_clean$sm_engagement_index, survey_clean$Q6_purchase, method = "pearson")
cor_q6
##
## Pearson's product-moment correlation
##
## data: survey_clean$sm_engagement_index and survey_clean$Q6_purchase
## t = 0.71167, df = 18, p-value = 0.4858
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.2989767 0.5664817
## sample estimates:
## cor
## 0.1654312
# Correlation between Social Media Engagement Index and Composite Intent (Q7-Q10)
cor_intent <- cor.test(survey_clean$sm_engagement_index, survey_clean$purchase_intent_index, method = "pearson")
cor_intent
##
## Pearson's product-moment correlation
##
## data: survey_clean$sm_engagement_index and survey_clean$purchase_intent_index
## t = 1.1235, df = 18, p-value = 0.276
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.2103664 0.6274308
## sample estimates:
## cor
## 0.2559843
# Linear regression: Purchase Intent Index ~ Social Media Engagement Index
intent_lm <- lm(purchase_intent_index ~ sm_engagement_index, data = survey_clean)
summary(intent_lm)
##
## Call:
## lm(formula = purchase_intent_index ~ sm_engagement_index, data = survey_clean)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.81678 -0.29031 -0.03694 0.20631 0.99178
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.4069 0.4496 3.129 0.0058 **
## sm_engagement_index 0.1757 0.1564 1.123 0.2760
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5051 on 18 degrees of freedom
## Multiple R-squared: 0.06553, Adjusted R-squared: 0.01361
## F-statistic: 1.262 on 1 and 18 DF, p-value: 0.276
ggplot(survey_clean, aes(x = sm_engagement_index, y = purchase_intent_index)) +
geom_jitter(width = 0.05, height = 0.05, size = 3, color = "#111111", alpha = 0.8) +
geom_smooth(method = "lm", se = TRUE, color = "#E65100", fill = "#FFE0B2") +
labs(
title = "Nike Social Media Engagement vs. Purchase Intention (Survey, n = 20)",
subtitle = paste0("Pearson r = ", round(cor_intent$estimate, 2), ", p = ", round(cor_intent$p.value, 3)),
x = "Social Media Engagement Index (Q2–Q5 Mean, 1–5 Scale)",
y = "Purchase Intention Index (Q7–Q10 Mean, 1–3 Scale)"
) +
theme_minimal()
#Response Breakdown Across Intent Questions (Q7–Q10)
survey_raw %>%
select(
`Increases Buying Interest (Q7)` = Q7,
`Recommend Nike (Q8)` = Q8,
`Buy Within 6 Months (Q9)` = Q9,
`Consider After Seeing Ad (Q10)` = Q10
) %>%
pivot_longer(everything(), names_to = "Question", values_to = "Response") %>%
filter(!is.na(Response)) %>%
count(Question, Response) %>%
group_by(Question) %>%
mutate(share = n / sum(n)) %>%
ggplot(aes(x = Question, y = share, fill = factor(Response, levels = c("Yes", "Maybe", "No")))) +
geom_col() +
coord_flip() +
scale_y_continuous(labels = percent) +
scale_fill_manual(values = c("Yes" = "#2C7FB8", "Maybe" = "#BDBDBD", "No" = "#D7301F")) +
labs(title = "Distribution of Nike Purchase & Recommendation Intentions", x = NULL, y = "Share of Respondents", fill = "Response") +
theme_minimal()