1

对于模拟研究,我对比了不同 LMEM 的重复测量能力。我想指定一个模型,其中允许随机截距和斜率相关,而其中一个不允许。但是,当我比较这两个模型时,它们似乎完全一样。当我在两个模型上运行方差分析时,没有相关性的模型甚至有一个更多的自由度,而它应该是相反的。

# correlation allowed
  ml1 <- lmer(rt ~ treatment + (1+treatment|subject),data=df)
Linear mixed model fit by REML ['lmerMod']
Formula: rt ~ treatment + (1 + treatment | subject)
   Data: df
REML criterion at convergence: 10910.52
Random effects:
 Groups   Name        Std.Dev. Corr       
 subject  (Intercept) 72.87               
          treatment2  37.59    -0.17      
          treatment3  72.32    -0.65  0.73
 Residual             98.22               
Number of obs: 900, groups: subject, 30
Fixed Effects:
(Intercept)   treatment2   treatment3  
    602.537       -8.971       33.803  


# no correlation
  ml2 <- lmer(rt ~ treatment + (1|subject) + (0+treatment|subject) ,data=df)
      Linear mixed model fit by REML ['lmerMod']
Formula: rt ~ treatment + (1 | subject) + (0 + treatment | subject)
   Data: df
REML criterion at convergence: 10910.52
Random effects:
 Groups    Name        Std.Dev. Corr     
 subject   (Intercept) 29.34             
 subject.1 treatment1  66.70             
           treatment2  70.31    0.85     
           treatment3  52.95    0.29 0.68
 Residual              98.22             
Number of obs: 900, groups: subject, 30
Fixed Effects:
(Intercept)   treatment2   treatment3  
    602.537       -8.971       33.803  

# anova
anova(ml1,ml2)
refitting model(s) with ML (instead of REML)
Data: df
Models:
ml1: rt ~ treatment + (1 + treatment | subject)
ml2: rt ~ treatment + (1 | subject) + (0 + treatment | subject)
    Df   AIC   BIC  logLik deviance Chisq Chi Df Pr(>Chisq)
ml1 10 10950 10998 -5465.2    10930                        
ml2 11 10952 11005 -5465.2    10930     0      1          1

数据:

dput(DF)
structure(list(subject = structure(c(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, 2L, 2L, 2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L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 
18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 
22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 
27L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 
28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L
), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", 
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", 
"22", "23", "24", "25", "26", "27", "28", "29", "30"), class = "factor"), 
    treatment = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2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L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    rt = c(551.798792586772, 693.014255128461, 715.599061613616, 
    670.119831344829, 777.748610260388, 736.018489208224, 636.791011800404, 
    864.593711496912, 604.529352905588, 596.673178487122, 860.858066937491, 
    717.975814131377, 531.672833100059, 571.150454430927, 644.315598150879, 
    601.914697283216, 583.92746647402, 702.714068138085, 660.346853172676, 
    541.292786332608, 608.233103066463, 740.593415976325, 686.059921551164, 
    706.522723402261, 567.648255604935, 596.111352599386, 625.779084220279, 
    752.776987343973, 922.314285125596, 720.736074757203, 768.585671134519, 
    539.657760625667, 431.193030969184, 739.341430343149, 581.505474510558, 
    485.905153431116, 524.085545405872, 876.566370460358, 631.259754679943, 
    587.887351105621, 624.365050240473, 642.528438460209, 440.661792577731, 
    517.142782023978, 705.840003729944, 557.122142924839, 645.711579229236, 
    477.292943229673, 578.522058679457, 623.879658296107, 480.855063147831, 
    622.295733392922, 611.623490658329, 594.974733982977, 546.239019853272, 
    551.638287622872, 567.791819285002, 539.239628365136, 541.328446070423, 
    609.931976806498, 549.492601324081, 479.862984098331, 592.411150981731, 
    466.224011597179, 489.388878789762, 565.187127159354, 806.196199699478, 
    565.001071713299, 449.529036961143, 446.824243314547, 357.993777663337, 
    370.054045045062, 546.443479822161, 473.894296409884, 335.821704077378, 
    370.498649523398, 486.052525038318, 436.53292033153, 359.637460079864, 
    333.146018287273, 597.894114487158, 551.993792800734, 518.563432886515, 
    513.629383189428, 572.062676720248, 366.611317255576, 353.934207291842, 
    492.273303938824, 414.632984933654, 456.987565377718, 585.524844348671, 
    453.577328112778, 665.072248688078, 459.204631254183, 452.028605442515, 
    422.731506299078, 522.84363619892, 771.586286956136, 478.422495080758, 
    530.925498291748, 457.030618882822, 446.313635696342, 537.708665959068, 
    815.929601138346, 460.420404065423, 603.027278932425, 538.526470664698, 
    571.491835856551, 567.234631106499, 450.878624452358, 650.340961680322, 
    598.829083718722, 620.85411026516, 573.498196791879, 519.953442801483, 
    1143.14393274202, 505.028670926264, 685.875665196364, 605.316954852204, 
    645.269429082978, 678.192056130499, 605.671978651269, 650.564580984954, 
    641.331733928499, 687.164180542278, 613.873849203194, 789.829709495785, 
    560.793473918547, 707.169378961089, 680.753196215641, 659.262985906231, 
    600.712008959484, 662.275074291484, 661.346206480403, 568.31000899618, 
    661.439508442242, 761.227769640367, 699.901658463283, 631.422448673388, 
    734.257735977184, 585.776345181453, 714.587957176744, 893.931699334816, 
    586.343993838929, 664.205207596859, 828.003782888565, 906.448165648461, 
    584.196768113385, 747.575564348236, 687.698668648395, 398.221092516595, 
    490.332613905338, 502.683377386602, 451.168200674477, 620.606534311108, 
    369.820458042713, 429.483129392912, 628.153937257066, 476.31856841443, 
    608.016880363378, 402.588700424079, 460.302916138576, 341.209753425326, 
    600.165531243784, 454.003777748405, 589.089266888531, 504.033320854066, 
    399.871492203846, 421.426563579218, 423.375093277487, 587.614013919312, 
    689.18637317583, 652.10069672704, 553.995320740249, 570.86533170596, 
    636.399559100471, 801.517490092303, 653.425223465164, 684.914139340214, 
    639.418654954543, 555.718100869331, 677.062768399616, 579.433200999322, 
    561.757369869387, 672.316124102021, 701.108131071079, 588.129426947175, 
    438.090900053591, 562.520435558598, 610.177372103278, 564.672192806652, 
    552.305226838045, 586.912866128373, 872.521433158083, 654.971253063189, 
    575.068762782096, 784.098108527601, 648.265348029739, 590.541840435637, 
    552.569131260877, 554.840084955354, 582.798864712891, 573.196470707737, 
    512.123960183202, 579.838037093289, 710.216216611067, 779.786949219207, 
    615.995650564573, 549.096392807351, 600.781394864656, 415.016144351654, 
    765.924387691343, 401.541419432177, 436.050367769487, 536.508634405116, 
    445.112952169149, 478.003493101049, 509.819044087032, 490.265270275681, 
    594.667876389766, 781.844411855516, 827.832351086729, 379.401116898897, 
    469.280230588986, 397.115839743604, 874.524377877882, 612.130504039819, 
    802.270319490186, 651.842161968928, 581.489774054855, 686.457677143518, 
    570.172663082147, 566.996565453736, 577.947675356248, 494.016772046721, 
    546.065861910691, 506.178677541412, 527.653822550596, 470.043764013502, 
    595.080116592997, 464.590366280242, 684.362069491853, 534.310814471562, 
    545.7046301149, 452.141529834992, 619.652055160652, 568.61376011316, 
    576.847350527713, 514.248803061826, 585.909312171032, 687.892034205561, 
    907.133281713537, 549.603068658537, 617.860688444804, 423.424246676122, 
    524.28348263976, 593.203848577403, 431.733188413523, 476.284708033659, 
    588.88583865225, 437.275988819986, 733.45270912684, 592.366412341047, 
    606.958434204909, 721.61902078205, 604.596941234802, 534.65440311647, 
    526.29928462654, 655.076689084035, 560.740728878595, 591.083376633783, 
    533.331301213643, 750.32841350028, 547.366173885661, 602.313382446308, 
    787.158938523176, 534.80106549099, 454.37886245909, 599.535859565986, 
    607.126697674517, 668.173760533712, 589.060272311024, 590.188448587092, 
    711.910534337354, 528.634489779135, 600.468858484032, 580.666817624455, 
    659.907090614686, 596.395917159692, 994.163737779338, 662.059444540888, 
    637.256716085147, 714.353436812361, 587.212427691626, 676.527668439672, 
    609.004414569998, 667.364031145608, 788.145350832559, 725.891539439069, 
    561.397498270981, 430.027498616446, 500.437956195847, 463.801763917305, 
    458.358780003907, 383.304386810731, 598.957692241571, 409.89510543858, 
    390.650415086637, 552.072907469115, 388.554580583084, 671.244783776164, 
    433.841093781351, 423.187562794827, 502.566122911232, 469.869008810394, 
    547.610270179268, 501.091740213331, 417.336826115574, 500.284514580019, 
    460.835882303962, 650.071068396249, 523.313503950421, 861.366681123829, 
    879.241985731583, 673.655630620254, 448.199583227711, 578.587129494665, 
    654.742597624172, 623.62363768736, 665.526175470944, 942.738238156293, 
    1006.15443845549, 667.679153732234, 711.686114156855, 642.929069350516, 
    685.862290196822, 1062.63097632175, 758.162511396556, 827.547233897549, 
    668.688764986398, 791.497544557741, 838.143090686178, 681.935257212825, 
    758.732997665222, 661.724656922782, 793.560801116029, 896.416624866383, 
    642.617709357462, 633.832129070135, 751.515360586321, 616.151652306802, 
    684.496510560379, 655.310039878885, 710.298048482024, 606.373767619465, 
    754.268924528687, 822.582103710613, 820.556840434073, 733.785411148237, 
    584.830824784288, 588.316573524589, 572.95505735157, 559.402915982595, 
    640.891735376065, 482.407652048448, 569.682285396545, 517.277707765673, 
    698.102946480301, 651.001615070688, 665.691471843539, 511.440973330271, 
    504.930464361447, 613.891964397534, 454.7073692139, 513.19138352863, 
    422.708112768038, 347.049510934991, 523.980248957572, 480.301125161823, 
    633.307276361827, 799.987010744151, 533.354042715484, 410.150445477125, 
    809.568249688128, 531.41976915349, 792.355614308461, 747.208014043674, 
    607.571115317023, 546.485408007754, 633.55875460818, 767.73368427773, 
    676.492693414302, 751.649529779836, 984.189814104173, 684.929427919003, 
    615.787024482925, 567.942282464503, 571.041675151281, 614.028930539252, 
    779.839834490734, 630.179209124113, 651.603035032816, 788.591687415382, 
    799.38918489533, 701.842888543902, 693.932887722425, 624.800556024233, 
    659.981040765196, 542.243217216484, 721.703181143723, 607.818766172507, 
    586.813797432694, 610.206652108693, 837.694469363876, 763.535995041537, 
    758.89830766469, 616.838182390385, 578.107924042397, 628.314074464124, 
    676.917384461922, 635.824489980127, 495.143374853889, 815.582155744321, 
    534.740299502999, 568.853739307473, 771.28519095763, 673.064072347686, 
    713.558399193608, 599.316767121742, 689.796480377465, 673.175516507747, 
    518.390229271871, 784.139459988779, 536.808895738866, 591.342581848355, 
    563.762291009613, 679.413099342014, 490.762928348403, 575.612328735691, 
    504.631070884374, 689.919729220693, 545.809277581445, 641.095314483731, 
    618.332256267043, 641.913937397485, 953.129874375365, 646.628853366556, 
    631.881991258933, 671.647395089865, 503.290799393907, 506.506064370266, 
    529.718096437596, 484.255438291713, 861.643688089666, 625.018895601203, 
    768.279996867868, 596.708155034627, 671.714642028838, 844.072568247028, 
    578.694918479722, 422.588349061727, 594.493346157147, 520.812331184257, 
    741.876339265066, 555.516494731537, 579.386393427601, 622.316950052304, 
    523.488853303438, 595.901305255518, 553.512680895547, 557.643582245011, 
    624.788623102115, 479.715363427417, 574.354660431126, 524.472350214463, 
    660.841590121958, 608.621321258764, 631.743182107793, 711.470012104646, 
    617.432792370567, 573.363544694191, 617.449976333406, 563.127159530709, 
    583.25391667852, 678.936105477067, 572.153554376884, 609.829503412847, 
    606.069768210344, 693.198276061625, 647.952198803514, 508.091779167254, 
    654.226813385831, 530.92016927824, 504.963210966908, 512.488303835862, 
    763.325818301401, 664.628862733417, 477.385861339593, 566.148674353306, 
    578.70068655976, 606.967024346421, 697.460752784057, 662.304772796768, 
    520.905460930742, 629.14344808993, 815.023764792173, 680.359748369552, 
    628.317980877129, 679.505810999772, 512.999611466799, 656.728389486035, 
    548.409794219861, 619.925877003775, 581.949057396067, 663.545400676099, 
    666.518874913722, 691.701483159255, 616.896649470106, 595.504424960074, 
    574.172251324537, 552.787259430621, 678.018976276998, 607.329759814185, 
    611.581207725935, 690.981992177989, 564.832150097104, 540.336710300887, 
    533.631062681699, 553.612294126468, 479.592612257575, 805.559491265258, 
    528.304765655223, 496.66528049325, 503.82305630743, 696.245302300331, 
    566.070769246181, 659.391688013324, 697.528902380277, 524.903347139913, 
    599.821891499886, 605.43297053286, 663.035359384042, 714.444647793395, 
    578.371129029246, 615.320894052349, 586.420779403222, 611.255799029828, 
    583.666658817928, 585.113768358993, 590.122958856932, 629.219469590256, 
    538.928053998428, 686.894125956954, 600.89266348967, 577.953187882193, 
    554.413905790583, 579.409330807908, 745.040084235899, 891.087132273406, 
    552.988614856682, 820.955690300634, 634.469321378978, 673.975047013567, 
    756.507601731563, 639.35059215201, 722.557986588015, 586.447409643988, 
    656.432427481585, 682.783381677787, 644.716232116734, 572.306442663379, 
    517.147784935371, 455.957276558869, 581.819706567048, 484.576715810217, 
    481.058650198264, 769.846887958231, 614.717393882487, 512.55467514312, 
    562.454770697369, 470.842224095898, 473.821865893767, 525.60888531351, 
    504.615217687803, 633.463711580414, 697.478798243637, 542.901502870182, 
    554.078075963646, 552.734146037028, 505.049122827182, 486.831379133217, 
    784.789844765716, 625.603196289942, 670.995369035953, 685.579926259636, 
    540.482850768361, 439.117039069522, 502.605387735171, 683.149979103402, 
    516.322278257158, 642.3671240847, 552.631029671279, 647.736853458454, 
    560.328629000192, 730.565596415312, 618.355157539931, 663.62525661894, 
    762.952777957374, 628.608584740535, 624.968635247218, 661.70575556195, 
    574.702252033339, 612.175432188694, 517.854558597715, 675.314287039473, 
    542.173699486536, 627.693153783529, 692.014742774091, 739.358457751625, 
    594.351746882543, 487.81864701434, 584.028504991851, 772.039898984639, 
    467.800944704621, 699.587386648698, 711.892383008835, 615.312970618784, 
    675.467367812567, 504.86811313757, 549.182867476271, 399.814725143066, 
    558.16544073586, 422.858340371991, 636.197179849367, 452.640724786824, 
    620.185492727861, 463.138266913543, 513.777642749675, 562.005709606924, 
    536.148107655772, 609.263894686695, 569.500530985324, 431.43349765191, 
    584.398797922899, 499.315449753743, 619.406287942484, 530.179301913325, 
    581.286972325074, 609.256211854971, 603.54936265609, 631.687639186526, 
    657.738657905408, 662.587176694764, 566.971357910094, 858.130855520899, 
    636.509916564228, 961.258701590037, 654.287721552112, 722.951283166332, 
    632.132002720104, 487.318833408862, 568.846556179602, 618.040023485574, 
    496.276276900436, 575.584711170303, 581.733646148308, 429.189732200854, 
    542.010860963286, 494.264804962282, 422.488093162063, 458.026827419797, 
    453.276318995818, 469.307056127784, 569.3897375524, 579.968164508765, 
    499.796867133562, 434.308570876294, 715.325075398682, 716.351002032214, 
    628.027210297141, 500.606473063414, 481.830926575354, 613.318935569666, 
    976.743117685661, 644.275338785824, 478.107026795071, 557.000656140104, 
    705.452526296914, 485.589962586432, 499.786618070234, 558.712600821937, 
    590.922333630969, 542.410481740128, 489.828649613243, 588.761989730902, 
    546.978243344109, 606.196264556647, 564.236942812287, 536.823507783435, 
    579.521762239388, 515.499050687035, 630.900495035976, 656.332012380511, 
    587.856990348358, 522.305185738772, 739.045222536055, 730.745657623434, 
    924.844562132056, 784.35778551794, 602.551997131679, 647.756594982111, 
    698.734409940058, 836.546703053691, 698.539340777214, 1026.87197547421, 
    629.904387631378, 1256.38776880042, 550.201102905894, 602.768212743634, 
    721.187968335008, 978.957227830475, 720.414204972345, 674.653879707098, 
    788.5848329187, 719.806764303146, 717.541641935441, 692.033638361742, 
    697.745018761048, 666.284578038868, 772.479906582772, 659.065480010219, 
    820.683359002167, 676.970146466469, 874.368371442289, 727.177048657942, 
    698.30875424695, 779.956903736863, 845.624757018358, 713.683982932567, 
    726.314529163246, 619.106987740244, 602.275574812157, 1012.31009024481, 
    900.357542354599, 644.181000629658, 696.237940779481, 723.968447714559, 
    728.433707295704, 738.277840656323, 624.899240530917, 602.62262026982, 
    741.637155120584, 771.780154658976, 655.858038042129, 746.047425940232, 
    620.210165076071, 727.335465168732, 575.696484591354, 664.112900876799, 
    635.568414156208, 813.389693290661, 782.803606862186, 611.54036820155, 
    626.182943686362, 629.796912199246, 850.589128120044, 751.317837909887, 
    698.370084520991, 684.731100139964, 675.610584876072, 746.655183232173, 
    700.916031879367, 672.999065959173, 754.165715908428, 1000.39209579409, 
    711.494061908177, 641.566680754116, 804.073919378063, 684.705472972499, 
    703.074833865838, 461.242335766073, 427.275150289403, 448.904300292751, 
    504.467553858542, 468.445048327652, 492.18239230431, 441.918536235364, 
    516.654435536123, 552.509951287832, 409.431285285276, 435.346043325067, 
    547.743500224329, 531.812309405229, 364.578903523756, 508.390034089605, 
    379.665384727272, 509.53781675453, 357.585528744983, 441.32777083335, 
    443.431829371385, 606.59281583625, 686.319960511486, 625.7347791126, 
    738.463790041674, 563.274182025531, 464.717827380926, 507.784383381725, 
    588.175980498022, 413.597103546393, 718.241261054521, 748.95432032953, 
    753.3423119569, 624.488936342165, 685.583685719862, 556.272453690569, 
    553.85940984926, 547.648759204925, 600.572261526898, 798.618024234413, 
    726.941645252511, 571.72160960877, 550.034219181198, 627.264280360843, 
    678.989621824996, 643.317665763982, 562.10080966811, 612.803383559254, 
    681.139896626253, 602.318525361381, 725.533189662524, 624.989203686985, 
    757.711095633453, 672.222798550503, 814.596048431427, 661.778896020412, 
    598.861275115565, 720.798422223033, 607.767472082705, 786.918370564599, 
    609.319159908796, 654.545951651791, 590.381966203786, 580.331158503126, 
    515.973182460188, 652.661059652561, 545.988014818838, 695.948607980764, 
    541.582595061958, 589.514921567389, 543.237248780138, 629.781187086802, 
    495.114814971547, 713.705169086826, 604.33689023605, 515.485770936165, 
    519.257552917307, 699.375113218082, 538.736700962025, 475.293688282428, 
    575.221421714611, 504.071893399439, 480.754098260713, 529.183372881182, 
    600.773688635732, 528.753221287108, 623.467259878089, 524.506017554373, 
    578.950778202312, 558.484848311201, 548.077100964434, 628.137735553388, 
    536.855310919075, 671.288977759216, 656.468309447081, 554.138278777839, 
    652.139385673766, 576.644938824018, 623.229206449598, 690.260009908557, 
    908.122945156817, 512.745373098672, 512.90318083329, 732.257651656802, 
    542.85407478119, 497.700590782599, 523.882208542902, 448.976579619777, 
    563.466660067041, 505.398939062326, 668.814284148356, 512.653186957994, 
    503.040433891059, 433.619712591384, 464.197386550985, 408.88198638402, 
    681.920233753602, 504.514813136438, 570.133904166935, 491.416987899975, 
    440.029552147731)), .Names = c("subject", "treatment", "rt"
), class = "data.frame", row.names = c(NA, -900L))
4

1 回答 1

2
source("lmer_nocorr_dat.R")  ## get data
library(lme4)
ml1 <- lmer(rt ~ treatment + (1+treatment|subject),data=dd)

用于获取我们目前感兴趣的输出位的摘要函数。(打印 RE 方差而不是标准差,因为它们是相加的,因此更容易分辨哪些术语正在组合或分离。)

sumfun <- function(x) {
   cat("REML criterion:",REMLcrit(x),"\n")
   invisible(print(VarCorr(x),comp="Variance"))
}
## REML criterion: 10910.52 
##  Groups   Name        Variance Corr         
##  subject  (Intercept) 5309.9                
##           treatment2  1412.8   -0.168       
##           treatment3  5230.4   -0.652  0.733
##  Residual             9648.1                

对角线模型的原始尝试:

ml2 <- lmer(rt ~ treatment + (1|subject)+(0+treatment|subject),data=dd)

这给出了一个警告

Model failed to converge: degenerate  Hessian with 1 negative eigenvalues

总结输出表明我们仍在拟合具有相关性的模型:

## REML criterion: 10910.52 
##  Groups    Name        Variance Corr       
##  subject   (Intercept)  860.71             
##  subject.1 treatment1  4449.14             
##            treatment2  4942.74  0.851      
##            treatment3  2803.64  0.286 0.683
##  Residual              9648.07             

事实上,前两项之和等于前一个模型中的第一项,进一步证明了不可识别性(我不太确定为什么其他两个方差是项不同,但我猜随机效应的方差没有改变。)

有几种方法可以解决这个问题。

设置数字虚拟变量

dd <- cbind(dd,model.matrix(~treatment,data=dd))

可能首选不同的参数化(例如~treatment-1),但相关性设置为零,这将对应于相同的模型......

ml3 <- lmer(rt ~ treatment +
        (0+`(Intercept)`|subject)+
        (0+treatment2|subject)+
        (0+treatment3|subject),
        data=dd)
## REML criterion: 10926.79 
##  Groups    Name          Variance
##  subject   `(Intercept)` 4366.25 
##  subject.1 treatment2     860.97 
##  subject.2 treatment3    3233.28 
##  Residual                9761.63 

REML 标准已经上升(正如我们所期望的,对于不太灵活的模型),尽管残差方差仍然相同。getME(ml3,"theta")显示参数的数量确实从 6 个减少到 3 个。

包裹偏差函数

dfun <- update(ml1,devFunOnly=TRUE)
lwr <- getME(ml1,"lower")
covpos <- which(lwr<0)
parvec <- numeric(length(lwr))
dfunwrap <- function(p) {
   parvec[varpos] <- p
   dfun(parvec)
}
opt <- minqa::bobyqa(par=getME(ml1,"theta")[varpos],
                        fn=dfunwrap,lower=0)
parvec[varpos] <- opt$par
opt$par <- parvec
opt$conv <- 0
lf <- lFormula(rt ~ treatment + (1+treatment|subject),data=dd)
ml4 <- mkMerMod(environment(dfun),opt,lf$reTrms,lf$fr)
## REML criterion: 10926.79 
##  Groups   Name        Variance Corr       
##  subject  (Intercept) 4366.25             
##           treatment2   860.98  0.000      
##           treatment3  3233.28  0.000 0.000
##  Residual             9761.63             

修改reTrms

lf$reTrms$theta <- c(1,1,1)    ## only 3 theta parameters
lf$reTrms$lower <- rep(0,3)
lf$reTrms$Lind <- rep(1:3,30)  ## correspondence of theta vector
                              ## with non-zero elements in Lambdat
## there should be an easier way to create a sparse diagonal matrix
##  of class 'dgCMatrix' ....
lf$reTrms$Lambdat <- sparseMatrix(i=1:90,j=1:90,dims=c(90,90),x=1)
devfun <- do.call(mkLmerDevfun,lf)
opt <- optimizeLmer(devfun)
ml5 <- mkMerMod(environment(devfun), opt, lf$reTrms, fr=lf$fr)

这给出了与以前的方法相同的答案,但它破坏了输出方法......

ml5@pp$theta
## [1] 0.6687950 0.2969846 0.5755197
ml4@pp$theta
## [1] 0.6687949 0.0000000 0.0000000 0.2969847 0.0000000 0.5755197

最终我们希望将这种东西构建到flexlambda分支中,但我们将不得不在输出方法上做一些工作......

于 2014-07-27T16:54:54.000 回答