1.1 Analyzing the impact of danceability and energy levels on the popularity of songs across various genres and subgenres to understand the influence of musical attributes on listener engagement and preferences. This analysis can offer a deeper understanding of how specific musical attributes contribute to a song’s appeal and resonance among different groups of listeners, potentially unveiling trends and preferences within the music industry.
1.2 To address this problem statement, I plan to utilize the Spotify dataset “spotify_songs.csv,” which contains a comprehensive collection of variables related to song attributes, popularity, and playlist information. The approach will include conducting exploratory data analysis to examine the correlation between danceability, energy levels, and song popularity within different music genres and subgenres. This process will incorporate the use of statistical measures and data visualization methods to identify trends and gain insights into the influence of distinct musical attributes on listener engagement and preferences.
1.3 This analysis will provide valuable insights for music industry professionals, including record labels, artists, and streaming platforms, allowing them to make informed decisions about song production, marketing strategies, and playlist curation. By comprehending how danceability and energy levels impact the popularity of songs and listener engagement, these stakeholders can customize their content and marketing strategies to align more closely with the preferences of their target audience, thus enhancing the likelihood of creating successful and broadly appreciated music.
2.1 Load necessary packages
library(dplyr) #For data manipulation and visualization
library(lubridate) #For handling date-time data
library(ggplot2) #For basic data visualization
library(readr) #For reading data into R
library(tidyr) #For tidying and reshaping data
2.2 Suppress messages and warnings suppressMessages(library(dplyr)) suppressMessages(library(lubridate)) suppressMessages(library(ggplot2)) suppressMessages(library(readr)) suppressMessages(library(tidyr))
2.3 Explanation of the purpose of each package
dplyr: This package provides a grammar of data manipulation, offering a consistent set of verbs that help in solving common data manipulation challenges.
lubridate: This package facilitates the handling of date-time data in R, allowing for easy and efficient operations involving dates and times.
ggplot2: A popular package used for creating basic data visualizations in R, which allows for the creation of a wide range of graphical representations, such as scatter plots, bar plots, and line plots.
readr: This package provides a fast and friendly way to read rectangular data (like csv, tsv, and fwf) into R, making the process of data importation and reading more convenient.
tidyr: This package allows for easy tidying and reshaping of data, aiding in the process of transforming data into a tidy format for better analysis and visualization.
3.1 Data Import and Initial Inspection # Load the dataset spotify_data <- read.csv(“spotify_songs.csv”)
str(spotify_data)
#Display the structure of the data
summary(spotify_data)
#Display the summary of the data
The initial dataset “spotify_songs.csv” contains 23 variables. These variables include the following:
track_id - Song unique IDtrack_name - Song nametrack_artist - Song artisttrack_popularity - Song popularity on a scale of
0-100track_album_id - Album unique IDtrack_album_name - Song album nametrack_album_release_date - Date when the album was
releasedplaylist_name - Name of the playlistplaylist_id - Playlist IDplaylist_genre - Playlist genreplaylist_subgenre - Playlist subgenredanceability - Measure of how suitable a track is for
dancingenergy - Measure of intensity and activity in the
trackkey - The estimated overall key of the trackloudness - The overall loudness of the track in
decibels (dB)mode - Indicates the modality (major or minor) of the
trackspeechiness - Detects the presence of spoken words in
the trackacousticness - Confidence measure of whether the track
is acousticinstrumentalness - Predicts whether a track contains no
vocalsliveness - Detects the presence of an audience in the
recordingvalence - Measure of the musical positiveness conveyed
by a tracktempo - The overall estimated tempo of the track in
beats per minute (BPM)duration_ms - Duration of the song in millisecondsRegarding missing values, the dataset appears to contain no specific peculiarities in terms of how missing values are recorded. However, a closer examination during the data cleaning process will confirm whether any missing values exist and how they are handled.
3.2 Data Cleaning
Check for missing values
missing_values <- sum(is.na(spotify_data))
#We want to ensure that the dataset does not contain any missing values that might affect our analysis.
Remove any duplicate rows
spotify_data <- spotify_data[!duplicated(spotify_data), ]
#Duplicate rows can skew our analysis and provide misleading insights. It’s crucial to remove them.
Convert date-related columns to appropriate date format
spotify_data\(track_album_release_date <- as.Date(spotify_data\)track_album_release_date, format = “%Y-%m-%d”)
#To perform any time-related analysis, it’s important to convert date columns to the appropriate date format.
3.3 Display Cleaned Data (Top 10 Observations)
head(spotify_data, 10)
#Display the first 10 rows of the cleaned dataset to examine the changes after data cleaning.
3.4 Summary Information To gain a better understanding of our cleaned dataset, I have summarized the key variables of interest. Here is a table presenting the summary statistics for each variable:
| Variable | Mean | Median | Standard Deviation |
|---|---|---|---|
| track_popularity | 62.48 | 64 | 14.21 |
| danceability | 0.619 | 0.624 | 0.161 |
| energy | 0.721 | 0.742 | 0.166 |
| key | 5.37 | 5 | 3.67 |
| loudness | -5.61 | -5.54 | 2.19 |
| mode | 0.71 | 1 | 0.45 |
| speechiness | 0.093 | 0.0462 | 0.0869 |
| acousticness | 0.202 | 0.117 | 0.229 |
| instrumentalness | 0.122 | 0 | 0.297 |
| liveness | 0.190 | 0.121 | 0.153 |
| valence | 0.496 | 0.497 | 0.246 |
| tempo | 121.63 | 123.97 | 29.98 |
| duration_ms | 218387.38 | 213040 | 60450.90 |
#The table includes the mean, median, and standard deviation for each variable, allowing us to grasp the central tendency and variability of the key attributes in our dataset.
spotify_data <- spotify_data
4.1 Data Exploration Strategies
To answer the questions regarding the impact of danceability and energy on song popularity, we can employ various strategies:
Slicing and Dicing
Creating New Variables
Joining DataFrames
Scatter Plots
4.2 Box Plots and Bar Plots Illustrate the distributions of danceability,
energy, and popularity across different genres using box plots and bar
plots.
4.3 Learning Objectives
To enhance the analysis, there is a need to learn:
4.4 Linear Regression We have already conducted a linear
regression analysis to understand the relationships between
danceability, energy, and popularity: library(plotly)
5.1 Summarize the Problem Statement
The problem addressed in this analysis is understanding the impact of danceability and energy levels on the popularity of songs across various genres and subgenres. The goal is to unveil trends and preferences within the music industry based on these specific musical attributes.
5.2 Methodology Employed
To address this problem statement, we utilized the Spotify dataset “spotify_songs.csv.” The methodology involved exploratory data analysis, including correlation analysis, genre-based exploration, and linear regression. Various strategies, such as slicing and dicing the data by genre and creating new variables, were employed to gain insights into the relationships between danceability, energy, and song popularity.
5.3 Interesting Insights
5.4 Implications to the Consumer
This analysis offers valuable insights for music industry professionals, including record labels, artists, and streaming platforms. Understanding how danceability and energy levels impact song popularity enables stakeholders to make informed decisions about song production, marketing strategies, and playlist curation. This customization aligns more closely with the preferences of the target audience, enhancing the likelihood of creating successful and broadly appreciated music.
5.5 Limitations of the Analysis
Set working directory setwd(“/Users/apple/Desktop/B BUS301/Midterm_Project”)
Load required libraries library(tidyverse) # Loading the tidyverse package # Install the plotly package install.packages(“plotly”)
Read the rds file and create a data frame called acs spotify_data <- read.csv(“spotify_songs.csv”) # Correlation between danceability, energy, and popularity correlation_matrix <- cor(spotify_data[, c(“danceability”, “energy”, “track_popularity”)])
Print correlation matrix print(correlation_matrix)
Create subsets based on genres genre_subset <- spotify_data %>% group_by(playlist_genre)
Summary statistics by genre summary_by_genre <- summarise(genre_subset, avg_danceability = mean(danceability), avg_energy = mean(energy), avg_popularity = mean(track_popularity))
Print summary by genre print(summary_by_genre)
Scatter plot of danceability vs. popularity ggplot(spotify_data, aes(x = danceability, y = track_popularity)) + geom_point() + labs(title = “Danceability vs. Popularity”, x = “Danceability”, y = “Popularity”)
Box plot of energy by genre ggplot(spotify_data, aes(x = playlist_genre, y = energy)) + geom_boxplot() + labs(title = “Energy Distribution by Genre”, x = “Genre”, y = “Energy”) library(plotly)
Scatter plot with interactive tooltips plot_ly(data = spotify_data, x = ~danceability, y = ~track_popularity, type = ‘scatter’, mode = ‘markers’, text = ~track_name, marker = list(size = 8)) %>% layout(title = “Interactive Danceability vs. Popularity”, xaxis = list(title = “Danceability”), yaxis = list(title = “Popularity”))
Linear regression model lm_model <- lm(track_popularity ~ danceability + energy, data = spotify_data)
Summary of the linear regression model summary(lm_model)