0

Within an R session I would have the following formula:

members ~ face + class + gender + number + (day || country)

How would I write this in a math formula? By the way, is it a random slope random intercept model?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Check out the equatiomatic package and see if that helps: https://datalorax.github.io/equatiomatic/ – Phil Nov 01 '20 at 17:53
  • It would typically be called a "random slopes model with uncorrelated slopes and intercepts" – Ben Bolker Nov 01 '20 at 18:07

1 Answers1

1

tl;dr

equation formula

This is just the "hard part"; your covariates that aren't involved in the random-effects part of the model would get added as part of the first equation (beta_2*face + beta_3*class + ...). (By the way, it's unusual [i.e. probably wrong unless you have some specific reason for doing it this way], if days is a continuous variable, to have it in the random-effects model and not in the fixed-effects model ...)

Using the development version of equatiomatic (note that most of the complexity here is for turning the results of extract_eq() into a PDF, then a PNG for posting here - requires some command-line tools (LaTeX, pdfcrop, ImageMagick). There may be a way to do this in a more self-contained way with the tinytex package:

while (!require("equatiomatic")) {
    remotes::install_github("datalorax/equatiomatic")
}
library(lme4)
m1 <- lmer(Reaction ~ Days + (Days||Subject), sleepstudy)
unlink("tmp.tex")

writeLines(c("\\documentclass{article}",
             "\\usepackage{amsmath}",
             "\\begin{document}",
             "\\thispagestyle{empty}",
             format(extract_eq(m1)),
             "\\end{document}"),
           con="tmp.tex")

system("pdflatex tmp.tex")
system("pdfcrop tmp.pdf")
system("convert tmp-crop.pdf tmp.png")
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • quick question why the alpha has those 2 indexes j adn i ? in your answer subjects should be the I index right ? also why then that alpha follows that normal distribution with the ~ in the equation? @Ben Bolker – Rosa Maria Mar 19 '22 at 09:33
  • `j` is the group (Subject) index, `i` is the observation index, `j[i]` means "the `j` corresponding to observation `i`". Don't understand the second question. – Ben Bolker Mar 19 '22 at 17:45