I would like to understand how to solve a "simple" mixed model by hand on R and not by using an available package (like nlme, etc).
As example let's get the data from this case,
library(mlmRev)
library(lme4)
library(rstanarm)
library(ggplot2)
# Make Male the reference category and rename variable
Gcsemv$female <- relevel(Gcsemv$gender, "M")
# Use only total score on coursework paper
GCSE <- subset(x = Gcsemv,
select = c(school, student, female, course))
# Count unique schools and students
J <- length(unique(GCSE$school))
N <- nrow(GCSE)
M2 <- lmer(formula = course ~ 1 + female + (1 | school),
data = GCSE,
REML = FALSE)
summary(M2)