Ds4 probability

Sylvan

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.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ 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

we need to import the data

df <- read_csv("Playlist - Clean.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 need to check the first 6 rows of data

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
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
genre_counts <- df %>% count(Genre)
genre_counts
## # 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
genre_counts <- genre_counts %>% mutate(prob = n/sum(n))
genre_counts
## # A tibble: 6 × 3
##   Genre                        n   prob
##   <fct>                    <int>  <dbl>
## 1 Genre 1 - hiphop/rap        58 0.331 
## 2 Genre 2 - pop/kpop/Latin    25 0.143 
## 3 Genre 3 -  house/ska         5 0.0286
## 4 Genre 4 -  rnb/soul         14 0.08  
## 5 Genre 5 - alt/indie/folk    45 0.257 
## 6 Genre 6 - country/rock      28 0.16
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

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

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

The song genres simulated are in some ways similar to the genres in my playlists. I listen mostly to hiphop and rock with some indie music in between

I would think that pop would be the most common genre but it seems that hiphop was the most common. I think its because of the age range of the people that gave the data.

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         5        0.25
## 2 Genre 2 - pop/kpop/Latin     5        0.25
## 3 Genre 3 -  house/ska         1        0.05
## 4 Genre 5 - alt/indie/folk     4        0.2 
## 5 Genre 6 - country/rock       5        0.25
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         3         0.1
## 2 Genre 2 - pop/kpop/Latin     3         0.1
## 3 Genre 3 -  house/ska         3         0.1
## 4 Genre 4 -  rnb/soul          3         0.1
## 5 Genre 5 - alt/indie/folk     9         0.3
## 6 Genre 6 - country/rock       9         0.3
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         6        0.15
## 2 Genre 2 - pop/kpop/Latin    10        0.25
## 3 Genre 3 -  house/ska         1        0.03
## 4 Genre 4 -  rnb/soul          3        0.07
## 5 Genre 5 - alt/indie/folk    13        0.32
## 6 Genre 6 - country/rock       7        0.17
sample_n(df, 17) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap         5        0.29
## 2 Genre 2 - pop/kpop/Latin     1        0.06
## 3 Genre 4 -  rnb/soul          1        0.06
## 4 Genre 5 - alt/indie/folk     5        0.29
## 5 Genre 6 - country/rock       5        0.29
sample_n(df, 80) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        29        0.36
## 2 Genre 2 - pop/kpop/Latin    11        0.14
## 3 Genre 3 -  house/ska         3        0.04
## 4 Genre 4 -  rnb/soul          5        0.06
## 5 Genre 5 - alt/indie/folk    19        0.24
## 6 Genre 6 - country/rock      13        0.16
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        32        0.32
## 2 Genre 2 - pop/kpop/Latin    12        0.12
## 3 Genre 3 -  house/ska         2        0.02
## 4 Genre 4 -  rnb/soul          7        0.07
## 5 Genre 5 - alt/indie/folk    27        0.27
## 6 Genre 6 - country/rock      20        0.2

Analyze & Synthesize

the shuffled data does support the genres of songs on the class playlist

When you look at the class playlist the hiphop/rap genre stands out as being listed the most. This is also the case on the shuffled data.

this taught me that my guess on what music people my age listen to was pretty accurate. It was interesting to see the data prove this.

Reflection

coding this simulation helped me see the data in a clearer way. You could use this type of simulation to look at a large group of peoples data in other ways. An example of this could be income.

The piece of code that was the most challenging for me to write was the genre counts. I was very confused on how to do this before I checked the example of writing the code.

I’m the most proud of the code that samples the data.

I would like to learn more about how to design the software in more visually appealing ways.

I would try to learn how the software works more clearly before trying to jump into using it.

I don’t think I have any remaining thoughts about it.