2026-10-18

Explanation

As an avid music listener, it is always fascinating to see what exactly makes a song popular.

Energy vs Popularity will be evaluated from this Spotify Tracks Dataset, where energy is measured from perceived intensity scores on a 0-1 scale, and popularity is measured from scores on on a 0-100 scale.

The correlation and linear regression will be explored between these two observations of Spotify tracks.

Correlation

To measure how energy (x) and population (y) change together, the correlation coefficient, r should be measured. \[ r = \frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})} {\sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2 \sum_{i=1}^{n}(y_i-\bar{y})^2}} \]

  • r ranges from [-1, 1]
  • being close to -1 is negative correlation
  • being close 1 is positive correlation
  • close to 0 is no correlation

Linear Regression

From a graphed correlation, a line may be able to fit the data found, and in this case popularity may be estimated from energy \[ \hat{y} = b_0 + b_1x \]

  • \(x\) = energy
  • \(\hat{y}\) = predicted popularity
  • \(b_0\) = intercept
  • \(b_1\) = slope

Slide with R Output

Below is the code for calculating the correlation between energy vs population.

cor(spotify$energy, spotify$popularity)
## [1] 0.001056136

Below is the code for calculating the linear regression model for energy vs population.

model <- lm(popularity ~ energy, data = spotify)
summary(model)
## 
## Call:
## lm(formula = popularity ~ energy, data = spotify)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -33.272 -16.248   1.728  16.763  66.777 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 33.17847    0.18095 183.362   <2e-16 ***
## energy       0.09366    0.26264   0.357    0.721    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 22.31 on 113998 degrees of freedom
## Multiple R-squared:  1.115e-06,  Adjusted R-squared:  -7.657e-06 
## F-statistic: 0.1272 on 1 and 113998 DF,  p-value: 0.7214

GGplot 1: Histogram

This histogram shows the frequency of songs that are in each energy level, showing which energy levels might be more common.

In general, higher energy level songs occur more in this data set, which may affect the results.

GGplot 2: Scatterplot/Linear Regression Model

This scatterplot/LR model shows almost no meaningful relationship between song energy and popularity, nor shows that there is a cause between the two.

Plotly: Box Plot

Grouping the songs into low, medium, and high categories, there are higher medians and averages for popularity scores of medium-energy songs than the rest of the energy gropu categories. Box plot stats may be viewed by hovering over the graph.

Conclusion

As the correlation coefficient calculated only slightly leans towards 1 at 0.56, it is still close to zero, especially made apparent by the graph showing that there may be no correlation between energy of a song and popularity.

The fact that there are more existing higher energy songs in the dataset may be a significant factor of a slight correlation at 0.56.

The box plot showed medium energy songs to have the highest popularity scores, showing that there truly was not a decreasing or increasing relationship between energy and popularity.

Spotify dataset from: https://www.kaggle.com/datasets/maharshipandya/-spotify-tracks-dataset?utm_source=chatgpt.com