Hello,
I'm trying to mean-centre a categorical variable (interference) with 3 levels by recoding it as a numeric variable with the values -1, 0 and 1. However, using the scale function to do this only has the effect of turning all the values in this variable to NA and I can't figure out why?
When I try to run the GLMM function, I later get an 'Error: Invalid grouping factor specification, subject_nr' message, which I think may be because of the earlier issue (subject_nr does exist in the d0 dataframe).
Any help would be much appreciated!
d0$subject_nr = as.factor(d0$subject_nr)
d0$speech = scale(ifelse(d0$speech == 'distorted', 1,0), scale = FALSE)
# recode d$interference as a numeric variable with values of -1, 0, and 1
d0$interference = as.numeric(d0$interference)-2
d0$int = scale(d0$interference, scale = FALSE)
# d0$int = scale(d0$interference == case_when(d0$interference == "none" ~ -1,
# d0$interference == "foot-tap" ~ 0,
# d0$interference == "whisper" ~ 1), scale = FALSE)
# GLMM interaction model (familiarity and interference)
glmm2int = glmer(binary_resp ~ speech*int + (1+speech*int|subject_nr),
data = d0,
fam = binomial("logit"),
control = glmerControl(optimizer = "bobyqa"))
summary(glmm2int)