DS4 Song Simulation

Preston Causey

We need to load tidyverse

{r echo=TRUE} install.packages("tidyverse")

{r} library (tidyverse)

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

checking the first 6 collums

{r} head(df)

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

{r} df %>% count(genre)

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

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

{r} genre_counts

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

{r} genre_counts

load necessary libraries

{r} library(tidyverse) # import data
{r} df <- read_csv("playlist - data_clean.csv")

#check first few rows of data {r} head(df)

change variable type to factor

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

get the counts for each genre

{r} df %>% count(genre)

caption
caption

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

Calculating Expiremental Probabilities

our next task is to simulate how shuffle works

{r} sample <- sample_n(df, 10) sample {r} sample_counts <- sample %>% count(genre) %>% mutate(probability = n/sum(n)) sample_counts

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

{r} sample <- sample_n(df, 10) sample ```{r} sample_counts <- sample %>% count(genre) %>% mutate(probability = n/sum(n)) sample_counts

```{r}
combined <- tibble(genre = genre_counts$genre, n = c(2, 3, 0, 1, 2, 2), probability = n/sum(n))  

combined

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


```{r}
sample_n(df, 30) %>% count(genre) %>% mutate(probability = round(n/sum(n), 2))

{r} sample_n(df, 50) %>% count(genre) %>% mutate(probability = n/sum(n))

caption
caption

hip hop/rap and country/rock seem to be the most chosen, which is concurrent with the previous predicted outcomes

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

```{r}
sample_n(df, 30) %>% count(genre) %>% mutate(probability = round(n/sum(n), 2))

```{r} sample_n(df, 40) %>% count(genre) %>% mutate(probability = round(n/sum(n), 2))

```{r}
sample_n(df, 67) %>% count(genre) %>% mutate(probability = round(n/sum(n), 2))

```{r} sample_n(df, 150) %>% count(genre) %>% mutate(probability = round(n/sum(n), 2))

```{r echo=TRUE}
sample_n(df, 54) %>% count(genre) %>% mutate(probability = round(n/sum(n), 2))
caption
caption

ananylze and synthesize

Do the genres you hear played on shuffle represent the genres of the songs in our class playlist?

yes, the genres that have more songs in them are more occuring in the shuffle.

What data do you have to support your response?

the ā€œnā€ or number of songs selected are higher in the genres that were higher in the simulation in 4.3.

What did you learn about experimental and theoretical probability and how do they apply to this situation?

i learned that expiremental probability is not exact to the theoretical but seems consistant.

Reflection

In what ways did coding a simulation support you in answering the unit question? What else might you use simulations for?

the use of this simulation showed how we can demonstrate expiremental probability and simulate these things to test our hypothesises.

What piece of code was most challenging for you to write?

i think the ones where i had to change the numbers and round them, there were lots of errors and trying to figure it out was hard

What piece of your code do you feel most proud of? Why?

i think the tables i did well, they were not very challenging.

What is something in programming that you would like to learn more about?

maybe using a different language.

Is there anything you would do differently if you were to do this again?

i would try to make the tables show up when its published.

Caption
Caption