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.
df$Song <- as.factor(df$Song)
playlist <-sample_n(df, 10)
playlist
## # A tibble: 10 × 3
## Genre Artist Song
## <fct> <chr> <fct>
## 1 Genre 6 - country/rock Pink Floyd Time
## 2 Genre 1 - hiphop/rap Bryson Tiller Whatever She Wants
## 3 Genre 1 - hiphop/rap Travis Scott Maria I'm Drunk
## 4 Genre 6 - country/rock Queens of the Stone Age No One Knows
## 5 Genre 2 - pop/kpop/Latin Phantogram Fall In Love
## 6 Genre 2 - pop/kpop/Latin Ginger root Loretta
## 7 Genre 6 - country/rock Billy Joel Summer, Highland Falls
## 8 Genre 4 - rnb/soul Rihanna Nobody's Business
## 9 Genre 1 - hiphop/rap 8k When you call
## 10 Genre 5 - alt/indie/folk Japanese Breakfast Everybody Wants to Love You
Now I will adjust this table to show me just the genres and their
probabilities
sample_counts <- df %>% count(df$Genre) %>% mutate(prob = n/sum(n))
sample_counts
## # A tibble: 6 × 3
## `df$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
Experimental Probability: .1% hiphop/rap,.1% pop/kpop/latin, 0%
house/ska, .1% rnb/soul,.3% alt/indie/folk, .4% country/rock
The song genres are decently representative of the ones in our
playlist, the sample showed alt/indie/folk the most which is the second
highest genre on our playlist.
Theoretical vs Experimental
The theoretical probability shows that the bigger the amount of a
certain genre, the more likely it is to show up resulting in a higher
percent of theoretical probability. The experimental probability varied
a bit from the theoretical probability. Alt/indie/folk genre and
house/ska stayed within the same percentage range. The reason the two
probabilities are different is because the experimental probability for
each genre is based off an actual random sample size.
Larger Sample Sizes
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 4 0.2
## 2 Genre 2 - pop/kpop/Latin 4 0.2
## 3 Genre 4 - rnb/soul 2 0.1
## 4 Genre 5 - alt/indie/folk 7 0.35
## 5 Genre 6 - country/rock 3 0.15
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 9 0.3
## 2 Genre 2 - pop/kpop/Latin 4 0.13
## 3 Genre 4 - rnb/soul 3 0.1
## 4 Genre 5 - alt/indie/folk 7 0.23
## 5 Genre 6 - country/rock 7 0.23
sample_n(df,40)%>%count(Genre)%>%mutate(probability=round(n/sum(n),2))
## # A tibble: 4 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 17 0.42
## 2 Genre 2 - pop/kpop/Latin 9 0.22
## 3 Genre 5 - alt/indie/folk 7 0.17
## 4 Genre 6 - country/rock 7 0.17
sample_n(df,50)%>%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.36
## 2 Genre 2 - pop/kpop/Latin 5 0.1
## 3 Genre 3 - house/ska 3 0.06
## 4 Genre 4 - rnb/soul 6 0.12
## 5 Genre 5 - alt/indie/folk 11 0.22
## 6 Genre 6 - country/rock 7 0.14
sample_n(df,60)%>%count(Genre)%>%mutate(probability=round(n/sum(n),2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 21 0.35
## 2 Genre 2 - pop/kpop/Latin 8 0.13
## 3 Genre 3 - house/ska 1 0.02
## 4 Genre 4 - rnb/soul 4 0.07
## 5 Genre 5 - alt/indie/folk 15 0.25
## 6 Genre 6 - country/rock 11 0.18
sample_n(df,70)%>%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.41
## 2 Genre 2 - pop/kpop/Latin 8 0.11
## 3 Genre 3 - house/ska 3 0.04
## 4 Genre 4 - rnb/soul 3 0.04
## 5 Genre 5 - alt/indie/folk 20 0.29
## 6 Genre 6 - country/rock 7 0.1
Analyze & Synthesize
Unit Question: Do the genres played on shuffle represent the genres
of the songs on the class playlist?
Yes, a shuffled playlist (or sample size) represents the genres of
the class playlist. This can be seen in any of the sample sizes pulled
previously by the number of songs from each genre and how they correlate
to the counts for each genre in the original playlist.
I learned that experimental probability is a lot more helpful for
this type of situation because it gives real results that can then be
calculated to find the probability percentage.
Reflection
Coding the simulation was an easier way to find results to help
answer the question instead of making an actual playlist and trying to
randomize it and record results.
The beginning pieces of code were the most challenging for me as
well as the mutate function and piping operator. I think the more
complicated and longer the code got, the more room there was for
error.
I feel most proud of the code I wrote for creating a new column for
genre counts because I was initially stuck on how to go about it.
I would like to learn about ways to effectively memorize code. I
found myself having to frequently go back and check how to write the
specific code I needed.
If I were to do this again, I would have asked for help earlier on
when I was confused instead of getting more and more stuck and making it
more complicated than it needed to be.