The formula one needs to specify for training a multilevel model (using lmer
from lme4
R
library) always gets me. I have read countless textbooks and tutorials, but never properly understood it.
So here's an example from this tutorial that I would like to see formulated in an equation. We are trying to model voice frequency as a function of gender (females have higher pitched voice than males in general) and attitude of the person (whether he/she answered in a polite or informal manner) in different scenarios. Also, as you can see from the subject
column, each person was subjected to measurements several times.
> head(politeness, n=20)
subject gender scenario attitude frequency
1 F1 F 1 pol 213.3
2 F1 F 1 inf 204.5
3 F1 F 2 pol 285.1
4 F1 F 2 inf 259.7
5 F1 F 3 pol 203.9
6 F1 F 3 inf 286.9
7 F1 F 4 pol 250.8
8 F1 F 4 inf 276.8
9 F1 F 5 pol 231.9
10 F1 F 5 inf 252.4
11 F1 F 6 pol 181.2
12 F1 F 6 inf 230.7
13 F1 F 7 inf 216.5
14 F1 F 7 pol 154.8
15 F3 F 1 pol 229.7
16 F3 F 1 inf 237.3
17 F3 F 2 pol 236.8
18 F3 F 2 inf 251.0
19 F3 F 3 pol 267.0
20 F3 F 3 inf 266.0
subject
, gender
and attitude
are factors (with informal
and female
considered as base levels for attitude
and gender
in equations below). Now, one idea is to train a model with differing intercepts for each subject
and scenario
:
politeness.model=lmer(frequency ~ attitude + gender +
(1|subject) + (1|scenario), data=politeness)
If my understanding of the notation is correct, this corresponds to:
$y_i=a^1_{j[i]}+a^2_{k[i]}+\beta\cdot$ attitude
$_{\text{pol}_i} + \gamma\cdot$ gender
$_{\text{male}_i}$
where $i$ denotes $i^{th}$ data point, $j[i]$ denotes group level for subject
and $k[i]$ denotes group level for scenario
for $i^{th}$ data point. attitude
$_\text{pol}$ and gender
$_\text{male}$ are an binary indicators.
To introduce random slopes for attitude, we can write:
politeness.model = lmer(frequency ~ attitude + gender +
(1+attitude|subject) + (1+attitude|scenario), data=politeness)
Again, if my understanding is clear, this corresponds to:
$y_i = a^1_{j[i]} + a^2_{k[i]} + (\beta^1_{j[i]} + \beta^2_{k[i]})\cdot$ attitude
$_{\text{pol}_i} + \gamma\cdot$ gender
$_{\text{male}_i}$
Now, what equation does the following R
command correspond to?
politeness.null = lmer(frequency ~ gender +
(1+attitude|subject) + (1+attitude|scenario), data=politeness)
attitude
being conditioned onsubject
andscenario
. $\endgroup$