DS4 - Song Simulation

05/16/2024

What is the likelihood of a song of a genre being played?

First we upload the data and download/load in tidyverse
install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Then we get R to read and rename the data, and after we can check the first few lines
df <- read_csv("Playlist_Clean_(2).csv")
## Rows: 175 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Genre, Artist, Song
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(df)
## # A tibble: 6 × 3
##   Genre                    Artist         Song                          
##   <chr>                    <chr>          <chr>                         
## 1 Genre 1 - hiphop/rap     8k             When you call                 
## 2 Genre 2 - pop/kpop/Latin Yonaguni       bad bunny                     
## 3 Genre 1 - hiphop/rap     $uicideboy$    Diemonds                      
## 4 Genre 1 - hiphop/rap     $uicideboy$    Not Even Ghosts Are This Empty
## 5 Genre 1 - hiphop/rap     03 Greedo      Trap House                    
## 6 Genre 5 - alt/indie/folk 10,000 Maniacs Trouble Me
change the genre column into a factor, check again then count the songs in each genre
df$Genre <- as.factor(df$Genre)
head(df)
## # A tibble: 6 × 3
##   Genre                    Artist         Song                          
##   <fct>                    <chr>          <chr>                         
## 1 Genre 1 - hiphop/rap     8k             When you call                 
## 2 Genre 2 - pop/kpop/Latin Yonaguni       bad bunny                     
## 3 Genre 1 - hiphop/rap     $uicideboy$    Diemonds                      
## 4 Genre 1 - hiphop/rap     $uicideboy$    Not Even Ghosts Are This Empty
## 5 Genre 1 - hiphop/rap     03 Greedo      Trap House                    
## 6 Genre 5 - alt/indie/folk 10,000 Maniacs Trouble Me
df %>% count(Genre)
## # A tibble: 6 × 2
##   Genre                        n
##   <fct>                    <int>
## 1 Genre 1 - hiphop/rap        58
## 2 Genre 2 - pop/kpop/Latin    25
## 3 Genre 3 -  house/ska         5
## 4 Genre 4 -  rnb/soul         14
## 5 Genre 5 - alt/indie/folk    45
## 6 Genre 6 - country/rock      28
Taking this data we can use it to find the theoretical probabilities. To do this we create a new column in our table and use mutate along with the operation n/sum(n) to get percentages. Since these percentages are hella long we also round it to the 2nd decimal
genre_counts <- df %>% count(Genre)
genre_counts <- genre_counts %>% mutate(prob = n/sum(n))
genre_counts$prob <- round(genre_counts$prob, 2)
genre_counts
## # A tibble: 6 × 3
##   Genre                        n  prob
##   <fct>                    <int> <dbl>
## 1 Genre 1 - hiphop/rap        58  0.33
## 2 Genre 2 - pop/kpop/Latin    25  0.14
## 3 Genre 3 -  house/ska         5  0.03
## 4 Genre 4 -  rnb/soul         14  0.08
## 5 Genre 5 - alt/indie/folk    45  0.26
## 6 Genre 6 - country/rock      28  0.16

Interpretation

my interpretation of this data is that you are most likely to hear hiphop/rap or alt/indie when putting this playlist on shuffle and you are least likely to hear house/ska

Calculating Experimental Probabilities

our next task is to simulate how shuffle works by pulling a random sample of songs and saving it as a new table

sample <- sample_n(df,10)
sample
## # A tibble: 10 × 3
##    Genre                    Artist           Song                       
##    <fct>                    <chr>            <chr>                      
##  1 Genre 1 - hiphop/rap     Polo G           Martin and Gina            
##  2 Genre 1 - hiphop/rap     drake            pipe down                  
##  3 Genre 1 - hiphop/rap     NLE choppa       Shotta Flow 3              
##  4 Genre 5 - alt/indie/folk Yot club         Ykwim?                     
##  5 Genre 2 - pop/kpop/Latin Taylor Swift     Style                      
##  6 Genre 6 - country/rock   VIOLENT MIRA     I Don't Care               
##  7 Genre 5 - alt/indie/folk Surf Curse       Freaks                     
##  8 Genre 6 - country/rock   Three Days Grace I Hate Everything About You
##  9 Genre 5 - alt/indie/folk Arctic Monkeys   When the sun comes down    
## 10 Genre 2 - pop/kpop/Latin Ice Paper        Talking to the moon

Now I will adjust this table to show me just the genres and their probabilities.

sample_counts <- sample %>% count(Genre) %>% mutate(probability = n/sum(n))

Disscussing results

Are your song genres representative of the song genres in your playlist? Why or why or why not?

I noticed in my genre sample that there is no genre 2 from the playlist (which is pop kpop and latin) i think this is interesting as i feel like pop or kpop at least would show up a bit more since they seem to be more listened to genres or more played genres overall for alot of people. Rap taking the top isn’t that surprising though, and indie being the follow up is also not that surprising. I think having country and rock together does confuse the data a bit since i think rock has made a resurgence so i could see it beating out pop but country being in it aswell is a little funny

Compare your theoretical probabilities with your experimental probabilities - why might they be different? What could we do to make them more similar?

Comparing theoretical and experimental probabilities shows similar numbers with rap being the most likely and indie being close runner up. On the smaller scale some of the numbers are more evened out at the end with most having a 10% likelihood making it equally probable to get them however looking at the actual data there is variation in some of the genres near the bottom. For example in the sample you have the same likelihood to have ska or soul whereas in actuality pop would be more probable than either of them yet on the sample it doesn’t even appear and wouldn’t even be played at all.

More Simulations and Data Collection

sample_n(df, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 4 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap         9        0.45
## 2 Genre 3 -  house/ska         1        0.05
## 3 Genre 5 - alt/indie/folk     5        0.25
## 4 Genre 6 - country/rock       5        0.25
sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        13        0.43
## 2 Genre 2 - pop/kpop/Latin     1        0.03
## 3 Genre 4 -  rnb/soul          2        0.07
## 4 Genre 5 - alt/indie/folk     8        0.27
## 5 Genre 6 - country/rock       6        0.2
sample_n(df, 40) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        18        0.45
## 2 Genre 2 - pop/kpop/Latin     3        0.07
## 3 Genre 3 -  house/ska         1        0.03
## 4 Genre 4 -  rnb/soul          2        0.05
## 5 Genre 5 - alt/indie/folk     8        0.2 
## 6 Genre 6 - country/rock       8        0.2
sample_n(df, 75) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        24        0.32
## 2 Genre 2 - pop/kpop/Latin    11        0.15
## 3 Genre 3 -  house/ska         4        0.05
## 4 Genre 4 -  rnb/soul          5        0.07
## 5 Genre 5 - alt/indie/folk    23        0.31
## 6 Genre 6 - country/rock       8        0.11
sample_n(df, 86) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        36        0.42
## 2 Genre 2 - pop/kpop/Latin    10        0.12
## 3 Genre 3 -  house/ska         3        0.03
## 4 Genre 4 -  rnb/soul          7        0.08
## 5 Genre 5 - alt/indie/folk    18        0.21
## 6 Genre 6 - country/rock      12        0.14
sample_n(df, 100) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        35        0.35
## 2 Genre 2 - pop/kpop/Latin    16        0.16
## 3 Genre 3 -  house/ska         5        0.05
## 4 Genre 4 -  rnb/soul          4        0.04
## 5 Genre 5 - alt/indie/folk    26        0.26
## 6 Genre 6 - country/rock      14        0.14

Analyze and Synthesize

Answer to unit question: As I previously assumed, if you listen to more songs on shuffle the distributions of genres become more accurate to the actual data however there are a few outliers and minor changes between genres, but they aren’t incredibly different but rather 2 genres being about equal but switching from rank between a few data sets. Overall there were specific genres that were consistently the least played or most played on shuffle and those were also the ones that were either majority or complete minority in the full data set, other than this most of the middle range of genres would differ from data set to data set in amount played. This leads me to the conclusion that it can represent the more extreme sides of the genre popularity but going more into the middle ground many of the datasets provide a more murky idea of the accurate genre distribution
What data do you have to support your response?: As seen in the multiple charts the probability of getting hip hop/rap was consistently the highest amount with a close follow up of indie/alt (majority of the time) which was the same as the experimental value of the dataset. Ska was sadly most commonly the lowest probable genre across the board minus a few outliers that indicate that if one listens to only a few ~10 theyd get a very general idea of the genre distribution in the genres that are very dominant whereas the middle area of genre distribution is a little more random and shows a fuzzier idea of the genre distribution.
What did you learn about experimental and theoretical probability and how do they apply to this situation?: I learned that they dont always line up and theoretical data probability is way more important to get an accurate idea of the actual true distribution than i had before realized. This is mainly from the fact that the genre that appeared around the higher end of the scale in the actual and higher data values wasnt even shown or represented in the smallest (10) data set.

Reflection

In what ways did coding a simulation support you in answering the unit question? What else might you use simulations for?
What piece of code was most challenging for you to write?: Every single piece of it
What piece of your code do you feel most proud of? Why?: I think just in general when certain things started to click and not js look like a bunch of jumbled symbolsput for no reason i felt hella chill
What is something in programming that you would like to learn more about?: I think actually learning to code n stuff like that in this context would be cool since im lowkey a big fan of data and like averages or probability and that typa stuff
Is there anything you would do differently if you were to do this again?: I’d probably try and not put it off for so long, granted before i really sat down and hella tried i was really lost and overwhelmed by everything but once i got it i felt mad accomplished
Do you have any remaining thoughts or questions around this?: While its cool n stuff i think i like the simpler stuff like google sheets personally so im js gonna stick w dat T^T