2026-10-17

Background + Driving Question

The tidytuesday repository of GitHub’s rfordatascience community sports an impressive roster of diverse datasets, including a dataset recording 28356 unique songs from Spotify.

Recorded variables include the following: song popularity (ranked 0-100, where higher is more popular), danceability (based on rhythmic stability), loudness, tempo, and duration.

With this in mind, how does the loudness of a song relate to its popularity within a genre? We will focus on loudness in this analysis. We will conduct analyses across all genres, not focusing on one specific genre.

Statistical Content: Setup + Takeaway

  • Goal: analyze how loudness correlates with track_popularity per genre.
  • Modeling: use simple linear regression to evaluate how loudness impacts popularity while keeping musical genre controlled.
  • Main takeaway: understand the mathematical metrics behind listener engagement within popular music on streaming services like Spotify.

Understanding how loudness correlates (or does not correlate) with popularity can help put into perspective what production/mixing/mastering styles people find compelling. The Loudness War has been a longstanding debate about whether or not loud music is better/popular, so analyzing this data can contribute to settling this debate. (In addition, viewing music through these metrics can help listeners objectively perceive their music taste. For example, a genre like progressive metal can trend high with loudness and duration, but lower on danceability.)

Mathematical Content: Single Linear Regression

To model song popularity (\(Y\)), we will first postulate the population regression model:

\[Y_i = \beta_0 + \beta_1 X_i + \epsilon_i\] Where:

  • \(Y_i\) = Popularity score of song \(i\) (dependent variable, scored 1-100)
  • \(X_i\) = Loudness of song \(i\) in dB (independent variable)
  • \(\beta_0\) = Population y-intercept (expected popularity when loudness is zero)
  • \(\beta_1\) = Population slope coefficient (expected changed in popularity per 1 dB increase in loudness)
  • \(\epsilon_i\) = Random error term, or residual

Mathematical Content: Minimizing Residual Errors

To estimate the optimal intercept and slope (\(\widehat{\beta}_0, \widehat{\beta}_1\)), here is the Sum of Squared Errors (SSE), sourcing information from our original song popularity regression model.

\[\text{SSE} = \sum_{i=1}^{n} (y_i - \widehat{y}_i)^2 = \sum_{i=1}^{n} \left( y_i - (\widehat{\beta}_0 + \widehat{\beta}_1 x_{i}) \right)^2\] Where:

  • \(y_i\) = Actual observed popularity score of song \(i\)
  • \(\widehat{y}_i\) = Predicted popularity score from regression model
  • \(n\) = Total number of unique tracks in our dataset (with approximately 4500 duplicates removed)
  • \(\widehat{\beta}_0, \widehat{\beta}_1\) = Estimated parameters that minimize the overall error distance

Our expected value \(\widehat{y}_i\) is what our song popularity model estimates. This is why we plug in \((\widehat{\beta}_0 + \widehat{\beta}_1 x_{i})\) for \(\widehat{y}_i\) to get the above formula.

R Code: Simple Linear Regression Model

# Load dplyr: necessary for pipe operator and distinct() function
library(dplyr)

# Remove the duplicate songs from the original spotify_songs dataset
spotify_unique <- spotify_songs %>%
  distinct(track_id, .keep_all = TRUE)

# Create popularity model versus the loudness (updated dataset)
model <- lm(track_popularity ~ loudness,
            data = spotify_unique)

# Create summary
summary(model)

ggplot2 Visualization 1: Scatterplot of Popularity vs. Loudness

ggplot2 Visualization 2: Loudness Boxplot Distributions per Genre

Plotly Visualization: Loudness AND Energy vs. Popularity

Communication and Conclusions

The three visualizations (scatterplot of popularity vs. loudness by genre, the loudness distributions by genre, and popularity vs. combination of loudness and energy) demonstrate that there is not a clear statistical relationship between song popularity and loudness. The visualizations showcase this in several ways.

The scatterplot prompts two main observations: the individual data points form a colorful blob of indistinguishable patterns, and the trendlines for each genre have different directions and all exist between 25-50 popularity. For some genres, there is a weak positive relationship between loudness and popularity; for others, there is a weak negative relationship; and the remaining genres have no relationship. The differing signs in the trendlines per genre show that there is no clear relationship between loudness and popularity.

The boxplot of loudness distributions per genre supports the observations from the scatterplot, especially by comparing how the median loudness levels per genre compare to the direction of their trendline on the scatterplot. For example, the loudest (by median) genre in the dataset is EDM, and its trendline in the scatterplot is nearly flat. The second and third loudest genres are latin and pop, and their trendlines in the scatterplot are clearly positive. The next loudest genre is rap, with a clearly negative trendline. This shows that the loudness of a genre does not predict how loudness and popularity correlate, further supporting that loudness and popularity are unrelated metrics.

The 3D plot demonstrates that loudness and energy have a positive correlation, but not loudness and popularity. This visualization proves that loudness can correlate with other factors in the dataset, but not necessarily popularity. Looking at the graph with popularity as the z-axis shows a positive relationship on the bottom 2D plane. As loudness approaches 0 dB, energy approaches 1 on a 0-1 scale. This relationship, however, extends throughout the height of the z-axis. Therefore, although loudness and genre have a correlation across popularity level, loudness does not have a correlation with popularity itself.

The above data analysis, visualizations, and conclusions show that loudness and popularity (controlled for genre) do not have a clear correlation. A song is not considered “better” by the public for having a higher volume on average.