---
format: docx
---

# Minimal Research Compendiums: An Approach to Assure Statistical Validity and Reproducibility in Digital Humanities Research

## Computing Environment

The code for the article was created using R version 4.3.0 on the aarch64-apple-dwarwin20 (64-bit architecture) on macOS Venture 13.3.1. The following libraries were loaded in the article.

```{r}
# install.packages("tidyverse")
# install.packages("easystats")
library(tidyverse)
library(easystats)
```


```{r}
sessionInfo()
```

## Dataset

The dataset utilized in this research comes from the Musical Sentiment Dataset put together by Christopher Akiki and Manuel Burghardt for the Journal of Open Humanities Data. The dataset itself consists of sentiment information for approximately ninety thousand songs.

The authors began by seeding 279 mood labels from AllMusic and collecting songs from the Last.fm API. For each of the mood labels, they gathered approximately one thousand songs. They then filtered the songs using the [WordNet-Affect list](https://aclanthology.org/L04-1208/). Mood tags were then mapped using an extension of James Russell’s [“circumplex model”](https://psycnet.apa.org/record/1981-25062-001?doi=1) with a weighted average for valence, arousal, and dominance calculated for songs with multiple mood tags. Finally, metadata information was added using MasicBrainz ID and duplicates were removed. 

Version 3 of the dataset was used and is downloaded in the accompanying folder. More information about the creation of the dataset is available [here](https://openhumanitiesdata.metajnl.com/articles/10.5334/johd.33#n1)

```{r}
muse <- read_csv("muse_dataset.csv")
```


## Data Wrangling

The following represents summary statistics for the original dataset.

```{r}
summary(muse)
```

For the purposes of demonstration, we will filter to only contain songs in the "rap" genre.

```{r}
rap_songs <- muse |>   
  filter(genre=="rap")
```

A qualitative “high arousal” variable is created showing if the arousal was more than 4 with the values “yes” or “no”. This is mainly done for the purposes of demonstrating how the general linear model works with qualitative predictors later in the article.

```{r}
rap_songs$high_arousal <- ifelse(rap_songs$arousal_tags>4, "yes", "no")
```

The following shows the summary statistics for the updated dataset.

```{r}
summary(rap_songs)
```

## Statistical Analysis

Because the purpose of this article was to overview the minimal research compendium framework along with providing a brief introduction to the general linear model, there were various charts created that would likely not be traditionally needed. However, for the purposes of reproducibility and clarity. They are provided here.

The following shows the creation of Figure 1, which demonstrates a scatter plot of valence and dominance.

```{r}
rap_songs |> 
  ggplot(aes(x=valence_tags, y=dominance_tags)) +
  geom_point() +
  theme_minimal()
```
The following shows the creation of Figure 2, which demonstrates a scatter plot of valence and dominance with a line of best fit. 

```{r}
rap_songs |> 
  ggplot(aes(x=valence_tags, y=dominance_tags)) +
  geom_point() +
  geom_smooth(method="lm", se=F) +
  theme_minimal()
```

The following shows the creation of Figure 2, which demonstrates a scatter plot of valence and dominance with a mean line. 

```{r}
rap_songs |> 
  ggplot(aes(x=valence_tags, y=dominance_tags)) +
  geom_point() +
  geom_hline(yintercept = mean(rap_songs$dominance_tags, na.rm=TRUE)) +
  theme_minimal()
```
Create a general linear model with dominance as the outcome and valence as the predictor.

```{r}
lm_valence <- lm(dominance_tags ~ valence_tags, data=rap_songs)
```

Results of linear model using valence to predict dominance.

```{r}
summary(lm_valence)
```

Adding arousal as an additional predictor to the above linear model.

```{r}
lm_valence_arousal <- lm(dominance_tags ~ valence_tags + arousal_tags, data=rap_songs)
```

Results of the linear model to predict dominance with valence and arousal as predictors

```{r}
summary(lm_valence_arousal)
```

Linear model using high arousal and valence as predictors with dominance as outcome variables. Chief goal of this section is to provide an overview of how qualitative variables can be used in the general linear model.

```{r}
lm_valence_high_arousal <- lm(dominance_tags ~ valence_tags + high_arousal, data=rap_songs)
```

Summary of the model using high arousal and valence as predictors and dominance as the outcome variable.

```{r}
summary(lm_valence_high_arousal)
```

Demonstration of the previous linear model but with high arousal serving as an interaction effect.

```{r}
lm_interaction_model <- lm(dominance_tags ~ valence_tags * high_arousal, data=rap_songs)
```

Results of the interaction model

```{r}
summary(lm_interaction_model)
```

## Checking GLM Assumptions through Residual Plots

Residual plots for linear model using valence to predict dominance.

```{r}
par(mfrow = c(2, 2))  
plot(lm_valence)
```
Residual plots for linear model using valence and arousal to predict dominance.

```{r}
par(mfrow = c(2, 2))  
plot(lm_valence_arousal)
```
Residual plots for linear model using valence and high arousal to predict dominance.

```{r}
par(mfrow = c(2, 2))  
plot(lm_valence_high_arousal)
```
Residual plots for linear model using valence and high arousal as an interaction effect to predict dominance.

```{r}
par(mfrow = c(2, 2))  
plot(lm_interaction_model)
```

Residual plots for linear model using valence to predict dominance using the "easystats" package.

```{r}
check_model(lm_valence)
```

Residual plots for linear model using valence and arousal to predict dominance using the "easystats" package.

```{r}
check_model(lm_valence_arousal)
```

Residual plots for linear model using valence and high arousal to predict dominance using the "easystats" package.

```{r}
check_model(lm_valence_high_arousal)
```

Residual plots for linear model using valence and high arousal as an interaction effect to predict dominance using the "easystats" package.

```{r}
check_model(lm_interaction_model)
```



