Week 7 Exercises - Does the Algorithm Know What a Hit Is?
R², adjusted R², and the predictor nobody wants to talk about
About 45 minutes · Pairs or small groups · 🧰 R (tidyverse, rio, here, broom) or JAMOVI
Every step is given both ways.
- Part A: Follow along (~15 min): can danceability predict streams?
- Part B: On your own (~20 min): throw four audio features at it, then find the one variable that actually works.
- Part C: Together (~10 min): the uncomfortable conclusion.
By the end you should be able to:
- Read R², adjusted R² and the residual standard error off any model output
- Say what a small R² means in the units of the outcome, not just as a percentage
- Explain why a significant predictor can be a nearly useless one
- Show that R² never decreases when you add a predictor, and that adjusted R² can
- Decide whether a model that fits well is actually telling you anything
Set up (5 min)
Download the data into the
datafolder of your PSYC 640 R Project.New Quarto document,
Week 7 - Model Fit, saved asweek7_inclass.qmd.
library(tidyverse)
library(rio)
library(here)
library(broom)
spotify <- import(here("data", "popular_spotify.csv")) %>%
janitor::clean_names() %>%
mutate(streams = as.numeric(streams),
streams_m = streams / 1e6) # streams in millions, easier to read
glimpse(spotify)952 songs. streams_m should run from under 1 million to about 3,700 million, with an SD of about 567.
- ☰ Menu → Open → Browse →
popular_spotify.csv - Data → Compute → new variable
streams_mwith the formulastreams / 1000000 - Check that
streams_mand the%variables are Continuous.
About the data. 952 of the most-streamed songs on Spotify, with audio features scored 0–100 by Spotify’s own algorithm: danceability_percent, energy_percent, valence_percent (how upbeat it sounds), acousticness_percent, and more.
Part A — Follow along: can danceability predict streams? (15 min)
Research question: Do more danceable songs get streamed more?
fit_dance <- lm(streams_m ~ danceability_percent, data = spotify)
summary(fit_dance)Analyses → Regression → Linear Regression. Dependent streams_m, Covariates danceability_percent. Under Model Fit, tick R², Adjusted R² and RMSE.
b = −4.09, t(950) = −3.27, p = .001 · R² = .011 · residual SE ≈ 564
❓Questions for Part A
- The slope is significant. Write the sentence a journalist would write about this finding.
- Now write the sentence a statistician would write. What does R² = .011 add?
- The SD of
streams_mis 567. The residual standard error is 564. In plain language, how much better is this model than guessing the mean for every song? - With n = 952, is it surprising that p = .001? What would have happened with n = 50?
Part B — On your own: more features, better model? (20 min)
Step 1: Throw everything at it
Fit a model with four audio features: danceability, energy, valence, and acousticness.
# Your code herePut all four in Covariates. Better still: use Model Builder — Block 1 = danceability, Block 2 = the other three — and tick Model Comparisons to get ΔR² directly.
R² = .013 · adjusted R² = .0088 · and only danceability is significant.
Compare to the one-predictor model: R² = .0111, adjusted R² = .0101.
❓Questions
- R² went up (.0111 → .0130) but adjusted R² went down (.0101 → .0088). Explain how both of those can be true at once.
- Three of the four predictors are not significant. What did adding them buy you?
- If a colleague showed you only the R² values and said “see, the bigger model is better,” what would you say?
Step 2: Find the variable that actually works
The dataset has a column called in_spotify_playlists — the number of playlists the song appears on. Fit:
# streams_m ~ in_spotify_playlistsR² = .624 · residual SE ≈ 348 · b = 0.057, t(950) = 39.7
❓Questions
- Compare this R² to the four-feature model. What does 62% vs 1% mean in plain language?
- The residual SE dropped from 564 to 348. Restate that in terms of how wrong you tend to be about a song.
- Add
danceability_percentto this model. What happens to R², to adjusted R², and to danceability’s p-value? Why?
Part C — Together: the uncomfortable conclusion (10 min)
We have a model that explains 62% of the variance in streams. That is a very good fit by psychology standards.
Songs on more playlists get streamed more.
❓Questions for Part C
- Is
in_spotify_playlistsa cause of streams, a consequence of streams, or both? Explain the feedback loop. - Which model would you rather have for predicting next month’s streams? Which would you rather have for understanding why a song succeeds? Are they the same model?
- A record label asks you: “should we make our songs more danceable?” Answer using numbers from today — and say what the data can and cannot support.
- Write one sentence that uses R² honestly in each direction: one where a small R² is still interesting, and one where a large R² is not.
R² measures how well a model tracks the outcome. It says nothing about whether the model explains why, and nothing about whether anyone can act on it. A high R² from a variable that is partly the outcome in disguise is a warning sign, not a trophy.
Exit ticket ✅
- Explain R² in one sentence to someone who has never taken statistics.
- Why can a predictor be statistically significant and still barely improve a model?
- One thing that is still muddy → journal.