DS4 Song Simulation

Max Wallace

We need to load tidyverse.

{r} install.packages("tidyverse")

{r} library(tidyverse)

Imported our class playlist data

{r} df <- read_csv("Playlist - Clean.csv")

Named the csv df

{r} head(df)

{r} df$genre <- as.factor(df$Genre)

After my data was loaded in, I counted how many songs were in each genre

{r} df %>% count(genre)

{r} genre_counts <-df %>% count(genre) head(genre_counts)

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

Next I calculated the theoretical probablilty by creating a new coulmn named tprob and using the mutate function.

```{r} genre_counts\(tprob <-round(genre_counts\)tprob,2) genre_counts


### Last I rounded my TPROB numbers to two decimal places so they were easier to interperet and read.

### The table shows me that there is a 33% chance of getting a Hip Hop/Rap song, 14% chance of getting a Pop/Kpop/Latin song, 3% of getting a House/Ska song, 8% chance for RnB/Soul song, 26% chance for alt/indie/folk and 16% chance of getting a country/rock song.
# 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
```{r}
playlist<-sample_n(df, 10)
playlist

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

{r} sample_counts<-playlist%>%count(playlist$Genre) sample_counts {r} sample_counts%>%mutate(prob=n/sum(n)) ## Yes my probability matches my playlist pretty well. The probability is .4 for art/indie/folk and there were four songs of this genre on my playlist. There was also a .3 experimental prob of hip hop and there were 3 songs on my playlist. ## When compared to my theoretical probabbility the biggest experimental was art/indie/folk but theoretical was only .1 running the experimental probability more times could maybe make them similar.