Cross Validated Asked on December 25, 2021
Here’s my code in R
but I unfortunately can’t share my data, and I can’t reproduce it by randomly creating a data set.
I can say that the data set has 1,561 cases. The variable AGE
has 7 levels, the variables SEX
and MODE
have 2, and the variable REGION
has 38.
The response variable Q11B_5
is a binomial variable indicating whether or not they selected answer 5 on a 5-point ordinal scale (if there is a family that I should be using for ordinal variables, I’d love to be corrected).
library(lme4)
Q11B_5.model <- glmer(formula = Q11B_5 ~ (1|AGE) + (1|SEX) + (1|REGION) + (1|MODE),data=mydata, family=binomial(link="logit"))
Here is my output:
ranef(Q11B_5.model)$AGE
(Intercept)
1 -0.77353064
2 -0.15898575
4 0.41855600
5 0.22227148
6 0.04636072
7 0.23850590
ranef(Q11B_5.model)$SEX
(Intercept)
1 -0.3309834
2 0.3260769
ranef(Q11B_5.model)$REGION
(Intercept)
1 0.0154718054
2 -0.0018864413
3 0.0221321678
4 0.0765918347
5 0.0786209587
6 0.0524533792
7 -0.0231999962
8 0.0199398123
9 -0.0001403251
10 0.1506503429
11 -0.0684629297
12 0.0690727463
13 0.0423773908
14 0.0533367587
15 -0.1113295650
16 -0.1987300152
17 -0.0924723159
18 -0.0468747352
19 -0.0953170195
20 0.2072223417
21 -0.0909952852
22 -0.0609481179
23 0.0138789384
24 -0.0610640354
25 0.0098904376
26 0.0697095809
27 0.0707942058
28 0.0657201849
29 -0.0907250031
30 -0.0434898354
31 0.0220447978
32 0.0095983501
33 0.0057010401
34 -0.0312116606
35 0.0143748382
37 -0.0184311778
38 -0.0354609785
ranef(Q11B_5.model)$MODE
(Intercept)
1 0.06094188
2 -0.06133576
Level 3 is not given a RE for the AGE
variable. Same with level 36 for the REGION
variable. What would be the causes for this omission?
This could be caused by there being no observations associated with AGE=='3'
.
For example:
> require(lme4)
> m0 <- lmer(Reaction ~ 1 + Days + (1|Subject), sleepstudy)
> ranef(m0)
$Subject
(Intercept)
308 40.783710
309 -77.849554
310 -63.108567
330 4.406442
331 10.216189
332 8.221238
333 16.500494
334 -2.996981
335 -45.282127
337 72.182686
349 -21.196249
350 14.111363
351 -7.862221
352 36.378425
369 7.036381
370 -6.362703
371 -3.294273
372 18.115747
Now we delete observations associated with Subject=='372'
> dt <- sleepstudy[sleepstudy$Subject!='372',]
> m1 <- lmer(Reaction ~ 1 + Days + (1|Subject), dt)
> ranef(m1)
$Subject
(Intercept)
308 41.832114
309 -76.752312
310 -62.017394
330 5.469822
331 11.277177
332 9.283047
333 17.558895
334 -1.930554
335 -44.198293
337 73.218164
349 -20.122330
350 15.170748
351 -6.793791
352 37.428643
369 8.098678
370 -5.294890
371 -2.227723
372
is now missing from ranef()
even though the level still exists:
> levels(dt$Subject)
[1] "308" "309" "310" "330" "331" "332" "333" "334" "335" "337" "349" "350"
[13] "351" "352" "369" "370" "371" "372"
But of course, it has no observations associated with it:
> table(dt$Subject)
308 309 310 330 331 332 333 334 335 337 349 350 351 352 369 370 371 372
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 0
As a general point on your model, it is not a good idea to include factors with only 2 levels as grouping variables / random intercepts. This can result in, at best, incorrect estimates, but also numerical problems.
Moreover, the idea behind treating factors as random is that they are a sample from the wider population, so fitting random intercepts for SEX
is not a good idea.
Answered by Robert Long on December 25, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP