---
title: "Data Analysis"
author: "Enming Zhang"
date: "2024-06-05"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Load necessary libraries
```{r}
library(tidyr)
library(dplyr)
library(lme4)
```

```{r}
# Load the cleaned data
dataset <- read.csv("anonymizedData.csv")

# Reshape the data from wide to long format
long_data <- dataset %>%
  tidyr::gather(key = "Question", value = "Response", Q1:Q224) %>%
  dplyr::mutate(Question = as.integer(gsub("Q", "", Question)))

# Ensure the data types are correct
long_data$Response <- as.numeric(long_data$Response)
long_data$Years_of_Musicianship <- as.numeric(long_data$Years_of_Musicianship)
long_data$Participant <- as.factor(long_data$Participant)
long_data$Question <- as.factor(long_data$Question)
```

```{r}
# Fit the generalized linear mixed-effects model
model_glmer <- lme4::glmer(Response ~ Years_of_Musicianship + (1 | Participant) + (1 | Question), 
                     data = long_data, family = binomial)
```

```{r}
# Display the summary of the model
summary(model_glmer)
```