In this activity, I explored how to calculate theoretical probabilities in a data set. In my group, we explored the question “What is the likelihood of a song of each genre being played?” in order to find data to answer the Essential Question of the unit:
We collected our data by having each student (anonymously) submit 5-10 songs onto a playlist
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ 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
playlist_data <- read_csv("Group 2 Playlist Data - data_clean.csv", show_col_types = FALSE)
head(playlist_data)
## # A tibble: 6 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 1 - hiphop/rap Alesso When I'm Gone
## 2 Genre 1 - hiphop/rap Aliyah's Interlude It Girl
## 3 Genre 1 - hiphop/rap Big Sean Beware
## 4 Genre 1 - hiphop/rap Clipse Ma, I Don't Love Her
## 5 Genre 1 - hiphop/rap Common Be
## 6 Genre 1 - hiphop/rap Drake Nice For What
Before using the data, we decided to delete any repeated songs to ensure that there would be an even chance of every song being played. We also put the songs in order according to their genre, and changed the names of the genres from entire questions to a single word (ex: “What is the genre of the song?” -> “genre”)
To calculate the theoretical probability (as a percent), I found the number of songs in each genre and divided them by the total number of songs that we collected across all genres; then I multiplied by one hundred to convert the solutions to percentages. I did all of this using the following code:
# Number of songs in each genre
count(playlist_data, genre)
## # A tibble: 6 × 2
## genre n
## <chr> <int>
## 1 Genre 1 - hiphop/rap 26
## 2 Genre 2 - pop/kpop/Latin 22
## 3 Genre 3 - house/ska 5
## 4 Genre 4 - rnb/soul 43
## 5 Genre 5 - alt/indie/folk 34
## 6 Genre 6 - country/rock 14
# Number of songs in total
count(playlist_data)
## # A tibble: 1 × 1
## n
## <int>
## 1 144
# Theoretical Genre Probability
genre_probability <- count(playlist_data, genre)
genre_probability %>% mutate(probability=n/sum(n)*100)
## # A tibble: 6 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 26 18.1
## 2 Genre 2 - pop/kpop/Latin 22 15.3
## 3 Genre 3 - house/ska 5 3.47
## 4 Genre 4 - rnb/soul 43 29.9
## 5 Genre 5 - alt/indie/folk 34 23.6
## 6 Genre 6 - country/rock 14 9.72
playlist_data[sample(nrow(playlist_data), 10), ]
## # A tibble: 10 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 5 - alt/indie/folk Ginger Root Loretta
## 2 Genre 2 - pop/kpop/Latin Shinee Replay
## 3 Genre 4 - rnb/soul Brent Faiyaz Rehab
## 4 Genre 6 - country/rock Citizen Hyper Trophy
## 5 Genre 2 - pop/kpop/Latin Ariana Grande Honeymoon Avenue
## 6 Genre 4 - rnb/soul J. Cole In The Morning
## 7 Genre 4 - rnb/soul Queen Naija Medicine
## 8 Genre 5 - alt/indie/folk Taylor Swift Ivy
## 9 Genre 5 - alt/indie/folk Death Cab for Cutie No Sunlight
## 10 Genre 5 - alt/indie/folk Taylor Swift Peace
# Experimental genre probability (as a percent) = # of songs in genre/# of total songs*100
playlist_data[sample(nrow(playlist_data), 10), ]
## # A tibble: 10 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 4 - rnb/soul SZA Snooze
## 2 Genre 4 - rnb/soul Ella Mai Shot Clock
## 3 Genre 4 - rnb/soul SZA Normal Girl
## 4 Genre 5 - alt/indie/folk Thundercat Them Changes
## 5 Genre 4 - rnb/soul Lauryn Hill Doo Wop
## 6 Genre 4 - rnb/soul Frank Ocean Pyramids
## 7 Genre 5 - alt/indie/folk Cherry Glazerr Soft Drink
## 8 Genre 5 - alt/indie/folk The Weather Machine Back O'er Oregon
## 9 Genre 1 - hiphop/rap Isaiah Rashad Headshots
## 10 Genre 2 - pop/kpop/Latin Shinee Replay
experimental_probability <- playlist_data[sample(nrow(playlist_data), 10), ]
experimental_data_genre_probability <- count(experimental_probability, genre)
experimental_data_genre_probability %>% mutate(probability=n/sum(n)*100)
## # A tibble: 4 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 2 - pop/kpop/Latin 2 20
## 2 Genre 4 - rnb/soul 6 60
## 3 Genre 5 - alt/indie/folk 1 10
## 4 Genre 6 - country/rock 1 10
To gather some more experimental data from the whole class, my table each did a ten-song-sample and we combined our results to gather the following n probabilities:
(12/60)*100
## [1] 20
( 8/60)*100
## [1] 13.33333
( 2/60)*100
## [1] 3.333333
(20/60)*100
## [1] 33.33333
(12/60)*100
## [1] 20
( 6/60)*100
## [1] 10
playlist_data[sample(nrow(playlist_data), 20), ]
## # A tibble: 20 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 5 - alt/indie/folk Rilo Kiley August
## 2 Genre 5 - alt/indie/folk Men I Trust Show Me How
## 3 Genre 1 - hiphop/rap Aliyah's Interlude It Girl
## 4 Genre 5 - alt/indie/folk Thundercat Them Changes
## 5 Genre 2 - pop/kpop/Latin Ariana Grande Everytime
## 6 Genre 4 - rnb/soul Leon Bridges River
## 7 Genre 6 - country/rock Luke Combs One Number Away
## 8 Genre 4 - rnb/soul Drake Look What You’ve Done
## 9 Genre 5 - alt/indie/folk Faye Webster A Dream With A Baseball Player
## 10 Genre 4 - rnb/soul Frank Ocean Pyramids
## 11 Genre 4 - rnb/soul Summer Walker To Summer, From Cole
## 12 Genre 1 - hiphop/rap Outkast Hey Ya
## 13 Genre 4 - rnb/soul SZA Kill Bill
## 14 Genre 3 - house/ska Beyonce My House
## 15 Genre 1 - hiphop/rap Little Simz Two Worlds Apart
## 16 Genre 2 - pop/kpop/Latin Natalia Lafourcade Hasta La Raiz
## 17 Genre 6 - country/rock Fleetwood Mac Everywhere
## 18 Genre 6 - country/rock Citizen Hyper Trophy
## 19 Genre 4 - rnb/soul Solange Don't Touch My Hair
## 20 Genre 4 - rnb/soul Nelccia Options
twenty_song_trial <- playlist_data[sample(nrow(playlist_data), 20), ]
twenty_song_trial <- count(twenty_song_trial, genre)
twenty_song_trial %>% mutate(probability=n/sum(n)*100)
## # A tibble: 6 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 4 20
## 2 Genre 2 - pop/kpop/Latin 1 5
## 3 Genre 3 - house/ska 2 10
## 4 Genre 4 - rnb/soul 7 35
## 5 Genre 5 - alt/indie/folk 3 15
## 6 Genre 6 - country/rock 3 15
playlist_data[sample(nrow(playlist_data), 60), ]
## # A tibble: 60 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 2 - pop/kpop/Latin J-Hope Safety Zone
## 2 Genre 2 - pop/kpop/Latin Bad Bunny Ojitos Lindos
## 3 Genre 5 - alt/indie/folk Lana Del Rey Million Dollar Man
## 4 Genre 3 - house/ska Sublime Garden Grove
## 5 Genre 5 - alt/indie/folk My Bloody Valentine To Here Knows When
## 6 Genre 5 - alt/indie/folk The Internet Under Control
## 7 Genre 1 - hiphop/rap Kanye West Devil In A New Dress
## 8 Genre 4 - rnb/soul Brent Faiyaz Rehab
## 9 Genre 4 - rnb/soul Kieth Sweat Get Up On It
## 10 Genre 4 - rnb/soul Solange Don't Touch My Hair
## # ℹ 50 more rows
sixty_song_trial <- playlist_data[sample(nrow(playlist_data), 60), ]
sixty_song_trial <- count(sixty_song_trial, genre)
sixty_song_trial %>% mutate(probability=n/sum(n)*100)
## # A tibble: 6 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 10 16.7
## 2 Genre 2 - pop/kpop/Latin 7 11.7
## 3 Genre 3 - house/ska 2 3.33
## 4 Genre 4 - rnb/soul 18 30
## 5 Genre 5 - alt/indie/folk 17 28.3
## 6 Genre 6 - country/rock 6 10
playlist_data[sample(nrow(playlist_data), 100), ]
## # A tibble: 100 × 3
## genre artist title
## <chr> <chr> <chr>
## 1 Genre 2 - pop/kpop/Latin Renee Rap Tummy Hurts
## 2 Genre 6 - country/rock Dolly Parton Nine To Five
## 3 Genre 6 - country/rock Dolly Parton Jolene
## 4 Genre 4 - rnb/soul Lauryn Hill Doo Wop
## 5 Genre 5 - alt/indie/folk Death Cab for Cutie No Sunlight
## 6 Genre 5 - alt/indie/folk My Bloody Valentine To Here Knows When
## 7 Genre 1 - hiphop/rap MF DOOM Doomsday
## 8 Genre 4 - rnb/soul Lauryn Hill Tell Him
## 9 Genre 4 - rnb/soul Nelccia Options
## 10 Genre 1 - hiphop/rap Little Simz Two Worlds Apart
## # ℹ 90 more rows
hundred_song_trial <- playlist_data[sample(nrow(playlist_data), 100), ]
hundred_song_trial <- count(hundred_song_trial, genre)
hundred_song_trial %>% mutate(probability=n/sum(n)*100)
## # A tibble: 6 × 3
## genre n probability
## <chr> <int> <dbl>
## 1 Genre 1 - hiphop/rap 17 17
## 2 Genre 2 - pop/kpop/Latin 14 14
## 3 Genre 3 - house/ska 4 4
## 4 Genre 4 - rnb/soul 28 28
## 5 Genre 5 - alt/indie/folk 24 24
## 6 Genre 6 - country/rock 13 13
The genres we hear played on shuffle match our class playlist’s genres better when more songs are played. When we sample a smaller amount of songs (compared to the total amount of songs on the playlist), the experimental probability is less likely to reflect the theoretical probability, as was shown in the twenty-song sample that was previously collected. When we sample a greater amount of songs from the playlist, it better reflects the theoretical probability of selecting a certain genre from the entire playlist, which the hundred-song sample veritably demonstrated. When collecting a smaller completely random sample from a larger data set, there is a greater chance for the songs to be of any genre; while when collecting a larger sample from the same data set, the sample has to better fill the amount of genres there are in the entire data set./
Theoretical probability is the more accurate probability, as it is the exact probability of genres being played throughout the entire playlist; but experimental data is also useful for understanding how probability will look in realistic samples of songs from the playlist./
Coding a simulation allowed me to more easily analyze the genres of
samples of songs from the class playlist, which permitted me to compare
the experimental data found using the sample simulation versus the
theoretical probability calculated using the class playlist
itself.
Simulations such as this could also be used for organizing
opinionated comments about a certain thing. If one wanted to see how
many people felt positively about a certain subject versus negative
opinions, they could use a sample simulation to determine how many
people of a certain amount of people feel about the aforementioned
subject.
The most challenging piece of code to write was the code for the
table of my theoretical probabilities, as it required the most trial
& error, on top of being the most time consuming.
I feel the most proud of the code for the tables of my experimental
probabilities because it all fits together very well, and I don’t think
there’s much I could to to improve upon it.
I’d like to learn more about how to visualize math (ex: functions on
a coordinate plane) in r, as this seems like the language in which to do
it.
If I were to do this process again, I would most likely pre-write the
code I’d know I’d need, rather than completing the analysis portion
before extemporizing my code.
I wonder how different the genres would look with a group of people
of greater varying ages, rather than solely highschoolers.