DS4 Song Simulation 4.3

install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ 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
df<-read_csv("Class Playlist Clean DS4 - Sheet1.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.

We created columns to show each genres most voted artist, ex. Yonaguni was voted most in pop/kpop/latin

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

We took count of each genres and how many people voted in these genres

df$Genre <- as.factor(df$Genre)
genre_counts<-df%>%count(df$Genre)
genre_counts
## # A tibble: 6 × 2
##   `df$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

We changed the column of each genres probability

genre_counts<-genre_counts%>%mutate(tprob=n/sum(n))

we have 33% hiphop/rap because we rounded to the decimal

genre_counts$tprob <- round(genre_counts$tprob,2)
genre_counts
## # A tibble: 6 × 3
##   `df$Genre`                   n tprob
##   <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

We calculated the experimental probabilties

sample <- sample_n(df, 10)
sample
## # A tibble: 10 × 3
##    Genre                    Artist                            Song              
##    <fct>                    <chr>                             <chr>             
##  1 Genre 6 - country/rock   Three Days Grace                  I Hate Everything…
##  2 Genre 1 - hiphop/rap     Drake                             Come thru         
##  3 Genre 5 - alt/indie/folk ついったー東方部 (Twitter Tohobu) Necrofantasia i   
##  4 Genre 5 - alt/indie/folk Flatt & Scruggs                   Flint Hill Special
##  5 Genre 2 - pop/kpop/Latin lady gaga                         just dance        
##  6 Genre 1 - hiphop/rap     A$ap Rocky                        I Smoked Away My …
##  7 Genre 5 - alt/indie/folk 2 8 1 4                           Arcadia           
##  8 Genre 5 - alt/indie/folk Yot club                          Ykwim?            
##  9 Genre 5 - alt/indie/folk yungblud                          Parents           
## 10 Genre 1 - hiphop/rap     Sha Gz                            New Opp
Sample_counts <- sample %>% count(Genre) %>% mutate(probability = n/sum(n))
Sample_counts
## # A tibble: 4 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap         3         0.3
## 2 Genre 2 - pop/kpop/Latin     1         0.1
## 3 Genre 5 - alt/indie/folk     5         0.5
## 4 Genre 6 - country/rock       1         0.1

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

combined <- tibble(Genre = genre_counts$Genre, n = c(2, 3, 0, 1, 2, 2), probability = n/sum(n))
## Warning: Unknown or uninitialised column: `Genre`.
combined
## # A tibble: 6 × 2
##       n probability
##   <dbl>       <dbl>
## 1     2         0.2
## 2     3         0.3
## 3     0         0  
## 4     1         0.1
## 5     2         0.2
## 6     2         0.2

We combined all of our samples of 10 as a class. You can see the results in the table below.

sample_n(df, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap         8        0.4 
## 2 Genre 2 - pop/kpop/Latin     3        0.15
## 3 Genre 3 -  house/ska         1        0.05
## 4 Genre 5 - alt/indie/folk     7        0.35
## 5 Genre 6 - country/rock       1        0.05

I will now run my simulation for different numbers of songs to see how the probabilities change.

Sampling 20

sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        12        0.4 
## 2 Genre 2 - pop/kpop/Latin     3        0.1 
## 3 Genre 3 -  house/ska         2        0.07
## 4 Genre 4 -  rnb/soul          3        0.1 
## 5 Genre 5 - alt/indie/folk     3        0.1 
## 6 Genre 6 - country/rock       7        0.23

Sampling 30

sample_n(df, 50) %>% count(Genre) %>% mutate(probability = n/sum(n))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        17        0.34
## 2 Genre 2 - pop/kpop/Latin     7        0.14
## 3 Genre 3 -  house/ska         3        0.06
## 4 Genre 4 -  rnb/soul          3        0.06
## 5 Genre 5 - alt/indie/folk    14        0.28
## 6 Genre 6 - country/rock       6        0.12

Sampling 50