Load necessary libraries
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(lme4)
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
# 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)
# Fit the generalized linear mixed-effects model
model_glmer <- lme4::glmer(Response ~ Years_of_Musicianship + (1 | Participant) + (1 | Question),
data = long_data, family = binomial)
# Display the summary of the model
summary(model_glmer)
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: binomial ( logit )
## Formula: Response ~ Years_of_Musicianship + (1 | Participant) + (1 | Question)
## Data: long_data
##
## AIC BIC logLik deviance df.resid
## 6160.2 6186.8 -3076.1 6152.2 5596
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.4688 -0.6890 0.3396 0.5967 3.4687
##
## Random effects:
## Groups Name Variance Std.Dev.
## Question (Intercept) 1.8014 1.3422
## Participant (Intercept) 0.2565 0.5065
## Number of obs: 5600, groups: Question, 224; Participant, 25
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.814390 0.188997 4.309 1.64e-05 ***
## Years_of_Musicianship -0.001953 0.025282 -0.077 0.938
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Yrs_f_Mscns -0.672