Using AI made the coding part of this assignment easier, but I still need to check whether the results make sense. The code can label words as positive or negative without understanding the whole sentence. For example, it might count “good” as positive even when someone says a product is “not good.” It could also confuse someone’s opinion about Hailey Bieber with their opinion about Rhode’s products. This shows why running the code without errors is only one part of the assignment.
My judgment matters when deciding whether a post is about Rhode skincare and what the person actually means. Searching for “Rhode” could include unrelated posts, while searching for “Rhode skincare” could leave out people who only mention a product’s name. Bluesky users also may not represent all Rhode customers, so I would be careful about making broad claims from this sample. To improve the lab, I would include a short comparison between the computer’s labels and students’ labels so we can see where the results differ and explain why.
What topics appear in this sample of Rhode skincare posts, what sentiment does a simple dictionary detect, and how credible are those labels after human review? This is one dataset for the current lab; the provided instructions do not require a Day 1/Day 3 comparison. Public posts are not verified purchases or a random sample of customers. Results apply to the collected sample only.
The code removes missing/blank text and duplicate post URIs. When a URI is absent, it retains the row and uses a local row identifier; the absence of stable IDs limits duplicate detection. Identical text on different URIs remains because it can represent separate posts. URLs and handles are removed only from the analysis copy; original text is preserved. Missing engagement counts remain missing.
raw <- read.csv(params$csv,stringsAsFactors=FALSE,check.names=FALSE,
fileEncoding="UTF-8-BOM",na.strings=c("NA"))
aliases <- list(text=c("text","post_text"),uri=c("uri","post_uri"),
author_handle=c("author_handle","handle"),
like_count=c("like_count","likeCount","likes"),
repost_count=c("repost_count","repostCount","reposts"))
for(nm in names(aliases)) {
hit <- intersect(aliases[[nm]],names(raw))
if(length(hit)) raw[[nm]] <- raw[[hit[1]]]
}
if(!"text" %in% names(raw)) stop("CSV needs a text column. Available columns: ",paste(names(raw),collapse=", "))
raw$source_row <- seq_len(nrow(raw))
if(!"uri" %in% names(raw)) raw$uri <- NA_character_
if(!"author_handle" %in% names(raw)) raw$author_handle <- NA_character_
for(nm in c("like_count","repost_count")) {
if(!nm %in% names(raw)) raw[[nm]] <- NA_real_
raw[[nm]] <- suppressWarnings(as.numeric(raw[[nm]]))
raw[[nm]][!is.na(raw[[nm]]) & (!is.finite(raw[[nm]]) | raw[[nm]]<0)] <- NA_real_
}
raw <- raw %>% mutate(text=as.character(text),
missing_text=is.na(text) | !nzchar(trimws(text)),
has_uri=!is.na(uri) & nzchar(trimws(uri)),
duplicate_uri=has_uri & duplicated(uri),
removal_reason=case_when(missing_text ~ "missing/blank text",
duplicate_uri ~ "duplicate URI",TRUE ~ "retained"))
posts <- raw %>% filter(removal_reason=="retained") %>%
mutate(post_id=if_else(has_uri,uri,paste0("local_row_",source_row)),
text_clean=str_squish(str_replace_all(str_replace_all(
text,"https?://[^[:space:]]+"," "),"@[A-Za-z0-9_.-]+"," ")),
engagement=like_count+repost_count)
if(!nrow(posts)) stop("No nonblank unique posts remain.")
cleaning <- raw %>% count(removal_reason,name="rows")
write.csv(raw %>% select(source_row,uri,removal_reason),
"results/cleaning_decisions.csv",row.names=FALSE)
write.csv(posts,"results/cleaned_posts.csv",row.names=FALSE,na="")
| removal_reason | rows |
|---|---|
| missing/blank text | 55 |
| retained | 245 |
There are 300 input rows and 245 retained posts. 0 retained posts lack an original URI. If your CSV includes several pulls, this report deduplicates across them; analyze pulls separately if you intend a temporal comparison.
Tokenize into lowercase English-style word tokens, remove numbers and stop words for word frequency, and exclude the search terms “rhode,” “skin,” and “skincare.” Sentiment uses the token stream before these frequency exclusions. Frequency is not the same as topic modeling: read posts before claiming a theme.
tokens <- posts %>% select(post_id,text_clean) %>%
unnest_tokens(word,text_clean) %>% filter(str_detect(word,"[a-z]"))
words <- tokens %>% anti_join(tidytext::stop_words,by="word") %>%
filter(!word %in% c("rhode","skin","skincare")) %>%
count(word,sort=TRUE,name="occurrences")
write.csv(words,"results/word_frequency.csv",row.names=FALSE)
| word | occurrences |
|---|---|
| hailey | 195 |
| beauty | 119 |
| bieber | 115 |
| billion | 81 |
| brand | 81 |
| bieber’s | 59 |
| deal | 50 |
| bieber’s | 39 |
| makeup | 38 |
| elf | 29 |
| sephora | 29 |
| justin | 28 |
| acquired | 22 |
| products | 21 |
| company | 20 |
The Bing lexicon assigns positive or negative labels to individual English words (Silge & Robinson, 2017). For each post, score = positive-word occurrences minus negative-word occurrences. Scores above/below zero are positive/negative. A zero with matches is balanced; zero matches is unclassified. Neither is automatically a neutral human opinion. Repeated words count repeatedly. The model does not handle negation, sarcasm, emojis, or the target of the opinion.
lexicon <- tidytext::get_sentiments("bing") %>% distinct(word,sentiment)
matches <- tokens %>% inner_join(lexicon,by="word")
counts <- matches %>% group_by(post_id) %>% summarise(
positive=sum(sentiment=="positive"),negative=sum(sentiment=="negative"),.groups="drop")
scored <- posts %>% left_join(counts,by="post_id") %>%
mutate(positive=replace_na(positive,0L),negative=replace_na(negative,0L),
matched_words=positive+negative,score=positive-negative,
model_label=case_when(matched_words==0 ~ "unclassified",
score>0 ~ "positive",score<0 ~ "negative",TRUE ~ "balanced"))
levels_sent <- c("positive","negative","balanced","unclassified")
sentiment <- data.frame(model_label=levels_sent,
posts=as.integer(table(factor(scored$model_label,levels=levels_sent)))) %>%
mutate(percent=100*posts/nrow(scored))
write.csv(matches,"results/sentiment_word_matches.csv",row.names=FALSE)
write.csv(scored,"results/posts_with_sentiment.csv",row.names=FALSE,na="")
write.csv(sentiment,"results/sentiment_summary.csv",row.names=FALSE)
| model_label | posts | percent |
|---|---|---|
| positive | 145 | 59.183673 |
| negative | 18 | 7.346939 |
| balanced | 16 | 6.530612 |
| unclassified | 66 | 26.938775 |
Hover over a bar to inspect its exact count and percentage. The denominator is all retained posts, including balanced and unclassified posts.
fig <- plotly::plot_ly(sentiment,x=~model_label,y=~posts,type="bar",
text=~paste0(model_label,": ",posts," posts (",round(percent,1),"%)"),
hoverinfo="text",marker=list(color=c("#27877C","#C05D66","#A29175","#818995")))
fig <- plotly::layout(fig,title="Rhode skincare: dictionary sentiment",
xaxis=list(title="Model classification",categoryorder="array",categoryarray=levels_sent),
yaxis=list(title="Number of posts"))
fig
checks <- data.frame(check=c("Cleaning counts reconcile","One row per retained ID",
"All retained posts scored","Sentiment counts reconcile","Percentages sum to 100",
"Matched-word totals reconcile"),
passed=c(sum(cleaning$rows)==nrow(raw),!anyDuplicated(posts$post_id),
nrow(scored)==nrow(posts),sum(sentiment$posts)==nrow(scored),
abs(sum(sentiment$percent)-100)<1e-8,
sum(scored$matched_words)==nrow(matches)))
stopifnot(all(checks$passed))
| check | passed |
|---|---|
| Cleaning counts reconcile | TRUE |
| One row per retained ID | TRUE |
| All retained posts scored | TRUE |
| Sentiment counts reconcile | TRUE |
| Percentages sum to 100 | TRUE |
| Matched-word totals reconcile | TRUE |
These checks detect processing inconsistencies, not whether sentiment labels are correct. Below is the first retained post and the exact dictionary matches used to score it. Read the text, count positive and negative matches yourself, and confirm that the difference equals the displayed score.
| post_id | text | positive | negative | score | model_label |
|---|---|---|---|---|---|
| at://did:plc:dm4eys2zqvfkxqnt4b3dyhys/app.bsky.feed.post/3mzq4r62zra24 |
The Rhode founder is promoting a more positive approach to skincare #HaileyBieber #AntiAgeing #BeautyStandards #Skincare #BeautyIndustry Read More : https://ift.tt/x4GDKvT November 7, 2026 at 02:36PM |
1 | 0 | 1 | positive |
| word | sentiment | occurrences |
|---|---|---|
| positive | positive | 1 |
My independent hand calculation: [positive occurrences] − [negative occurrences] = [score]. [Explain whether the computed label fits the meaning of the post.]
The first knit creates manual_review.csv. Before
looking at the model labels, open that CSV and read each sampled post.
Enter positive, negative,
neutral, or unclear in
human_sentiment; judge sentiment toward Rhode’s products.
Enter yes, no, or uncertain in
brand_relevant, and explain disagreements or ambiguities in
notes. Save as CSV UTF-8, close Excel, then knit again.
Only English posts are suitable for this English lexicon; note other
languages. The sample stays fixed across knits. Existing reviews are
never overwritten.
review_path <- "manual_review.csv"
if(!file.exists(review_path)) {
set.seed(4000)
sample_ids <- sample(sort(scored$post_id),min(20,nrow(scored)))
review <- scored[match(sample_ids,scored$post_id),c("post_id","text")]
review$human_sentiment <- ""; review$brand_relevant <- ""; review$notes <- ""
write.csv(review,review_path,row.names=FALSE,na="",fileEncoding="UTF-8")
}
review <- read.csv(review_path,stringsAsFactors=FALSE,check.names=FALSE,
fileEncoding="UTF-8-BOM",na.strings=c("NA"))
required <- c("post_id","human_sentiment","brand_relevant","notes")
if(!all(required %in% names(review))) stop("Keep the original manual_review.csv columns.")
if(nrow(review)!=min(20,nrow(scored)) || anyNA(review$post_id) ||
anyDuplicated(review$post_id) || any(!review$post_id %in% scored$post_id))
stop("Review file does not match dataset. Move it aside and knit to regenerate, then relabel.")
for(nm in c("human_sentiment","brand_relevant")) {
review[[nm]][is.na(review[[nm]])] <- ""
review[[nm]] <- tolower(trimws(review[[nm]]))
}
if(any(!review$human_sentiment %in% c("","positive","negative","neutral","unclear")))
stop("Use positive, negative, neutral, unclear, or blank in human_sentiment.")
if(any(!review$brand_relevant %in% c("","yes","no","uncertain")))
stop("Use yes, no, uncertain, or blank in brand_relevant.")
# Join fresh source text so accidental edits in the review CSV do not change evidence.
audit <- review %>% select(-any_of("text")) %>%
left_join(scored %>% select(post_id,text,model_label,score),by="post_id")
write.csv(audit,"results/human_model_audit.csv",row.names=FALSE,na="")
Human sentiment labels completed: 0 / 20; relevance checks: 0 / 20.
## Manual verification pending. No model accuracy claim is justified yet.
Agreement above excludes neutral, unclear, balanced, unclassified, and unconfirmed brand relevance. It is a restricted diagnostic, not overall model accuracy. Use the cross-tabulation to examine all reviewed labels and abstentions. A small sample also limits how precisely model performance can be estimated.
Evidence-based critique: [Quote or paraphrase one actual sampled post, state the model and human labels, and explain the role of negation, context, relevance, language, or sentiment target. Report the number checked.]
My 2–3 themes: [Name themes and cite actual posts supporting each.]
My recommendation: [Connect a specific supported theme to a content test, customer question, or follow-up research. Avoid claiming causal impact, medical benefits, or that popularity proves product quality.]
Sampling limitation: The search wording may exclude product-only references; results may include promotion, repeated authors, non-English posts, and unrelated uses. Likes and reposts reflect accumulated engagement, not buying intention. A single pull does not establish a trend over time.
Exchange 1: The student requested help adapting a Bluesky/RStudio workflow to Rhode skincare and pasted the assignment requiring cleaning, text and sentiment analysis, Plotly, verification, reflection, and a second AI exchange. This is a summary; screenshot the original chat request and the actual response.
Exchange 2 — proposed improved prompt, not yet used:
Review the Rhode R Markdown code you gave me. Explain exactly how it avoids treating posts with no sentiment-word matches as neutral, how I can verify one post’s score by hand, and how I should critique negation and unrelated uses of Rhode. Identify any remaining limitations. Keep your explanation simple and suggest a specific improvement without inventing data or findings.
Send that prompt to the assistant, read the response, then record what actually changed here: [second prompt used, response summary, revision accepted or rejected, and why]. Screenshot both exchanges for the discussion. Proposed prompts do not count as completed exchanges.
Silge, J., & Robinson, D. (2017). Text mining with R: A tidy approach. O’Reilly Media. Chapter 2: https://www.tidytextmining.com/sentiment.
Plotly. (n.d.). Getting started with Plotly in R. https://plotly.com/r/getting-started/.
Gruber, J., & Guinaudeau, B. (n.d.). atrrr: Basic usage. https://jbgruber.github.io/atrrr/articles/Basic_Usage.html.
ChatGPT assisted with code and a reflection scaffold. R performs the calculations; the student reviews relevance and labels, checks arithmetic, critiques the results, and writes the final reflection. Update this disclosure to match the work done.
sessionInfo()
## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
## [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
## [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
##
## time zone: UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] tidytext_0.4.3 stringr_1.6.0 tidyr_1.3.2 dplyr_1.2.1
##
## loaded via a namespace (and not attached):
## [1] Matrix_1.7-6 gtable_0.3.6 jsonlite_2.0.0
## [4] janeaustenr_1.0.0 compiler_4.6.2 tidyselect_1.2.1
## [7] Rcpp_1.1.2 jquerylib_0.1.4 scales_1.4.0
## [10] yaml_2.3.12 fastmap_1.2.0 lattice_0.23-1
## [13] ggplot2_4.0.4 R6_2.6.1 SnowballC_0.7.1
## [16] generics_0.1.4 knitr_1.52 htmlwidgets_1.6.4
## [19] tibble_3.3.1 RColorBrewer_1.1-3 bslib_0.12.0
## [22] pillar_1.11.1 tokenizers_0.3.0 rlang_1.3.0
## [25] cachem_1.1.0 stringi_1.8.9 xfun_0.62
## [28] S7_0.2.2 sass_0.4.10 otel_0.3.0
## [31] viridisLite_0.4.3 plotly_4.12.1 cli_3.6.6
## [34] withr_3.0.3 magrittr_2.0.5 crosstalk_1.2.2
## [37] digest_0.6.39 grid_4.6.2 rstudioapi_0.19.0
## [40] lifecycle_1.0.5 vctrs_0.7.3 data.table_1.18.6.1
## [43] evaluate_1.0.5 glue_1.8.1 farver_2.1.2
## [46] httr_1.4.9 rmarkdown_2.32 purrr_1.2.2
## [49] tools_4.6.2 pkgconfig_2.0.3 htmltools_0.5.9