The questions and exercises below all include examples using a dataset put together in the Tottenham Lab of many Billboard Hot 100 songs from 1946-1983. Today in this challenge you’ll want to work to answer several questions:
rstanarm::stan_glm()
, and plotting with ggplot()
You don’t have to write code in this section, but it will be helpful to read through to understand the data a little better.
Load the needed packages (install if necessary and ASK AN INSTRUCTOR if you’re getting stuck here
library(tidyverse)
library(car)
library(rstanarm)
library(tidybayes)
library(bayesplot)
Now, we can load in the data from Github using read_csv()
music = read_csv('https://raw.githubusercontent.com/pab2163/danl_code_workshop/main/data/familiar_music_database.csv')
## Parsed with column specification:
## cols(
## .default = col_double(),
## title = col_character(),
## artist = col_character(),
## id = col_character(),
## uri = col_character(),
## genre = col_character(),
## cover = col_logical(),
## start_time = col_time(format = "")
## )
## See spec(...) for full column specifications.
names(music)
## [1] "year" "title" "artist" "id"
## [5] "uri" "rank" "genre" "cover"
## [9] "danceability" "energy" "key" "loudness"
## [13] "speechiness" "acousticness" "instrumentalness" "liveness"
## [17] "valence" "tempo" "mode" "time_signature"
## [21] "duration_ms" "start_time"
We have a lot of columns here we could look at, but for today’s challenge just focus on genre, loudnesss, and year. We’ll also only look at the Pop
and Rock
genres for today
# select just the relevant columns
music = dplyr::select(music, title, artist, year, genre, loudness) %>%
# filter the data to only include Pop/Rock genre
dplyr::filter(genre %in% c('Pop', 'Rock')) %>%
# scale/center loudness
dplyr::mutate(loudness = as.vector(scale(loudness, center = TRUE, scale = TRUE)))
head(music)
## # A tibble: 6 x 5
## title artist year genre loudness
## <chr> <chr> <dbl> <chr> <dbl>
## 1 I Can't Begin To Tell You - Single Version Bing Crosby 1946 Pop -2.96
## 2 Let It Snow! Let It Snow! Let It Snow! Vaughn Mon… 1946 Pop 1.24
## 3 Doctor, Lawyer, Indian Chief Betty Hutt… 1946 Pop -0.461
## 4 Personality Johnny Mer… 1946 Pop -1.68
## 5 Oh! What It Seemed to Be Frankie Ca… 1946 Pop -1.13
## 6 Prisoner of Love (with Russ Case & His Orche… Perry Como 1946 Pop -0.495
rstanarm::stan_glm()
with 1 continuous predictor to understand relationships betweenyear
and loudness
in the music dataset!tidybayes
and ggplot()
# here's 1 open code chunk for this question, but feel free to make more!
rstanarm::stan_glm()
with 1 categorical predictor to understand relationships between genre
and loudness
in the music dataset!tidybayes
and ggplot()
# here's 1 open code chunk for this question, but feel free to make more!
rstanarm::stan_glm()
with 1 categorical predictor, 1 continuous predictor, and an interaction term between them, to understand loudness
as a function of genre
, year
, and their interaction.tidybayes
and ggplot()
# here's 1 open code chunk for this question, but feel free to make more!
Congrats! You’ve finished the challenge!