I’m trying to wrap my head around population- and group-level intercepts (and other betas) for mixed models involving two (possibly interrelated) categorical predictors
In these examples, I use x
as any number of continuous predictors, and G
and H
are two, possibly interrelated groups.
-
Simple case: Single population mean, two independent group-level intercepts
y ~ 1 + x + (1 + x | G) + (1 + x | H)
This basically says that there are two groups, which independent of each other “modify” the intercept and betas for the
x
variables. The two groups operate “independently of each other” -
Even simpler case: Only using group-level intercepts
y ~ 1 + x + (1 | G) + (1 | H)
This is even simpler, where only the intercept is modeled as varying according to the group.
Q1: What is the difference by modeling the groups as predictors intead of grouping variables:
y ~ 1 + x + G + H
As I understand brms (which is not saying much), this would also make theG
beta adjust the population-level intercept? But I guess it would be much harder to make “out-of-sample predictions” (i.e. predicting new behaviours for new group levels appearing in the data)? -
Interaction terms between groups
As I understand the colon operator, it can be used to construct new factors from old ones, by combining each level of the lhs factor with every level of the rhs factor.
y ~ 1 + x + (1 + x | G:H)
This allows each intercept and beta to vary, depending on the combination of G and H level. -
Using an interaction as a predictor
In analogy to question 2, if we have only the intercept as the grouping factor, then could we make a similar choice of making the new factor a predictor?
y ~ 1 + x + G:H
Q2: But I guess a similar caveat applies - how would the model react to new factors appearing in either G or H? -
Finally, we could use the multiplication operation, to make a “full cross product” of the factors
As I read?glm
, as referenced by brms, it seems like the syntaxG*H
is equivalent toG + H + G:H
.
That is, the model allows variance for each of the individual groups, but also for their interaction.
I guess the most common use for that construct is as a predictor term, right?
y ~ 1 + x + G*H
would be equivalent to
y ~ 1 + x + (1 | G) + (1 | H) + (1 | G:H)
Q3: Or, should I putG*H
in the grouping term? That seems weird, or?
Sorry if this question has been asked before, but I tried both the forums and reputable books (e.g. “McElreath, Rethinking, 2nd ed.” and “Johnson et al. Bayes Rules!”. But they seem to stop just short of modeling interactions between categorical variables.
Thanks for your time,
/Anders