1

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)

Lefty
  • 479
  • 1
    It is not clear what you mean by to solve a mixed model by hand. Mixed models cannot be solved (i.e., find the maximum likelihood estimates) by hand they require iterative optimization algorithms. For linear mixed, models you only have a close-form solution for the fixed effects if you know the values of the variance components. Namely, for known variance components, the fixed effects are estimated using generalized least squares. – Dimitris Rizopoulos Sep 25 '20 at 07:57
  • Can I use one of these iterative optimizations algorithms to do it? – Lefty Sep 25 '20 at 08:01
  • 1
    Yes, you can, and you may find an example here: https://stats.stackexchange.com/questions/385670/completely-different-results-from-lme-and-lmer/385780#385780 – Dimitris Rizopoulos Sep 25 '20 at 08:35
  • If you can write down and program the likelihood function, then you can find the maxlik solution by optimizing the likelihood, multiple R packages will help! – kjetil b halvorsen Sep 25 '20 at 11:21
  • Do you mean that you want to do all the computations by hand ? – Robert Long Sep 26 '20 at 13:02

0 Answers0