This lab shows how AI can help organize messy data while also showing why its output needs to be checked. AI helped create a workflow for combining our group’s Bluesky files, removing duplicate posts, examining frequent words, calculating sentiment, and building an interactive chart. The files contained blank text, missing dates, repeated posts, and an incomplete file. Another issue was that the week labels in the filenames did not consistently match the actual posting dates. I think this newly designed lab is useful because it connects coding with a real dataset and makes verification part of the assignment. A short example of how to check a sentiment score would make the instructions easier to follow.
The biggest limitation is that correct calculations do not automatically produce correct interpretations. A sentiment dictionary counts individual words without fully understanding sarcasm, negation, advertisements, or game titles. Some FIFA posts discuss real-world soccer instead of video games, and a discount advertisement does not necessarily express a player’s opinion. Human judgment contributes by evaluating relevance, interpreting the original wording, and deciding what conclusions the evidence supports. The context examples in this report were developed with AI support and do not establish independent human validation. The findings describe this collected sample rather than the opinions of all gamers.
```{r setup, include=FALSE} knitr::opts_chunk$set( echo = TRUE, message = FALSE, warning = TRUE )
packages <- c( “tidyverse”, “tidytext”, “lubridate”, “plotly”, “knitr” )
missing_packages <- packages[ !vapply( packages, requireNamespace, logical(1), quietly = TRUE )]
if (length(missing_packages) > 0) { install.packages( missing_packages, repos = “https://cloud.r-project.org” ) }
library(tidyverse) library(tidytext) library(lubridate) library(plotly) library(knitr)
## 1. Introduction
This report uses eight Bluesky CSV files collected by our group to examine conversations related to video games.
The analysis combines and cleans the data, identifies common words, calculates dictionary-based sentiment, and compares weekly results using an interactive plotly chart.
The report also checks the calculations and examines three posts in context. Weekly comparisons use actual posting dates rather than the week labels in filenames.
The findings describe the uploaded sample. They do not represent all Bluesky activity, establish actual video game sales, or measure the opinions of all gamers.
## 2. Import the Data
All columns are initially imported as text to avoid conflicts between files. Missing fields in the incomplete week-four file are represented as missing values.
```{r import}
files <- sort(
list.files(
path = "data",
pattern = "\\.csv$",
full.names = TRUE
)
)
if (length(files) == 0) {
stop(
"No CSV files found. Put the data folder beside this saved R Markdown file."
)
}
needed_columns <- c(
"uri",
"text",
"created_at",
"langs"
)
raw_data <- map_dfr(files, function(file) {
df <- read_csv(
file,
col_types = cols(.default = col_character()),
na = c("", "NA"),
name_repair = "unique",
show_col_types = FALSE
)
if (!all(c("uri", "text") %in% names(df))) {
stop(
paste(
"Required uri or text column missing from",
basename(file)
)
)
}
for (column in setdiff(needed_columns, names(df))) {
df[[column]] <- NA_character_
}
df %>%
select(all_of(needed_columns)) %>%
mutate(source_file = basename(file))
})
file_summary <- raw_data %>%
group_by(source_file) %>%
summarise(
imported_rows = n(),
missing_text = sum(
is.na(text) | str_trim(text) == ""
),
missing_date_field = sum(is.na(created_at)),
.groups = "drop"
)
kable(
file_summary,
caption = "Original Files and Missing Fields"
)
Blank posts and invalid post IDs are removed first. Duplicate post IDs are then counted once.
When multiple copies exist, a copy with a supplied date is preferred. The source filenames and original text are preserved.
URLs and mentions are removed from the version of the text used for analysis.
```{r cleaning} valid_data <- raw_data %>% filter( !is.na(text), str_trim(text) != ““, !is.na(uri), str_detect(uri,”^at://“) )
source_lookup <- valid_data %>% group_by(uri) %>% summarise( source_files = paste( sort(unique(source_file)), collapse = “;” ), copies_in_upload = n(), .groups = “drop” )
clean_data <- valid_data %>% arrange(is.na(created_at), source_file) %>% distinct(uri, .keep_all = TRUE) %>% left_join(source_lookup, by = “uri”) %>% mutate( post_id = row_number(),
created_time = ymd_hms(
created_at,
tz = "UTC",
quiet = TRUE
),
week = as.Date(
floor_date(
created_time,
unit = "week",
week_start = 1
)
),
clean_text = text %>%
str_replace_all(
"https?://\\S+|www\\.\\S+",
" "
) %>%
str_replace_all(
"\\b[[:alnum:]-]+(?:\\.[[:alnum:]-]+)*\\.[[:alpha:]]{2,}(?:/\\S*)?",
" "
) %>%
str_replace_all(
"@[[:alnum:]_.-]+",
" "
) %>%
str_squish(),
fifa_review = str_detect(
str_to_lower(text),
"\\bfifa\\b"
),
language_review = !is.na(langs) &
!str_detect(langs, "\\ben\\b")
) %>% add_count( clean_text, name = “same_text_post_ids” )
cleaning_summary <- tibble( step = c( “Imported rows”, “Rows removed for blank text or invalid ID”, “Duplicate post IDs removed”, “Unique posts retained”, “Retained posts without usable dates” ), count = c( nrow(raw_data), nrow(raw_data) - nrow(valid_data), nrow(valid_data) - nrow(clean_data), nrow(clean_data), sum(is.na(clean_data$week)) ) )
kable( cleaning_summary, caption = “Cleaning Results” )
The files contain **`r nrow(raw_data)` original rows**. Cleaning removes **`r nrow(raw_data) - nrow(valid_data)` rows with blank text or invalid IDs** and **`r nrow(valid_data) - nrow(clean_data)` duplicate post IDs**, leaving **`r nrow(clean_data)` unique posts**.
There are **`r sum(is.na(clean_data$week))` retained posts without usable dates**. These remain in the overall text and sentiment analyses but are excluded from the weekly chart.
Different post IDs with identical cleaned text are flagged rather than automatically removed. Repeated advertisements or copied wording can therefore influence the findings.
### Posting Dates
```{r posting-dates}
dated_posts <- clean_data %>%
filter(!is.na(created_time))
if (nrow(dated_posts) == 0) {
stop("No usable posting dates were found.")
}
date_summary <- tibble(
earliest_post_UTC = as.character(
min(dated_posts$created_time)
),
latest_post_UTC = as.character(
max(dated_posts$created_time)
)
)
kable(
date_summary,
caption = "Actual Posting Date Range"
)
The actual posting dates determine the calendar weeks. The filenames alone cannot establish when posts were written or collected.
```{r review-flags} review_flags <- tibble( issue = c( “Posts mentioning FIFA”, “Posts with language tags but no English tag”, “Posts sharing cleaned text with another post ID” ), posts_flagged = c( sum(clean_data\(fifa_review), sum(clean_data\)language_review), sum(clean_data$same_text_post_ids > 1) ) )
kable( review_flags, caption = “Potential Review Issues” )
These flags identify possible issues rather than automatically proving that a post should be excluded. Missing language tags also prevent the flags from identifying every non-English post.
All retained posts remain in the analysis, so relevance and language differences are limitations.
## 4. Word Frequency Analysis
Tokenization separates the cleaned text into individual word occurrences. Common stop words are removed for the frequency analysis.
The full token table is retained for sentiment analysis so a stop-word list does not silently remove potential sentiment matches.
```{r word-frequency}
tokens <- clean_data %>%
select(post_id, clean_text) %>%
unnest_tokens(word, clean_text) %>%
filter(str_detect(word, "[[:alpha:]]"))
word_counts <- tokens %>%
anti_join(stop_words, by = "word") %>%
filter(str_length(word) > 2) %>%
count(word, sort = TRUE)
kable(
head(word_counts, 20),
caption = "Twenty Most Frequent Words"
)
{r word-chart, fig.height=6} word_counts %>% slice_max( order_by = n, n = 20, with_ties = FALSE ) %>% ggplot( aes( x = reorder(word, n), y = n ) ) + geom_col(fill = "steelblue") + coord_flip() + labs( title = "Most Frequent Words in the Collected Posts", x = "Word", y = "Word Occurrences" ) + theme_minimal()
The most frequent retained words include
r paste(head(word_counts$word, 5), collapse = ", ").
These words identify recurring vocabulary. Frequency alone does not establish whether a topic is viewed positively or influences purchasing decisions.
The Bing English sentiment dictionary classifies matched words as positive or negative.
Each positive occurrence contributes +1, and each negative occurrence contributes −1.
Post sentiment score = positive occurrences − negative occurrences
Posts without dictionary matches are separated from posts with equal positive and negative matches.
```{r sentiment} bing_dictionary <- get_sentiments(“bing”)
sentiment_words <- tokens %>% inner_join( bing_dictionary, by = “word” )
sentiment_counts <- sentiment_words %>% group_by(post_id) %>% summarise( positive = sum(sentiment == “positive”), negative = sum(sentiment == “negative”), .groups = “drop” )
scored_posts <- clean_data %>% left_join( sentiment_counts, by = “post_id” ) %>% mutate( positive = replace_na(positive, 0L), negative = replace_na(negative, 0L), matched_words = positive + negative, sentiment_score = positive - negative,
sentiment_label = case_when(
matched_words == 0 ~ "No dictionary matches",
sentiment_score > 0 ~ "Positive matches",
sentiment_score < 0 ~ "Negative matches",
TRUE ~ "Balanced matches"
)
)
sentiment_summary <- scored_posts %>% count( sentiment_label, name = “posts” ) %>% mutate( percentage = round( 100 * posts / sum(posts), 1 ) )
kable( sentiment_summary, caption = “Dictionary-Based Sentiment Results” )
```{r sentiment-chart, fig.height=5}
ggplot(
sentiment_summary,
aes(
x = reorder(sentiment_label, posts),
y = posts,
fill = sentiment_label
)
) +
geom_col(show.legend = FALSE) +
coord_flip() +
labs(
title = "Sentiment Labels in the Collected Sample",
x = NULL,
y = "Number of Posts"
) +
theme_minimal()
r sum(scored_posts$matched_words > 0)
posts, or
r round(100 * mean(scored_posts$matched_words > 0), 1)%
of retained posts, contain at least one dictionary match.
These labels describe matched vocabulary rather than verified opinions about video games. “No dictionary matches” does not mean neutral, and “Balanced matches” does not prove that the writer expressed a balanced opinion.
Because the dictionary is English, posts in other languages may be missed or misinterpreted.
The chart displays the mean sentiment score among posts containing at least one dictionary match.
Weeks begin on Monday in UTC. Hover text displays weekly sample sizes.
```{r weekly-chart} weekly_observed <- scored_posts %>% filter(!is.na(week)) %>% group_by(week) %>% summarise( total_posts = n(),
posts_with_matches = sum(
matched_words > 0
),
average_sentiment = if (
any(matched_words > 0)
) {
mean(
sentiment_score[matched_words > 0]
)
} else {
NA_real_
},
.groups = "drop"
)
weekly_summary <- tibble( week = seq( min(dated_posts\(week), max(dated_posts\)week), by = “week” ) ) %>% left_join( weekly_observed, by = “week” ) %>% mutate( total_posts = replace_na( total_posts, 0L ),
posts_with_matches = replace_na(
posts_with_matches,
0L
),
hover_text = paste0(
"Week starting: ", week,
"<br>Collected posts: ", total_posts,
"<br>Posts with sentiment matches: ",
posts_with_matches,
"<br>Average score: ",
round(average_sentiment, 2)
)
)
plot_ly( data = weekly_summary, x = ~week, y = ~average_sentiment, type = “scatter”, mode = “lines+markers”, text = ~hover_text, hoverinfo = “text”, connectgaps = FALSE, line = list(color = “steelblue”) ) %>% layout( title = “Weekly Dictionary Sentiment”,
xaxis = list(
title = "Week Starting Monday (UTC)",
rangeslider = list(visible = TRUE)
),
yaxis = list(
title = "Mean Positive Minus Negative Matches"
)
)
Weeks without collected posts appear as gaps. A week containing posts but no sentiment matches also has no plotted mean.
Weekly differences require caution because sample sizes and search coverage vary. A change in this chart does not establish a change in opinion across the entire gaming community.
## 7. Verify the Calculations
The following checks verify that cleaning totals balance, post IDs are unique, sentiment arithmetic agrees, and weekly counts equal the number of dated posts.
```{r verification}
independent_scores <- sentiment_words %>%
mutate(
word_value = if_else(
sentiment == "positive",
1L,
-1L
)
) %>%
group_by(post_id) %>%
summarise(
recalculated_score = sum(word_value),
.groups = "drop"
)
score_check <- scored_posts %>%
select(post_id, sentiment_score) %>%
left_join(
independent_scores,
by = "post_id"
) %>%
mutate(
recalculated_score = replace_na(
recalculated_score,
0L
)
)
stopifnot(
nrow(raw_data) ==
(nrow(raw_data) - nrow(valid_data)) +
(nrow(valid_data) - nrow(clean_data)) +
nrow(clean_data),
anyDuplicated(scored_posts$uri) == 0,
nrow(scored_posts) == nrow(clean_data),
sum(sentiment_summary$posts) ==
nrow(scored_posts),
all(
scored_posts$matched_words ==
scored_posts$positive +
scored_posts$negative
),
all(
score_check$sentiment_score ==
score_check$recalculated_score
),
sum(weekly_summary$total_posts) ==
sum(!is.na(scored_posts$week))
)
cat(
"All automated accounting and sentiment arithmetic checks passed."
)
Passing these checks verifies accounting and arithmetic. It does not prove that the dictionary correctly interprets every post.
Three actual posts were selected for a context review: a positive player experience, a FIFA news headline, and a Call of Duty advertisement.
The review compares their original wording with their automatic labels. The worked example lists the dictionary matches and verifies the reported score. Together, these checks distinguish calculation accuracy from interpretation: a calculation can be correct while the post is off-topic or does not express a player’s opinion. These interpretations were developed with AI support rather than independent human labeling.
```{r context-review} review_notes <- tribble( ~uri, ~context_interpretation, ~reason,
“at://did:plc:fpvpbh5es47i5t3jlsmjbgpj/app.bsky.feed.post/3mpkon3z63k2i”, “Positive player experience”, “The writer praises polish and atmosphere and describes another game as fun. Game-title words need to be interpreted in context.”,
“at://did:plc:pzt7alpo2373magrlob5s72e/app.bsky.feed.post/3n3agybwaml2v”, “Off-topic for video game sentiment”, “The post concerns FIFA leadership, corruption allegations, and World Cup rights rather than a video game experience.”,
“at://did:plc:mijxmcmme5wjkxrekwayypry/app.bsky.feed.post/3n3b5p6gnps2x”, “Promotional content; player opinion unclear”, “The post advertises a discounted Call of Duty product. An advertisement does not establish whether a player enjoyed the game.” )
context_review <- review_notes %>% left_join( scored_posts %>% select( uri, post_id, text, positive, negative, sentiment_score, sentiment_label ), by = “uri” )
stopifnot( !any(is.na(context_review$post_id)) )
kable( context_review %>% select( text, sentiment_label, sentiment_score, context_interpretation, reason ), caption = “Context Review of Three Actual Posts” )
The player post expresses enjoyment directly. The FIFA headline discusses a different subject, while the advertisement promotes a product without establishing a player’s experience.
A sentiment score alone cannot determine whether a post answers the research question. Relevance, purpose, and the target of the sentiment must also be considered.
### Worked Sentiment Calculation
```{r worked-calculation}
player_post <- context_review %>%
filter(
context_interpretation ==
"Positive player experience"
)
player_words <- sentiment_words %>%
filter(
post_id == player_post$post_id[[1]]
) %>%
count(
word,
sentiment,
name = "occurrences"
)
kable(
player_post %>%
select(
text,
positive,
negative,
sentiment_score
),
caption = "Player Post and Calculated Score"
)
kable(
player_words,
caption = "Dictionary Matches Used in the Calculation"
)
The dictionary identifies
r player_post$positive[[1]] positive
occurrences and
r player_post$negative[[1]] negative
occurrences.
The calculation is:
r player_post$positive[[1]] −
r player_post$negative[[1]] =
r player_post$sentiment_score[[1]]
```{r verify-example} worked_score <- sum( ifelse( player_words\(sentiment == "positive", player_words\)occurrences, -player_words$occurrences ) )
stopifnot( worked_score == player_post$sentiment_score[[1]] )
cat( “The worked calculation agrees with the stored score.” )
This makes the calculation transparent and reproducible. It is a worked arithmetic check rather than a claim that a person independently hand-counted the words.
## 9. Findings
The combined files contain **`r nrow(raw_data)` original rows** and **`r nrow(scored_posts)` unique posts after cleaning**.
Common words include **`r paste(head(word_counts$word, 5), collapse = ", ")`**. These identify recurring vocabulary within the sample.
The largest automatic category is **`r sentiment_summary$sentiment_label[which.max(sentiment_summary$posts)]`**, with **`r max(sentiment_summary$posts)` posts**. This identifies the largest dictionary-based category without assuming that it represents verified player attitudes.
The interactive chart allows exploration of dictionary scores by posting week. Missing dates, unequal weekly samples, repeated advertising, language differences, and off-topic posts limit the conclusions.
The context review shows that negative vocabulary can appear in a post unrelated to gaming. Promotional language can also appear without expressing a player’s opinion.
A stronger follow-up study would use consistent search terms, documented collection windows, and independent human labels for relevance and sentiment.
## 10. Critique of AI Output and Human Judgment
The AI-generated workflow addresses several practical problems. It preserves source filenames, removes duplicate post IDs, separates missing sentiment matches from balanced matches, and uses actual posting dates for weekly comparisons.
However, the workflow has important limitations:
- Potentially off-topic posts remain in the analysis.
- An English dictionary is applied to a multilingual sample.
- Sarcasm, negation, and game-title meanings are not fully understood.
- Different post IDs are counted separately even when their wording is identical.
- Claims about sales or news events inside posts are not fact-checked.
- Arithmetic checks cannot establish whether an interpretation is correct.
- Three selected context examples cannot establish accuracy across the dataset.
The code was prepared in an environment without R. Its execution and chart rendering are checked when the document is knitted in RStudio.
Human judgment contributes by defining the research question, choosing inclusion rules, interpreting context, and deciding how much confidence the results deserve.
## 11. Actual AI Prompts and Responses
The assignment instructions and ZIP containing eight CSV files were supplied earlier in this conversation.
### Original Follow-Up Prompt
> Give me the exact syntax to paste into my r markdown document
**Response received:** The AI supplied an R Markdown workflow with data import, cleaning, word frequencies, Bing sentiment analysis, a plotly chart, verification checks, and exports. However, it left some review and prompt-record sections unfinished.
### Improved Follow-Up Prompt
> have the syntax with all the filled in answers and reflections, with nothing left for me to fill in
**Response received:** The AI supplied a revised report with completed reflection paragraphs, findings calculated when the document runs, a worked sentiment calculation, and interpretations of three actual posts.
### Final Consolidation Prompt
> could you give me the exact syntax for the whole assignment so everything is there so I can copy n paste
**Response received:** The AI consolidated the report into one complete R Markdown document containing the reflection, analysis, chart, verification, context review, findings, critique, and prompt record.
### Evaluation of the Prompt Improvement
The improved prompts clarified the required output: a complete document that could be pasted into R Markdown. They relied on the assignment instructions, uploaded files, and earlier conversation for the technical details.
A more specific standalone prompt would also identify the packages, input columns, duplicate-removal rule, date handling, sentiment method, and verification requirements.
This report makes those choices explicit so they can be inspected. It also distinguishes automated checks and AI-supported interpretations from independent human validation.
Screenshots of the actual prompts and responses are a separate discussion-forum submission requirement.
## 12. Save the Results
These tables are saved locally in a folder called `results`.
```{r save-results}
dir.create(
"results",
showWarnings = FALSE
)
write_csv(
cleaning_summary,
"results/cleaning_summary.csv"
)
write_csv(
scored_posts,
"results/cleaned_scored_posts.csv"
)
write_csv(
word_counts,
"results/word_counts.csv"
)
write_csv(
sentiment_summary,
"results/sentiment_summary.csv"
)
write_csv(
weekly_summary %>%
select(-hover_text),
"results/weekly_summary.csv"
)
write_csv(
context_review,
"results/context_review.csv"
)
write_csv(
player_words,
"results/worked_example_word_matches.csv"
)
{r session-info} sessionInfo()