Song Simulation

Jonny

```{r} df<-read_csv(“Class Playlist Clean DS4 - Sheet1.csv”)


First 5 genres of music

```{r}
head(df)

{r} df$Genre<-as.factor(df$Genre) df%>%count(Genre)

Based on this we can see that the majority of songs are hiphop/rap

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

Data saved for access later

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

Probability

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

{r} genre_counts$prob<-round(genre_counts$prob,2) genre_counts

This final table shows us the probability of any Genre of music being played, the highest being Hiphop/rap with a 33% chance of being played, and alt/indie/folk with a 26% chance. Lowest probability is house/ska with only a 3% chance of being played.

We know this data is accurate because the numbers (.33, .14, .03, .08, .26, and .16 add up to 1- 100%)

Now I will attempt to simulate a song ‘shuffle’ using theoretical probability

{r} sample<-sample_n(df,10) sample

{r} sample_counts<-sample%>%count(Genre)%>%mutate(probability=n/sum(n)) sample_counts

Here we see the probabilty of each genre from the sample of 10 random songs

{r} sample<-sample_n(df,10) sample

{r} sample_n(df,20)%>%count(Genre)%>%mutate(probability=round(n/sum(n),2))

{r} sample_n(df,20)%>%count(Genre)%>%mutate(probability=round(n/sum(n),2))

Reflection

If the trial were ran multiple times the variability of the results would increase, however by taking the average probability of the different outcomes you could calculate the theoretical probability on a more accurate level

coding this was a challenge, I feel like I was unable to write any piece of code on my own without causing multiple errors. Thankfully with the cheatsheet I managed to get by

I hope we don’t do too much coding in the future, I felt as though there would have been an easier way to show a theoretical shuffle playlist rather than writing code for it.