Research question

Which features of a BlueSky post about movies go with more likes, and does a positive tone help?

This lab is usually done with a Qualtrics survey. I use the same steps (raw data → cleaning → clean file → simple and multivariate regression) on the BlueSky movie posts our team scraped.

  • Outcome (y): likes, as log(likes + 1)
  • Simple regression predictor (x): sentiment score (positive words − negative words)
  • Extra predictors: post age, word count, link, hashtags, question, account type, scrape date

Load packages

# Run once in the Console if needed: install.packages(c("tidyverse", "tidytext", "broom"))
library(tidyverse)
library(tidytext)
library(broom)

Import the raw data

Both raw CSV files must be in your project (in Posit Cloud: Files pane → Upload).

# Look for the two files anywhere in this project, even if they were renamed (e.g. "... (1).csv")
csv_files <- list.files(path = c(".", "/cloud/project"), pattern = "\\.csv$", recursive = TRUE,
                        ignore.case = TRUE, full.names = TRUE)
csv_files
## [1] "./bluesky_posts_2026-11-19.csv"             
## [2] "./movies_posts_clean.csv"                   
## [3] "./scrape_movies.csv"                        
## [4] "/cloud/project/bluesky_posts_2026-11-19.csv"
## [5] "/cloud/project/movies_posts_clean.csv"      
## [6] "/cloud/project/scrape_movies.csv"
file_nov3  <- csv_files[str_detect(csv_files, regex("scrape_movies", ignore_case = TRUE))][1]
file_nov19 <- csv_files[str_detect(csv_files, regex("bluesky_posts_2026-11-19", ignore_case = TRUE))][1]

if (is.na(file_nov3) | is.na(file_nov19)) {
  stop("R can't find the raw CSV files.\n",
       "R is looking in: ", getwd(), "\n",
       "CSV files R can see: ", paste(basename(csv_files), collapse = ", "), "\n",
       "Fix: in the Files pane click Upload and upload regression_lab.zip (or both CSVs), then knit again.")
}

# Gian's file was saved from Excel, so it needs the Windows encoding
raw_nov3  <- read_csv(file_nov3, locale = locale(encoding = "windows-1252"))
raw_nov19 <- read_csv(file_nov19)

nrow(raw_nov3)
## [1] 200
nrow(raw_nov19)
## [1] 596

Clean the data

Combine the two files

The files use different column names for the time (created_at vs. indexed_at), so I rename them to match.

nov3 <- raw_nov3 %>%
  transmute(dataset = "Nov 3", author = author_handle, text,
            posted = lubridate::as_datetime(created_at), likes = like_count)

nov19 <- raw_nov19 %>%
  transmute(dataset = "Nov 19", author = author_handle, text,
            posted = lubridate::as_datetime(indexed_at), likes = like_count)

posts <- bind_rows(nov3, nov19)

# Each file is sorted newest first, so the first post is about when it was scraped.
# A time later than that is impossible (a typo), so I set it to missing.
posts <- posts %>%
  group_by(dataset) %>%
  mutate(scrape_time = first(posted),
         posted = replace(posted, which(posted > scrape_time), NA)) %>%
  ungroup()

Remove posts that don’t belong

spam_accounts <- c("realpornblogger.bsky.social", "aebn.bsky.social", "jav-mania.net",
                   "thronly.bsky.social", "crimson-hard.bsky.social")

# 1. Blank posts (link cards with no text)
step1 <- posts %>% filter(!is.na(text), str_trim(text) != "")

# 2. Test posts
step2 <- step1 %>% filter(str_to_lower(str_trim(text)) != "test")

# 3. Adult / spam posts
step3 <- step2 %>% filter(!str_detect(str_to_lower(text), "nsfw"), !author %in% spam_accounts)

# 4. Automated accounts: 4+ posts in one short scrape window (news feeds, deal bots, promoters)
step4 <- step3 %>%
  add_count(dataset, author, name = "posts_by_author") %>%
  filter(posts_by_author < 4)

# 5. Off-topic: the post's own words (links removed) never mention movies
step5 <- step4 %>%
  filter(str_detect(str_to_lower(str_remove_all(text, "https?://\\S+|\\S+\\.\\S+/\\S*")),
                    "movie|film|cinema|theat"))

# 6. Non-English: no common English words (very short posts are kept)
step6 <- step5 %>%
  filter(str_detect(str_to_lower(text),
                    "\\b(the|and|to|of|you|my|this|that|for|with|it|are|we|they|i|what|not|but|just)\\b") |
           str_count(text, "\\S+") <= 6)

cleaning_log <- tibble(
  step  = c("Raw posts", "Removed blank posts", "Removed test posts", "Removed adult/spam posts",
            "Removed automated accounts", "Removed off-topic posts", "Removed non-English posts"),
  posts_left = c(nrow(posts), nrow(step1), nrow(step2), nrow(step3), nrow(step4), nrow(step5), nrow(step6))
)
knitr::kable(cleaning_log)
step posts_left
Raw posts 796
Removed blank posts 783
Removed test posts 782
Removed adult/spam posts 775
Removed automated accounts 742
Removed off-topic posts 656
Removed non-English posts 635

Recode variables

clean <- step6 %>%
  mutate(
    id            = row_number(),
    log_likes     = log(likes + 1),
    word_count    = str_count(text, "\\S+"),
    has_link      = ifelse(str_detect(text, "https?://|www\\.|\\S+\\.[a-z]{2,6}/"), 1, 0),
    n_hashtags    = str_count(text, "#[A-Za-z]"),
    q_text        = ifelse(dataset == "Nov 3", str_remove_all(text, "\\?{2,}"), text),  # "??" = lost emoji
    is_question   = ifelse(str_detect(q_text, "\\?"), 1, 0),
    custom_domain = ifelse(str_detect(author, "bsky\\.social|brid\\.gy|blacksky|northsky|eurosky|myatproto"), 0, 1),
    nov19         = ifelse(dataset == "Nov 19", 1, 0),
    post_age_hr   = as.numeric(difftime(scrape_time, posted, units = "hours"))
  )

Fill missing values with the column mean

A few posts have no usable time, so their post age is missing. I replace each missing value with the mean post age of its own file and keep a 0/1 flag.

sum(is.na(clean$post_age_hr))   # how many are missing
## [1] 4
clean <- clean %>%
  group_by(dataset) %>%
  mutate(age_missing = ifelse(is.na(post_age_hr), 1, 0),
         post_age_hr = ifelse(is.na(post_age_hr), mean(post_age_hr, na.rm = TRUE), post_age_hr)) %>%
  ungroup()

sum(is.na(clean$post_age_hr))   # should now be 0
## [1] 0

Sentiment score

Score = positive words − negative words (Bing lexicon). Horror-genre words and filler like “like” are skipped because they aren’t opinions in movie posts.

ignore_words <- c("horror", "scary", "creepy", "monster", "monsters", "villain", "evil", "dead",
                  "kill", "killer", "killing", "murder", "bloody", "haunted", "nightmare",
                  "zombie", "trump", "die", "hot", "like")

sentiment_scores <- clean %>%
  select(id, text) %>%
  unnest_tokens(word, text) %>%
  filter(!word %in% ignore_words) %>%
  inner_join(get_sentiments("bing"), by = "word") %>%
  count(id, sentiment) %>%
  pivot_wider(names_from = sentiment, values_from = n, values_fill = 0)

clean <- clean %>%
  left_join(sentiment_scores, by = "id") %>%
  mutate(positive  = replace_na(positive, 0),
         negative  = replace_na(negative, 0),
         sentiment = positive - negative)

Save the clean file

clean_out <- clean %>%
  select(dataset, author, posted, text, likes, log_likes, sentiment, post_age_hr, age_missing,
         word_count, has_link, n_hashtags, is_question, custom_domain, nov19)

write_csv(clean_out, "movies_posts_clean.csv")
nrow(clean_out)
## [1] 635

Explore the data

clean %>%
  select(likes, log_likes, sentiment, post_age_hr, word_count, has_link,
         n_hashtags, is_question, custom_domain, nov19) %>%
  summary()
##      likes          log_likes        sentiment        post_age_hr      
##  Min.   : 0.000   Min.   :0.0000   Min.   :-4.0000   Min.   :0.004167  
##  1st Qu.: 0.000   1st Qu.:0.0000   1st Qu.:-0.5000   1st Qu.:0.538333  
##  Median : 1.000   Median :0.6931   Median : 0.0000   Median :1.183056  
##  Mean   : 2.156   Mean   :0.6301   Mean   : 0.3039   Mean   :1.416230  
##  3rd Qu.: 2.000   3rd Qu.:1.0986   3rd Qu.: 1.0000   3rd Qu.:2.351389  
##  Max.   :88.000   Max.   :4.4886   Max.   : 9.0000   Max.   :3.303611  
##    word_count       has_link        n_hashtags       is_question    
##  Min.   : 2.00   Min.   :0.0000   Min.   : 0.0000   Min.   :0.0000  
##  1st Qu.:17.50   1st Qu.:0.0000   1st Qu.: 0.0000   1st Qu.:0.0000  
##  Median :28.00   Median :0.0000   Median : 0.0000   Median :0.0000  
##  Mean   :29.73   Mean   :0.1181   Mean   : 0.5134   Mean   :0.1465  
##  3rd Qu.:42.00   3rd Qu.:0.0000   3rd Qu.: 0.0000   3rd Qu.:0.0000  
##  Max.   :59.00   Max.   :1.0000   Max.   :18.0000   Max.   :1.0000  
##  custom_domain         nov19      
##  Min.   :0.00000   Min.   :0.000  
##  1st Qu.:0.00000   1st Qu.:0.000  
##  Median :0.00000   Median :1.000  
##  Mean   :0.08031   Mean   :0.748  
##  3rd Qu.:0.00000   3rd Qu.:1.000  
##  Max.   :1.00000   Max.   :1.000
ggplot(clean, aes(x = likes)) +
  geom_histogram(binwidth = 1, fill = "#2a78d6", color = "white") +
  coord_cartesian(xlim = c(-0.5, 20)) +
  labs(title = "Most posts get zero or one like",
       subtitle = "Likes per post (zoomed to 0–20; a few posts have many more)",
       x = "Likes", y = "Number of posts") +
  theme_minimal(base_size = 13)

Likes are piled up at zero with a long tail, so I use log(likes + 1) as the outcome. A log transform is a standard fix for this kind of skew and uneven spread (James et al., 2021, §3.3.3). The + 1 keeps posts with zero likes.

Simple regression

model1 <- lm(log_likes ~ sentiment, data = clean)
summary(model1)
## 
## Call:
## lm(formula = log_likes ~ sentiment, data = clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.6571 -0.6320  0.0486  0.4603  3.8503 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.632018   0.032725  19.313   <2e-16 ***
## sentiment   -0.006281   0.021021  -0.299    0.765    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8088 on 633 degrees of freedom
## Multiple R-squared:  0.000141,   Adjusted R-squared:  -0.001439 
## F-statistic: 0.08927 on 1 and 633 DF,  p-value: 0.7652
ggplot(clean, aes(x = sentiment, y = log_likes)) +
  geom_jitter(width = 0.2, height = 0.03, alpha = 0.3, color = "#2a78d6") +
  geom_smooth(method = "lm", color = "black") +
  labs(title = "Likes vs. sentiment",
       subtitle = "Each dot is a post (jittered so overlapping dots show). Line = simple regression.",
       x = "Sentiment score (positive − negative words)", y = "log(likes + 1)") +
  theme_minimal(base_size = 13)

Interpretation: the sentiment coefficient is -0.006 (p = 0.765). Because likes are logged, one more net-positive word goes with about -0.6% change in likes. R² = 0, so sentiment alone explains 0% of the variation.

Multivariate regression

model2 <- lm(log_likes ~ sentiment + post_age_hr + word_count + has_link + n_hashtags +
               is_question + custom_domain + nov19, data = clean)
summary(model2)
## 
## Call:
## lm(formula = log_likes ~ sentiment + post_age_hr + word_count + 
##     has_link + n_hashtags + is_question + custom_domain + nov19, 
##     data = clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.1779 -0.5592 -0.1772  0.3186  3.7176 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.5240755  0.0939229   5.580 3.59e-08 ***
## sentiment     -0.0009656  0.0207281  -0.047 0.962858    
## post_age_hr    0.1376312  0.0382344   3.600 0.000344 ***
## word_count    -0.0017173  0.0021932  -0.783 0.433928    
## has_link      -0.2825702  0.1016918  -2.779 0.005622 ** 
## n_hashtags    -0.0133283  0.0195856  -0.681 0.496430    
## is_question    0.0691640  0.0899458   0.769 0.442212    
## custom_domain  0.4208100  0.1156069   3.640 0.000295 ***
## nov19         -0.0551446  0.0873314  -0.631 0.527983    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7902 on 626 degrees of freedom
## Multiple R-squared:  0.05607,    Adjusted R-squared:  0.04401 
## F-statistic: 4.648 on 8 and 626 DF,  p-value: 1.551e-05
ggplot(clean, aes(x = post_age_hr, y = log_likes)) +
  geom_jitter(width = 0, height = 0.03, alpha = 0.3, color = "#2a78d6") +
  geom_smooth(method = "lm", color = "black") +
  labs(title = "Older posts had more time to collect likes",
       subtitle = "Post age = hours between posting and the scrape",
       x = "Post age (hours)", y = "log(likes + 1)") +
  theme_minimal(base_size = 13)

Which predictor mattered most?

The predictors are in different units (hours, words, yes/no), so I standardize everything with scale() and compare the coefficients.

model_std <- lm(scale(log_likes) ~ scale(sentiment) + scale(post_age_hr) + scale(word_count) +
                  scale(has_link) + scale(n_hashtags) + scale(is_question) +
                  scale(custom_domain) + scale(nov19), data = clean)

std_coefs <- tidy(model_std, conf.int = TRUE) %>%
  filter(term != "(Intercept)") %>%
  mutate(term = str_remove_all(term, "scale\\(|\\)")) %>%
  arrange(desc(abs(estimate)))

knitr::kable(std_coefs %>% select(term, estimate, conf.low, conf.high, p.value), digits = 3)
term estimate conf.low conf.high p.value
post_age_hr 0.169 0.077 0.262 0.000
custom_domain 0.142 0.065 0.218 0.000
has_link -0.113 -0.193 -0.033 0.006
word_count -0.031 -0.107 0.046 0.434
is_question 0.030 -0.047 0.108 0.442
nov19 -0.030 -0.122 0.063 0.528
n_hashtags -0.027 -0.107 0.052 0.496
sentiment -0.002 -0.079 0.075 0.963
ggplot(std_coefs, aes(x = estimate, y = reorder(term, abs(estimate)))) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "gray50") +
  geom_pointrange(aes(xmin = conf.low, xmax = conf.high), color = "#2a78d6") +
  labs(title = "Standardized effects on likes",
       subtitle = "Dot = coefficient, line = 95% confidence interval. Biggest effects at the top.",
       x = "Standardized coefficient", y = NULL) +
  theme_minimal(base_size = 13)

Model checks

par(mfrow = c(2, 2))
plot(model2)

The residuals form bands because likes are whole numbers and many are zero. That is normal for count data.

Simple vs. multivariate

comparison <- tibble(
  model            = c("Simple", "Multivariate"),
  sentiment_coef   = c(coef(model1)["sentiment"], coef(model2)["sentiment"]),
  sentiment_pvalue = c(summary(model1)$coefficients["sentiment", 4],
                       summary(model2)$coefficients["sentiment", 4]),
  r_squared        = c(summary(model1)$r.squared, summary(model2)$r.squared),
  adj_r_squared    = c(summary(model1)$adj.r.squared, summary(model2)$adj.r.squared)
)
knitr::kable(comparison, digits = 3)
model sentiment_coef sentiment_pvalue r_squared adj_r_squared
Simple -0.006 0.765 0.000 -0.001
Multivariate -0.001 0.963 0.056 0.044

Check the regression by hand

For a simple regression, slope = cov(x, y) / var(x), intercept = mean(y) − slope × mean(x), and R² = cor(x, y)². These should match lm().

x <- clean$sentiment
y <- clean$log_likes

slope     <- cov(x, y) / var(x)
intercept <- mean(y) - slope * mean(x)
r2        <- cor(x, y)^2

tibble(quantity = c("slope", "intercept", "R-squared"),
       by_hand  = c(slope, intercept, r2),
       from_lm  = c(coef(model1)["sentiment"], coef(model1)["(Intercept)"], summary(model1)$r.squared)) %>%
  knitr::kable(digits = 5)
quantity by_hand from_lm
slope -0.00628 -0.00628
intercept 0.63202 0.63202
R-squared 0.00014 0.00014

Interpretation and reflection

  • Tone vs. reach. Berger and Milkman (2012) found that positive content gets shared more, but that high-arousal emotions matter more than positivity alone. A positive/negative word count can’t measure arousal.
  • The lexicon wasn’t built for movie talk. Bing comes from customer-review research (Hu & Liu, 2004) and scores one word at a time (Silge & Robinson, 2017), so I removed genre words like “horror” that describe a movie rather than judge it.
  • Post age is a confounder. A post scraped minutes after it went up hasn’t had time to get likes. Leaving out a variable that is related to both x and y biases a simple regression (James et al., 2021, ch. 3).
  • Audience size is missing. Follower counts aren’t in the data and probably drive likes more than wording, which is why R² stays low. These results are associations, not causes.
  • Mean imputation is a quick fix. van Buuren (2018, §1.3.3) warns that it shrinks variance and weakens relationships, and accepts it only when a handful of values are missing, which is the case here.

Write-up (about 150 words)

Which predictor mattered most? In the multivariate model, post_age_hr had the largest standardized effect (β = 0.17). Simple vs. multivariate: sentiment alone had a coefficient of -0.006 (R² = 0). With seven more predictors, it became -0.001 and R² rose to 0.056. [Explain why the sentiment coefficient changed or stayed about the same: did the added predictors overlap with sentiment?] The relationship: sentiment vs. likes is negative and not statistically significant, and most posts get zero or one like whatever their tone. If I did it again, I would collect follower counts, measure likes 24 hours after posting, scrape more days, and try a count model (negative binomial) instead of logging likes.

Forum post (draft)

Raw files: Gian_Abundo_-Scrape_Movies_11-3Sheet1.csv and movies_bluesky_posts_2026-11-19.csv. Clean file: movies_posts_clean.csv.

What I changed: I combined the two scrapes (796 posts), fixed the different column names and the Excel encoding, and removed blank posts, a test post, adult/spam posts, automated accounts, off-topic posts and non-English posts, leaving 635 posts. I set one impossible timestamp to missing and filled missing post ages with the column mean. I recoded each post into numbers: log likes, sentiment score, post age, word count, link, hashtags, question, account type and scrape date.

References