0

如果我没有正确格式化,请提前道歉,这是我关于 SO 的第一个问题。

我在 R 中使用 lme4 运行了一系列多级模型。我的结果变量是连续的,我有一个具有多个类别(美国地区:中西部、东北部、南部、西部)的分类二级预测变量以及一系列的时变协变量。当我运行这段代码时,

m5 <- lmer(percentfemale~ timecat1 + region + sizelogc + 
         perLatinxc.lag8 + perBlackc.lag8 + 
         femincomedisc.lag8 + femLFPdisc.lag8 + fememploydisc.lag8 + femedudisc.lag8 +
         (1 + timecat1|AJID), data=data, REML=F) 

我得到以下结果(减少空间):

     AIC      BIC   logLik deviance df.resid 
  8182.5   8269.8  -4075.2   8150.5     1722 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-6.4726 -0.3921 -0.0245  0.3687  6.4414 

Random effects:
 Groups   Name        Variance Std.Dev. Corr
 AJID     (Intercept) 12.70271 3.5641       
          timecat1     0.04184 0.2045   0.44
 Residual              2.16582 1.4717       
Number of obs: 1738, groups:  AJID, 531

Fixed effects:
                     Estimate Std. Error t value
(Intercept)         1.088e+01  3.544e-01  30.696
timecat1            1.086e-01  1.252e-02   8.679
regionNortheast    -2.337e+00  4.749e-01  -4.920
regionSouth         6.269e-01  4.472e-01   1.402
regionWest          1.079e+00  4.807e-01   2.245

但是,当我按自变量绘制残差时,我只有四个区域中的两个区域的残差(见下文)。

xyplot(resid(m5) ~ region, data=data, jitter.x=T, abline=0, type=c("p", "g"))

残差绘制在 y 轴上,中西部、东北部、南部、西部绘制在 x 轴上,残差仅适用于南部和西部地区

我在区域变量中没有丢失数据,并且不知道为什么我会对没有相应残差的区域进行估计。为什么会这样?

编辑2:

m5 <- lmer(percentfemale~ timecat1 + region + sizelogc + 
        (1 + timecat1|AJID), data=egdata, REML=F)

xyplot(resid(m5) ~ region, data=data, jitter.x=T, abline=0, type=c("p", "g"))

> dput(egdata)
structure(list(AJID = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 13L, 
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 68L, 68L, 68L, 68L, 68L, 
68L, 68L, 68L, 79L, 83L, 83L, 83L, 83L, 83L, 83L, 83L, 97L, 116L, 
116L, 116L, 127L, 127L, 127L, 127L, 127L, 127L, 127L, 148L, 148L, 
148L, 148L, 148L, 148L, 148L, 148L, 152L, 152L, 152L, 152L, 152L, 
152L, 160L, 160L, 160L, 160L, 160L, 160L, 168L, 168L, 168L, 168L, 
168L, 168L, 168L, 171L, 171L, 171L, 176L, 176L, 176L, 176L, 176L, 
176L, 176L, 176L, 179L, 179L, 179L, 179L, 179L, 179L, 179L, 183L, 
183L, 183L, 183L, 183L, 183L, 191L, 191L, 191L, 191L, 191L, 191L, 
191L, 197L, 197L, 207L, 207L, 207L, 225L, 235L, 235L, 235L, 235L, 
235L, 235L, 235L, 237L, 237L, 237L, 237L, 237L, 237L, 237L, 238L, 
238L, 238L, 238L, 238L, 238L, 238L, 238L, 245L, 245L, 245L, 245L, 
245L, 251L, 251L, 251L, 251L, 251L, 251L, 251L, 265L, 265L, 265L, 
265L, 265L, 266L, 266L, 266L, 266L, 266L, 266L, 266L, 273L, 273L, 
273L, 273L, 273L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 275L, 
279L, 279L, 279L, 279L, 279L, 280L, 280L, 280L, 280L, 280L, 280L, 
284L, 284L, 284L, 284L, 284L, 284L, 284L, 286L, 286L, 286L, 286L, 
286L, 286L, 286L, 286L, 296L, 296L, 296L, 296L, 296L, 296L, 296L, 
296L, 313L, 341L, 341L, 341L, 341L, 341L, 345L, 345L, 345L, 345L, 
345L, 345L, 345L, 345L, 352L, 363L, 363L, 365L, 365L, 365L, 365L, 
365L, 365L, 365L, 365L, 369L, 369L, 369L, 369L, 374L, 374L, 374L, 
374L, 374L, 374L, 374L, 385L, 385L, 385L, 385L, 385L, 385L, 385L, 
391L, 391L, 391L, 391L, 391L, 391L, 391L, 416L, 416L, 416L, 416L, 
416L, 416L, 416L, 417L, 417L, 417L, 417L, 417L, 417L, 417L, 423L, 
423L, 423L, 423L, 423L, 423L, 423L, 429L, 429L, 429L, 429L, 429L, 
429L, 434L, 434L, 434L, 434L, 434L, 434L, 441L, 441L, 441L, 441L, 
441L, 441L, 441L, 441L, 447L, 447L, 447L, 447L, 447L, 447L, 447L, 
447L, 448L, 448L, 448L, 448L, 448L, 448L, 448L, 448L, 453L, 454L, 
454L, 454L, 454L, 454L, 454L, 466L, 466L, 466L, 466L, 466L, 466L, 
466L, 480L, 480L, 480L, 480L, 480L, 480L, 482L, 482L, 506L, 506L, 
506L, 510L, 510L, 510L, 510L, 510L, 513L, 513L, 513L, 513L, 513L, 
513L, 513L, 514L, 514L, 514L, 514L, 514L, 514L, 514L, 525L, 525L, 
525L, 525L, 525L, 525L, 525L, 525L, 547L, 563L, 563L, 563L, 563L, 
563L, 563L, 563L, 563L, 577L, 577L, 577L, 577L, 577L, 577L, 577L, 
580L, 580L, 580L, 580L, 580L, 580L, 580L, 586L, 586L, 586L, 586L, 
586L, 586L, 586L, 598L, 598L, 598L, 598L, 598L, 598L, 598L, 598L, 
602L, 602L, 602L, 602L, 602L, 602L, 602L, 603L, 603L, 603L, 617L, 
617L, 617L, 617L, 617L, 617L, 617L, 617L, 630L, 630L, 630L, 630L, 
630L, 630L, 630L, 636L, 636L, 641L, 641L, 641L, 641L, 641L, 641L, 
641L), percentfemale = c(7.834101382, 8.612440191, 8.173076923, 
9.030837004, 10.81081081, 12.15932914, 15.47861507, 13.06818182, 
13.51351351, 6.010928962, 5.825242718, 8.5, 9.708737864, 9.302325581, 
9.5, 12.29946524, 12.06896552, 6.802721088, 6.622516556, 7.042253521, 
8.843537415, 7.843137255, 7.792207792, 11.25, 11.11111111, 10.85271318, 
4.972375691, 6.179775281, 4.651162791, 4.954954955, 6.392694064, 
4.867256637, 3.555555556, 5.172413793, 13.63636364, 13.97058824, 
12.40875912, 5.925925926, 6.25, 7.692307692, 7.586206897, 0.666666667, 
6.756756757, 8.904109589, 6.25, 6.94980695, 8.148148148, 10.98039216, 
9.318996416, 8.865248227, 9.863945578, 10.52631579, 8.088235294, 
11.64383562, 12.10191083, 10.625, 13.0952381, 12.4260355, 7.246376812, 
9.289617486, 10.44776119, 11.01321586, 16.04938272, 14.71861472, 
12.07207207, 15.55763824, 18.0734856, 17.56756757, 17.72639692, 
19.07020873, 19.71014493, 17.64705882, 18, 18.25396825, 19.13043478, 
16.31944444, 17.79935275, 20, 22.11838006, 19.77077364, 20.32967033, 
19.66292135, 12.5, 14.59074733, 17.66666667, 19.62905719, 17.64705882, 
16.09042553, 16.43646409, 6.060606061, 7.947019868, 7.638888889, 
11.9205298, 13.15789474, 12.58741259, 6.091370558, 7.929515419, 
12.38095238, 12.82051282, 12.88888889, 14.52991453, 15.49295775, 
12.5984252, 12.90322581, 14.17322835, 13.17829457, 14.92537313, 
9.803921569, 3.333333333, 5.109489051, 3.496503497, 3.821656051, 
6.060606061, 9.756097561, 9.85915493, 2.857142857, 2.142857143, 
4.516129032, 4.268292683, 5.769230769, 7.407407407, 7.317073171, 
7.894736842, 5.365853659, 7.798165138, 9.482758621, 10.86956522, 
9.777777778, 10.24590164, 11.29032258, 10.67961165, 9.615384615, 
9.322033898, 9.649122807, 10.08403361, 4.615384615, 4.761904762, 
6.25, 5.303030303, 7.8125, 5.882352941, 5.454545455, 8.620689655, 
7.352941176, 9.032258065, 10.97560976, 9.036144578, 6.870229008, 
9.459459459, 14.36464088, 11.5, 13.90134529, 18.4, 16, 8.571428571, 
8.771929825, 6.194690265, 5.504587156, 6.796116505, 11.03117506, 
19.47743468, 12.07289294, 12.9740519, 15.49295775, 16.42411642, 
16.99604743, 19.1681736, 6.034482759, 14.28571429, 6.923076923, 
9.929078014, 9.433962264, 8.074534161, 9.941520468, 13.77245509, 
7.01754386, 8.333333333, 7.851239669, 4.827586207, 4.861111111, 
7.092198582, 9.868421053, 10.1910828, 10.96774194, 13.66459627, 
9.386776293, 10.94023069, 12.86926995, 14.01687216, 15.68885959, 
17.43400859, 16.4295393, 15.56459817, 5.696202532, 5.921052632, 
19.44444444, 8.024691358, 7.142857143, 6.951871658, 7.692307692, 
6.179775281, 9.482758621, 4.761905, 3.703704, 4.950495, 2.912621, 
6.930693, 5.447471, 7.142857, 9.056604, 13.42513, 16.14583, 17.77379, 
17.54967, 17.65677, 9.565217, 6.306306, 8.181818, 5.340114, 7.124352, 
7.549669, 12.74876, 13.29752, 14.33311, 15.43027, 15.96702, 7.758621, 
7.968127, 10.16949, 9.60961, 2.424242, 15.34091, 10.30928, 4.6875, 
5.050505, 7.009346, 7.906977, 2.9615, 3.616637, 10.94527, 11.86903, 
15.31532, 17.4939, 20.42042, 0, 0, 0, 1.694915, 3.225806, 3.149606, 
5, 1.183432, 1.694915, 2.717391, 2.312139, 0.9478673, 2.45098, 
3.012048, 0, 1.734104, 2.564103, 3.5, 3.626943, 3.571429, 5.729167, 
1, 0.9803922, 1.818182, 1.818182, 1.694915, 1.709402, 0.862069, 
6.956522, 9.917355, 10.25641, 0, 11.51079, 9.333333, 1.470588, 
3.472222, 4.166667, 4.166667, 6.756757, 7.801418, 0, 7.741935, 
7.643312, 6.962025, 7.594937, 8.823529, 9.333333, 9.677419, 9.574468, 
7.446809, 7.55814, 7.821229, 6.989247, 10.27027, 8.196721, 8.441558, 
5.714286, 5.5, 6.521739, 6, 5.940594, 4.663212, 8.837209, 11.45833, 
4.516129, 3.703704, 4.285714, 5.625, 5.91716, 5.813953, 6.134969, 
11.87335, 12.16545, 12.23529, 12.72321, 12.67606, 15.6746, 15.21739, 
6.930693, 9.677419, 11.2, 11.2782, 12.19512, 9.448819, 10.18519, 
8.490566, 7.894737, 10.15625, 11.19403, 8.917197, 11.68831, 17.51412, 
16.66667, 18.53933, 4.081633, 4.6875, 5.181347, 4.812834, 4.975124, 
3.349282, 4.624277, 0.6369427, 2.857143, 7.142857, 5.454545, 
7.058824, 7.142857, 8.391608, 1.360544, 1.37931, 1.360544, 4.026846, 
4.697987, 6.535948, 5.405405, 7.801418, 5.454545, 6.622517, 5.882353, 
7.18232, 8.571429, 9.589041, 9.846154, 10.81871, 11.47059, 3.90625, 
4.6875, 3.571429, 4.511278, 6.818182, 11.04294, 14.10256, 4.020101, 
3.045685, 2.439024, 3.478261, 3.2, 3.703704, 3.571429, 4.363636, 
3.97351, 4.792332, 5.333333, 5.315615, 7.923497, 7.286432, 10.35387, 
11.32075, 11.50923, 11.9877, 11.8007, 11.60267, 11.66078, 10.52002, 
6.752412, 6.583072, 9.898477, 10.51345, 10.22444, 10.90487, 8.878505, 
13.67521, 16.66667, 17.43119, 10, 10.62802, 12.61682, 13.00813, 
11.78862, 7.33945, 10.69959, 20.95238, 7.438017, 7.5, 8.333333, 
10.32028, 13.35616, 15.24823, 11.67883, 18.30508, 21.59468, 3.902439, 
4.950495, 5.365854, 5.263158, 7, 8.653846, 7.614213), timecat1 = c(-26L, 
-23L, -20L, -16L, -13L, -10L, -6L, 0L, 0L, -26L, -23L, -20L, 
-16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, -13L, -10L, 
-6L, 0L, 0L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -6L, -10L, 
-6L, 0L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, 
-16L, -13L, -10L, -6L, 0L, -20L, -16L, -13L, -10L, -6L, 0L, -20L, 
-16L, -13L, -10L, -6L, 0L, -23L, -20L, -16L, -13L, -10L, -6L, 
0L, -13L, -10L, -6L, -26L, -23L, -20L, -16L, -13L, -10L, -6L, 
0L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -20L, -16L, -13L, 
-10L, -6L, 0L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -6L, 0L, 
-10L, -6L, 0L, -10L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -23L, 
-20L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, -13L, 
-10L, -6L, 0L, -16L, -13L, -10L, -6L, 0L, -23L, -20L, -16L, -13L, 
-10L, -6L, 0L, -16L, -13L, -10L, -6L, 0L, -23L, -20L, -16L, -13L, 
-10L, -6L, 0L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, 
-13L, -10L, -6L, 0L, -23L, -20L, -16L, -13L, 0L, -26L, -23L, 
-20L, -13L, -6L, 0L, -26L, -23L, -20L, -13L, -10L, -6L, 0L, -26L, 
-23L, -20L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, 
-13L, -10L, -6L, 0L, -16L, -23L, -20L, -16L, -13L, -10L, -26L, 
-23L, -20L, -16L, -13L, -10L, -6L, 0L, -13L, -10L, -6L, -26L, 
-23L, -20L, -16L, -13L, -10L, -6L, 0L, -13L, -10L, -6L, 0L, -23L, 
-20L, -16L, -13L, -10L, -6L, 0L, -23L, -20L, -16L, -13L, -10L, 
-6L, 0L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, 
-16L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, -13L, -10L, 0L, 
-23L, -20L, -16L, -13L, -10L, -6L, 0L, -23L, -20L, -16L, -13L, 
-10L, -6L, -23L, -20L, -16L, -13L, -10L, -6L, -26L, -23L, -20L, 
-16L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, -13L, -10L, 
-6L, 0L, -26L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -16L, -23L, 
-20L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, -13L, -10L, 
0L, -23L, -20L, -13L, -10L, -6L, 0L, -13L, 0L, -10L, -6L, 0L, 
-26L, -23L, -16L, -13L, -10L, -26L, -23L, -20L, -16L, -13L, -10L, 
0L, -26L, -23L, -20L, -13L, -10L, -6L, 0L, -26L, -23L, -20L, 
-16L, -13L, -10L, -6L, 0L, 0L, -26L, -23L, -20L, -16L, -13L, 
-10L, -6L, 0L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, 
-20L, -16L, -13L, -10L, -6L, -26L, -23L, -20L, -16L, -13L, -6L, 
0L, -26L, -23L, -20L, -16L, -13L, -10L, -6L, 0L, -26L, -23L, 
-16L, -13L, -10L, -6L, 0L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, 
-13L, -10L, -6L, 0L, -26L, -23L, -20L, -16L, -13L, -6L, 0L, -26L, 
-23L, -26L, -23L, -20L, -16L, -13L, -10L, -6L), region = structure(c(3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Midwest", 
"Northeast", "South", "West"), class = "factor"), sizelogc = c(0.408823946, 
0.636182014, 0.663878359, 0.774106962, 0.837491565, 0.81147203, 
0.731559255, 0.989580112, -0.52527906, -0.277305662, -0.02646953, 
-0.011379257, 0.009202568, -0.141848484, -0.110337044, -0.078522425, 
-0.136207762, -0.595759393, -0.282844698, -0.2826483, -0.277326766, 
-0.250742573, -0.245563831, -0.183035124, -0.32184058, -0.287607408, 
0.048395349, -0.092604697, 0.036508019, 0.127815082, 0.155366121, 
0.255766404, 0.173947166, -0.884692994, -0.731071647, -0.394593501, 
-0.316877791, -0.702103128, -0.74801155, -0.646588826, -0.647397051, 
-0.587480728, -0.603441812, -0.601264967, -0.183904487, 0.168725229, 
0.124365995, 0.088979071, 0.14285296, 0.250676301, 0.31927981, 
0.28021636, -0.460329477, -0.384224561, -0.338558779, -0.562322168, 
-0.200129557, -0.076069403, -0.494231029, -0.189163979, -0.110595941, 
0.001720365, 0.121454067, 0.037814992, 1.598396458, 1.552348848, 
1.528920185, 1.633910643, 1.606908979, 1.832432709, 1.57677083, 
-0.640839651, -0.694966643, -0.547000501, -0.149472291, 0.361169794, 
0.451506904, 0.497633974, 0.455591612, 0.556782641, 0.567741169, 
0.559003403, 0.960085349, 1.049901785, 1.093877349, 1.153096098, 
1.25397841, 1.307771936, 1.216469988, -0.340080349, -0.277326766, 
-0.309985406, -0.232080481, -0.22633193, -0.259169473, -0.066114362, 
0.07356142, 0.079348177, 0.189508651, 0.182273574, 0.213919294, 
0.176972887, -0.622986408, -0.655332188, -0.375868374, -0.37900877, 
-0.594707567, -0.776192083, -0.530252871, -0.726032643, -0.399728748, 
-0.408587383, -0.241049151, -0.153805486, -0.432188637, -0.681483841, 
-0.499994734, -0.399728748, -0.363009875, -0.40728457, -0.37386737, 
-0.341941759, -0.327495407, -0.02646953, -0.062299347, -0.018869451, 
-0.025830674, -0.045304574, 0.009124882, -0.222468106, -0.75938432, 
-0.758622686, -0.680881903, -0.705224506, -0.662300858, -0.57205, 
-0.5534199, -0.521425683, -0.512222273, -0.633091239, -0.726886003, 
-0.765333084, -0.673617498, -0.517985978, -0.355459502, -0.328746935, 
-0.357287329, -0.547952449, -0.390596139, -0.155965909, -0.141848484, 
-0.041607712, 0.070160772, 0.081964777, -0.782026797, -0.850996006, 
-0.680881903, -0.726886003, -0.897757669, 0.303072117, 0.499784169, 
0.702821333, 0.801114163, 0.693473185, 0.685994373, 0.914163737, 
0.870120068, -0.641478507, -0.669679706, -0.384224561, -0.4137822, 
-0.165559974, -0.58143934, -0.195452876, -0.273388974, 0.015697784, 
0.03330568, 0.085281529, -0.650093744, -0.36861152, -0.422177711, 
-0.309985406, -0.254654803, -0.314148136, -0.245248134, 2.21254214, 
2.464016344, 2.517465096, 2.561832541, 2.531204875, 2.596658583, 
2.532332869, 2.463416317, -0.762813478, -0.524421951, -0.559536127, 
-0.464267269, -0.367972664, -0.31100774, -0.33366095, -0.336878457, 
-0.78968967, -0.804381978, -0.770484405, -0.820942213, -0.780928444, 
-0.753377405, 0.507649068, 0.90594493, 0.950657497, 0.942646379, 
1.012083374, 0.956143966, 1.041487785, 0.985550557, -0.674065298, 
-0.666992791, -0.442860242, 1.740855448, 2.044544372, 2.029656842, 
2.069429545, 1.968364716, 1.97746863, 1.883613066, 1.896172492, 
0.042455234, 0.173384627, 0.639131166, 0.581430439, -0.55992864, 
-0.223940699, -0.081275017, -0.095328469, -0.041607712, -0.022849423, 
-0.012017382, 1.467743908, 1.517602151, 1.75795099, 1.728731945, 
1.819062624, 1.618562794, 1.394151166, -1.056795911, -0.989847234, 
-0.929836301, -0.819247308, -0.753377405, -0.741592151, -0.933797606, 
-0.639992648, -0.358710449, -0.202247874, -0.272729057, -0.154788807, 
-0.090038867, -0.25450746, -0.58143934, -0.36861152, -0.250608946, 
-0.155965909, -0.19481402, -0.154788807, -0.076069403, -0.867895383, 
-0.793473924, -0.722750187, -0.729635149, -0.660119911, -0.677053629, 
-0.683503065, -0.501432433, -0.529322349, -0.582050305, -0.333739492, 
-0.428790775, -0.36875227, -0.674704154, -0.565689993, -0.575819755, 
-0.640839651, -0.562322168, -0.609914327, -0.929351167, -0.507130454, 
-0.465900522, -0.47544057, -0.523783095, -0.606773931, -0.448369898, 
-0.37287206, -0.503951844, -0.246966411, -0.301428195, -0.227878491, 
-0.118317987, -0.098549089, -0.11347744, -0.24986708, -0.495218164, 
-0.030009357, -0.069790019, -0.015317049, -0.087781263, -0.079206126, 
-0.204449218, -0.302135509, -0.486740125, -0.578166227, -0.584382126, 
-0.461791419, -0.370726974, -0.493575335, -0.399398814, 0.250851418, 
0.597179856, 0.658448481, 0.714387727, 0.820962263, 0.859063513, 
1.053196627, -0.804381978, -0.578112513, -0.660642278, -0.5811315, 
-0.677053629, -0.655332188, -0.827090486, -0.812961133, -0.716472848, 
-0.590621124, -0.489347051, -0.645030442, -0.363648731, -0.250052349, 
-0.319419439, -0.218776516, -0.54880241, -0.282844698, -0.202247874, 
-0.219144811, -0.165946036, -0.090766948, -0.326828121, -0.427965937, 
-0.615670623, -0.578112513, -0.467270885, -0.417979859, -0.528873117, 
-0.549971673, -0.751513923, -0.404058269, -0.494231029, -0.492438146, 
-0.333739492, -0.273088505, -0.410424966, -0.448995755, -0.655332188, 
-0.499575469, -0.122840343, -0.135833432, 0.209243937, 0.371355262, 
0.498310873, 0.539341695, 0.552798626, -0.484530622, -0.460329477, 
-0.410200048, -0.621421565, -0.606773931, -0.262371866, -0.217973717, 
-0.436129248, -0.191277505, -0.088765921, 0.036508019, 0.065294725, 
0.173384627, 0.140030452, -0.128162504, 0.159966049, 0.221644403, 
0.209243937, 0.22036664, 0.614624755, 0.681129799, 1.065212169, 
1.315573819, 1.477612502, 1.56898489, 1.741486445, 1.795245059, 
1.968924143, 2.11464897, 0.14434477, 0.319548119, 0.663544174, 
0.670843847, 0.680632429, 0.731559255, 0.749879332, -0.687899475, 
-0.622986408, -0.73479636, -0.291390402, -0.058788322, 0.020036939, 
0.217706611, 0.239519072, 0.076585244, 0.182078689, 0.051608314, 
-0.199956196, 0.093274675, 0.204646826, 0.288196489, 0.380811597, 
0.324394911, 0.291056575, -0.009041676, 0.268254825, -0.361143441, 
-0.077205048, -0.172647405, -0.015317049, -0.207445767, -0.114297445, 
-0.093907344)), row.names = c(NA, -432L), class = "data.frame")

> str(egdata)
'data.frame':   432 obs. of  5 variables:
 $ AJID         : int  8 8 8 8 8 8 8 8 13 51 ...
 $ percentfemale: num  7.83 8.61 8.17 9.03 10.81 ...
 $ timecat1     : int  -26 -23 -20 -16 -13 -10 -6 0 0 -26 ...
 $ region       : Factor w/ 4 levels "Midwest","Northeast",..: 3 3 3 3 3 3 3 3 4 4 ...
 $ sizelogc     : num  0.409 0.636 0.664 0.774 0.837 ...
4

1 回答 1

0

鉴于您提供的数据,我现在可以看到根本问题。您的数据集有许多缺失值。如该函数的文档中所述(https://www.rdocumentation.org/packages/lme4/versions/1.1-23/topics/lmer):

默认操作(na.omit,继承自 getOption("na.action") 的 'factory fresh' 值)去除任何变量中任何缺失值的观察。

因此,您的模型将仅利用没有缺失值的行。这就是您在某些级别的数据中看不到残值的原因。

要自己查看,您可以运行以下命令以仅提取没有缺失值的行:

data2 = data[complete.cases(data),]

你可以看到它data2要小得多。然后运行table(data2$region)以查看这个较小数据集中的区域级别。

请查看https://stats.stackexchange.com/questions/309718/how-to-deal-with-missing-data-in-mixed-effects-or-multi-level-models了解您可能如何处理这些丢失的数据。

更新:鉴于您的新数据集仅包含完整案例,我再也看不到这个问题了。也许清除您的 R 会话并重新启动?可重现的代码:

library(lme4)
library(lattice)
m5 <- lmer(percentfemale~ timecat1 + region + sizelogc +
             (1 + timecat1|AJID), data=egdata, REML=F) 
summary(m5)
xyplot(resid(m5) ~ region, data=egdata, jitter.x=T, abline=0, type=c("p", "g"))

在此处输入图像描述

于 2020-08-08T06:55:52.300 回答