R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

spotify2023 <- read.csv("C:/Users/Jjtra/Desktop/spotify4220/spotify2023.csv")
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Question 1

First graph is an extremely simple histogram that looks at spotify chart rankings. In this graph, it is skewed right due to many songs being extremely high in both chart ranking and the frequency of those songs.

The second graph displays a scatter plot that compares chart rankings in accordance to the perceived energy of the song. Energy in this case being something like being very active/generating hype, not to be confused with valence (positivity) and danceability. Each point is a song that shows both the ranking and amount of energy. As you can see, many high ranking songs are also high in energy.

ggplot(spotify2023, aes(energy_.,in_spotify_charts)) + 
  labs(title = "Energy and Spotify Chart Ranking", x = "Energy", y = "Chart Ranking") +
  geom_point(aes(colour = 'red'))

Question 2: Mean

Below is a simple mean of energy of the most popular songs in Spotify 2023. If you compare the mean to the previous graph, it does show that most songs have the energy between 50 and 75, albeit, hard to exactly conclude. The mean being 64 sort of supports this.

energy_mean <- mean(spotify2023$energy_.)
energy_mean
## [1] 64.27912

Question 3: Correlation Test using Pearson

I used the Pearson method to find correlation between the energy and dancbility of songs. According to the results, the p-value for this test is less than 5%, which means there is a correlation between the energy and danceability. In other words, the energy percieved directly or closely interacts danceability (ex. high energy means higher danceability of a song). This also rejects the null hypothesis, which in this case was that energy and danceability has little to no correalation.

cor.test(spotify2023$danceability_.,spotify2023$energy_., method = 'pearson')
## 
##  Pearson's product-moment correlation
## 
## data:  spotify2023$danceability_. and spotify2023$energy_.
## t = 6.2324, df = 951, p-value = 6.893e-10
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1363055 0.2583489
## sample estimates:
##       cor 
## 0.1980948

Question 4: T-Test

This is a 2 sample t-test between popular songs between the years 2016-2019 and 2020-2023. The hypothesis for this test is to see if more relevant songs have more energy than pre-2020 songs. The Null Hypothesis in this case would be the opposite, other wise meaning that pre-2020 songs have a higher energy perception than the more relevent songs. The p-value in this case is just below .05, which means that we can reject the null hypothesis. The mean value for x (post-2020) is higher than y (pre-2020). As for the exact reason as to it is significant why is unknown (could be due to key and mode).

spotge2019 <- filter(spotify2023, released_year > 2019)
spotle2016 <- filter(spotify2023, released_year <= 2019 & released_year >= 2016)
t.test(spotge2019$energy_., spotle2016$energy_.)
## 
##  Welch Two Sample t-test
## 
## data:  spotge2019$energy_. and spotle2016$energy_.
## t = 2.7057, df = 104.39, p-value = 0.007963
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  1.402859 9.100849
## sample estimates:
## mean of x mean of y 
##  64.88404  59.63218

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.